Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xi/boon
unix terminal framework
https://github.com/xi/boon
terminal
Last synced: about 2 months ago
JSON representation
unix terminal framework
- Host: GitHub
- URL: https://github.com/xi/boon
- Owner: xi
- License: mit
- Created: 2020-07-12T18:44:40.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-12T21:32:52.000Z (5 months ago)
- Last Synced: 2024-11-14T18:52:42.453Z (2 months ago)
- Topics: terminal
- Language: Python
- Homepage:
- Size: 43.9 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# boon - unix terminal framework
Boon is an alternative to curses. It occupies a similar level of abstraction
(somewhere between terminfo and your application), but uses different concepts.
It is just over 100loc and has no dependencies outside the standard library.The high level API aims to be declarative and is partly inspired by react. The
lines of the terminal are represented as a list of strings. On each update,
this list is regenerated and compared to the previous version. Only the lines
that have changed are rendered to the terminal.Boon does not provide utilities for color and styling. You can either use the
low level API or a third party library such as
[colorama](https://github.com/tartley/colorama/) or
[blessings](https://github.com/erikrose/blessings/).## Installation
```
pip install boon-term
```## Example
```python
import boonclass Example(boon.App):
def render(self, rows, cols):
yield 'Hello World'def on_key(self, key):
if key == 'q':
self.running = Falseexample = Example()
example.run()
```## High level API
### `App.run()`
Call to start the main loop.
### `App.running`
Set to `False` to stop the main loop.
### `App.selector`
An instance of
[`selectors.DefaultSelector`](https://docs.python.org/3/library/selectors.html#selectors.DefaultSelector)
you can use to register additional file objects to the main loop.### `App.render(rows, cols)`
Overwrite to define your view. For every line in the UI, this functions should
yield a string.### `App.on_key(key)`
Overwrite to react to key presses. `key` is a string containing either a
character or an escape sequence. Boon contains constants for the most common
escape sequences:- `KEY_BACKSPACE`
- `KEY_ESC`
- `KEY_HOME`
- `KEY_END`
- `KEY_DEL`
- `KEY_PPAGE`
- `KEY_NPAGE`
- `KEY_UP`
- `KEY_DOWN`
- `KEY_RIGHT`
- `KEY_LEFT`## Low level API
### `get_cap(cap, *args) -> str`
Get a capability from the terminfo database. If stdout is not a tty or if the
capability is not supported by the terminal this returns an empty string. The
full list of capabilities is available in the [terminfo
manpage](http://manpages.ubuntu.com/manpages/man5/terminfo.5.html)```python
print(get_cap('setaf', 13) + 'foo' + get_cap('sgr0'))
```### `move(y, x)`
Move the cursor to the given position.
### `tty_restore(fd)`
Context manager that restores tty settings after the nested block.
```python
def getpass(prompt):
fd = sys.stdin.fileno()
with tty_restore(fd):
flags = termios.tcgetattr(fd)
flags[3] &= ~termios.ECHO
termios.tcsetattr(fd, termios.TCSADRAIN, flags)
return input(prompt)
```### `fullscreen()`
Context manager that enters cup and cbreak mode and also hides the cursor.
Everything is restored to the previous state after the nested block.### `getch() -> string`
Read from stdin. See `App.on_key()` for details on the return value.