Skip to content

Commit

Permalink
Merge pull request #14 from yukihirop/issues13/fix_bug_about_display
Browse files Browse the repository at this point in the history
Bug about a page turning
  • Loading branch information
yukihirop authored Jan 26, 2021
2 parents 60aefe0 + 57abc58 commit 390ebcd
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 70 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.2.2

2021/01/27

- `[Fix bugs]` Bug about a page turning ([#14](https://github.com/yukihirop/gfzs/issues/14))

Please see [milestone](https://github.com/yukihirop/gfzs/milestone/4)


## 0.2.1

2021/01/23
Expand Down
70 changes: 38 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ __We are not responsible if you ignore the advice and block your IP. please note
pip install gfzs
```

or

```bash
pipx instal gfzs
```

## 😎 Demo

seeing is believing.
Expand Down Expand Up @@ -64,35 +70,35 @@ For Example, Assuming that data.json is as follows.
```json
[
{
"abstract": "Rustは非常に高速でメモリ効率が高くランタイムやガベージコレクタがないため、パフォーマンス重視のサービスを実装できますし、組込み機器上で実行したり他の言語との調和も簡単にできます。 信頼性. Rustの豊かな型システムと所有権 ...",
"abstract": "Python is an interpreted, high-level and general-purpose programming language. Python's design philosophy emphasizes code readability with its notable use ...",
"matches": [
{
"offset": 0,
"phrase": "Rust"
"phrase": "Python"
},
{
"offset": 97,
"phrase": "Rust"
"offset": 79,
"phrase": "Python's"
}
],
"title": "Rustプログラミング言語",
"url": "https://www.rust-lang.org/ja"
"metadata": "Developer: Python Software Foundation | Designed by: Guido van Rossum | Filename extensions: .py,.pyi,.pyc,.pyd,.pyo ... | Typing discipline: Duck, dynamic, gradual (since ...",
"title": "Python (programming language) - Wikipedia",
"url": "https://en.wikipedia.org/wiki/Python_(programming_language)"
},
{
"abstract": "Rust(ラスト)はMozillaが支援するオープンソースのシステムプログラミング言語である。 Rust言語は速度、並行性、安全性を言語仕様として保証するC言語、C++に代わるシステムプログラミング(英語版)に適したプログラミング言語を ...",
"abstract": "プログラミング言語 Pythonの紹介・ダウンロードとインストール・Python入門講座など.",
"matches": [
{
"offset": 0,
"phrase": "Rust"
"offset": 10,
"phrase": "Python"
},
{
"offset": 48,
"phrase": "Rust"
"offset": 34,
"phrase": "Python"
}
],
"metadata": "型付け: 静的型付け、強い型付け、型推論、構造... | 登場時期: 2010年7月7日 | ライセンス: Apache-2.0、MIT License | 影響を受けた言語: Alef、C++、C Sharp、Cyclon...",
"title": "Rust (プログラミング言語) - Wikipedia",
"url": "https://ja.wikipedia.org/wiki/Rust_(%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0%E8%A8%80%E8%AA%9E)"
"title": "プログラミング言語 Python - python.jp",
"url": "https://www.python.jp/"
}
]
```
Expand Down Expand Up @@ -253,57 +259,57 @@ $ python3 gfzs/controller.py
or

```bash
$ cat fixtures/rust.json | python3 -m gfzs
$ cat fixtures/python.json | python3 -m gfzs
```

or

```bash
$ cat fixtures/rust.json | bin/gfzs
$ cat fixtures/python.json | bin/gfzs
```

## 💪 Development (Check Partial View)
## 💪 Development (Check Each View)

### search_result
### header

```bash
$ python3 gfzs/views/search_result.py
$ python3 gfzs/views/header.py
```

![image](https://user-images.githubusercontent.com/11146767/104927269-8e50af00-59e4-11eb-8fcf-8b18f4db4420.png)
![image](https://user-images.githubusercontent.com/11146767/104927550-ed162880-59e4-11eb-8d5c-efca84c58ea6.png)

### footer
### search_result

```bash
$ python3 gfzs/views/footer.py
$ python3 gfzs/views/search_result.py
```

![image](https://user-images.githubusercontent.com/11146767/104927398-b93b0300-59e4-11eb-99a8-5b1e85dc000d.png)
![image](https://user-images.githubusercontent.com/11146767/104927269-8e50af00-59e4-11eb-8fcf-8b18f4db4420.png)

### header
### paging

```bash
$ python3 gfzs/views/header.py
$ python3 gfzs/views/paging.py
```

![image](https://user-images.githubusercontent.com/11146767/104927550-ed162880-59e4-11eb-8d5c-efca84c58ea6.png)
![image](https://user-images.githubusercontent.com/11146767/104927802-36667800-59e5-11eb-9afb-2b3386c4d8c6.png)

### not_found
### footer

```bash
$ python3 gfzs/views/not_found.py
$ python3 gfzs/views/footer.py
```

![image](https://user-images.githubusercontent.com/11146767/104927669-0d45e780-59e5-11eb-9dc8-76baec0c04ac.png)
![image](https://user-images.githubusercontent.com/11146767/104927398-b93b0300-59e4-11eb-99a8-5b1e85dc000d.png)


### paging
### not_found

```bash
$ python3 gfzs/views/paging.py
$ python3 gfzs/views/not_found.py
```

![image](https://user-images.githubusercontent.com/11146767/104927802-36667800-59e5-11eb-9afb-2b3386c4d8c6.png)
![image](https://user-images.githubusercontent.com/11146767/104927669-0d45e780-59e5-11eb-9dc8-76baec0c04ac.png)


## 📚 Reference
Expand Down
2 changes: 1 addition & 1 deletion gfzs/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__name__ = "gfzs"
__description__ = "Google Fuzzy Search"
__version__ = "0.2.1"
__version__ = "0.2.2"
__copyright__ = "Copyright ©︎ 2021 yukihirop"
__url__ = "https://github.com/yukihirop/gfzs"
__author__ = "yukihirop"
Expand Down
97 changes: 61 additions & 36 deletions gfzs/views/search_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,62 @@ def update_attributues(self, current_selected, last, topy, top_textbox):
def update_per_page(self, value):
self.per_page = value

@property
def current_page(self) -> int:
return self.current_selected // self.per_page + 1

def prev_page(self, total_data_size):
per_page = self.per_page
old_current_selected = self.current_selected
current_pagetop_index = per_page * math.floor(old_current_selected / per_page)

self.change_page = True
if self.current_page == 1:
total_page = math.ceil(total_data_size / per_page)

if total_page >= 1:
self.current_selected = (total_page - 1) * per_page
else:
pass
else:
self.current_selected = current_pagetop_index - per_page

def next_page(self, total_data_size):
per_page = self.per_page
old_current_selected = self.current_selected
current_pagetop_index = per_page * math.floor(old_current_selected / per_page)
total_page = math.ceil(total_data_size / per_page)

self.change_page = True
if self.current_page == total_page:
self.current_selected = 0
else:
self.current_selected = current_pagetop_index + per_page

def down(self, total_data_size):
old_current_page = self.current_page
old_current_selected = self.current_selected

if old_current_selected >= total_data_size - 1:
self.change_page = True
self.current_selected = 0
else:
self.current_selected += 1
if self.current_page != old_current_page:
self.change_page = True

def up(self, total_data_size):
old_current_page = self.current_page
old_current_selected = self.current_selected

if old_current_selected == 0:
self.change_page = True
self.current_selected = total_data_size - 1 # wrap around.
else:
self.current_selected -= 1
if self.current_page != old_current_page:
self.change_page = True


class SearchResult(Base):
"""Display options build from a list of strings in a (unix) terminal.
Expand Down Expand Up @@ -106,10 +162,7 @@ def data_size(self) -> int:

@property
def current_page(self) -> int:
return self.current_selected // self.per_page + 1

def current_page_from(self, current_selected) -> int:
return current_selected // self.per_page + 1
return self.helper.current_page

def update_per_page(self, value):
self.helper.update_per_page(value)
Expand Down Expand Up @@ -355,57 +408,29 @@ def update_view_in_loop(self) -> bool:

def handle_key_in_loop(self, user_input):
self.helper.change_page = False
old_current_page = self.current_page
textboxes = self.textboxes
textboxes_len = len(textboxes)

if textboxes_len == 0:
return

current_selected = self.current_selected
per_page = self.per_page

# Vim like KEY_UP/KEY_DOWN with j(DOWN) and k(UP)
if textboxes_len > 1 and user_input == curses.KEY_DOWN:
if current_selected >= textboxes_len - 1:
self.helper.change_page = True
current_selected = 0 # wrap around.
else:
current_selected += 1
if self.current_page_from(current_selected) != old_current_page:
self.helper.change_page = True
self.helper.down(textboxes_len)
elif textboxes_len > 1 and user_input == curses.KEY_UP:
if current_selected == 0:
self.helper.change_page = True
current_selected = textboxes_len - 1 # wrap around.
else:
current_selected -= 1
if self.current_page_from(current_selected) != old_current_page:
self.helper.change_page = True
self.helper.up(textboxes_len)
elif textboxes_len > per_page + 1 and user_input == curses.KEY_RIGHT:
self.helper.change_page = True
next_pagetop_index = per_page * (math.ceil(current_selected / per_page) + 1)

if next_pagetop_index <= textboxes_len - 1:
current_selected = next_pagetop_index
else:
current_selected = 0 # wrap around.
self.helper.next_page(textboxes_len)
elif textboxes_len > per_page + 1 and user_input == curses.KEY_LEFT:
self.helper.change_page = True
current_pagetop_index = per_page * math.floor(current_selected / per_page)
if current_pagetop_index <= 0:
current_selected = textboxes_len - per_page # wrap around.
else:
current_selected = current_pagetop_index - per_page
self.helper.prev_page(textboxes_len)
elif user_input == curses.KEY_RESIZE:
self.reset()
elif user_input in (curses.ascii.BS, curses.ascii.DEL, curses.KEY_BACKSPACE):
self.reset()
elif user_input == ord("q"): # Quit without selecting.
self.stop_loop = True

self.helper.current_selected = current_selected


if __name__ == "__main__":

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "gfzs"
version = "0.2.1"
version = "0.2.2"
description = "Google Fuzzy Search"
authors = ["yukihirop <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 390ebcd

Please sign in to comment.