Skip to main content

unix terminal framework

Project description

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 or blessings.

Example

import boon

class Example(boon.App):
  def render(self, rows, cols):
    yield 'Hello World'

  def on_key(self, key):
    if key == 'q':
      self.running = False

example = 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 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

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.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

boon_term-0.0.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

boon_term-0.0.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file boon_term-0.0.0.tar.gz.

File metadata

  • Download URL: boon_term-0.0.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for boon_term-0.0.0.tar.gz
Algorithm Hash digest
SHA256 7c38fa5a0760ed28c0b22573069ea4ba632f715123e00d13c3e55fb0fd344558
MD5 6022d1883ce7ee82848d09e3db5fcfd5
BLAKE2b-256 c1284003f394075dc2461f87840d5876f318429d187c7744400dfc84eccb8e45

See more details on using hashes here.

File details

Details for the file boon_term-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: boon_term-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for boon_term-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51050dd91fc62502d686baa67d4b4636323828bc351e85732a90eef64b7ccefd
MD5 f5d8b76fc49e85fd918bb34ded426e87
BLAKE2b-256 fa4a68feaf299e51677cc577fcf46ce3b8f3820ade1bb7b2fb9759c63761ac84

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page