https://github.com/mingrammer/python-curses-scroll-example
:tv: How to implement the scroll and paging in Python curses
https://github.com/mingrammer/python-curses-scroll-example
curses example paging python scroll
Last synced: 9 months ago
JSON representation
:tv: How to implement the scroll and paging in Python curses
- Host: GitHub
- URL: https://github.com/mingrammer/python-curses-scroll-example
- Owner: mingrammer
- License: mit
- Created: 2018-03-04T07:06:12.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-09-22T15:51:52.000Z (over 4 years ago)
- Last Synced: 2024-02-29T16:32:11.522Z (almost 2 years ago)
- Topics: curses, example, paging, python, scroll
- Language: Python
- Homepage:
- Size: 10.7 KB
- Stars: 47
- Watchers: 3
- Forks: 12
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Python Curses Scroll Example
I'll introduce how to implement the scroll and paging in Python curses.
## What is purpose?
Scroll and paging are little a bit cumbersome to implement with curses. So, I'd like to share the code snippets to help for building the scroll and paging feature for your TUI based application.
## Key Idea
The key idea is simple. The idea is that compare the length of item list and current cursor position, then just calculate the next cursor position. Of course, there are some exceptions such as scroll overflow we must deal with.
## Run & Test
Clone this repository and run `python3 tui.py`
> It supports Python 3+ only. With Python 2, It might not be work correctly.
* Scroll
* KEY_UP (↑) for scroll up
* KEY_DOWN (↓) for scroll down
* Paging
* KEY_LEFT (←) for page up
* KEY_RIGHT (→) for page down
## Scroll Demo
[Scroll implementation](/tui.py#L86-L110)
[](https://asciinema.org/a/166994)
## Paging Demo
[Paging implementation](/tui.py#L112-L132)
[](https://asciinema.org/a/166995)
## License
MIT