Skip to main content

A small, stateless, fully compositional TUI framework.

Project description

compot

Compot is a simple, compositional framework for building TUIs. It is heavily inspired by jetpack-compose and strives to be its equivalent in TUIs.

Currently, it is in its early stages of development as I do not have much time to dedicate it and am developing it for internal use at work. As requirements expand, so too will compot.

Features

  • Abstractions beyond low-level curses
  • Fully Stateless
  • Lazy Rendering
  • Fully written in python

What all this means is that curses development becomes a breeze. Here's an example:

@Composable
def StatusBar(
    content: Tuple[Tuple[ComposableT, ...],
                   Tuple[ComposableT, ...],
                   Tuple[ComposableT, ...]],
    measurement: MeasurementSpec = MeasurementSpec.INJECTED()
):
    return Row(
        children=content,
        measurement=measurement,
        layout=LayoutSpec.FILL,
        spacing=RowSpacing.SPACE_BETWEEN
    )

This is the source code for the StatusBar widget. To invoke it, run it with:

StatusBar(
    (
        Text('Left Status'),
        Text('Center Status'),
        Text('Right Status')
    ),
    measurement=MeasurementSpec.xywh(0, 0, bar_w, 1)
).build().render()

Only the top level element needs to know its measurements (as of now, there is no MainWindow-like widget that would handle this for you automatically), and everything else gathers its measurements automatically

Note some of the cool things here:

  • Until you call Composable.build() nothing actually gets invoked. Simply calling StatusBar just makes a very small data structure that holds all the data required to build the StatusBar, but until you call build its measurements, its specs are all indeterminate. Calling build then forces the UI element to actually figure out its dimensions and create all the required objects. Usually this requires the widget to ask its child widgets to predict how large they are going to be, but even then, only the bare minimum is done to actually measure the widgets. build then constructs a graph that is rendered with render().
  • Everything is automatic! Where do I position the Left Status text? Where does Center Status go? What about Right Status? We don't care. StatusBar figures it out (actually, the spacing=RowSpacing.SPACE_BETWEEN) value given to Row in StatusBar forces the desired StatusBar behavior.

The downsides

  • The codebase is in a state of improvement and development.
  • The API is bound to change.
  • The number of widgets is too small to make a usable product out of this as of now.

Requirements

The only requirement is that you have python > 3.8. I do not plan to support lower versions of python and cannot help in supporting them.

Installing

You should be able to get up and running by running

pip install compot-ui

Tests

Tests are very rudimentary and you must manually test all the widgets that are available currently. Check the tests/ui directory and run each of the scripts to see how they appear.

Licensing

Copyright 2022 Marko Vejnovic

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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

compot-ui-0.2.3.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

compot_ui-0.2.3-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file compot-ui-0.2.3.tar.gz.

File metadata

  • Download URL: compot-ui-0.2.3.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for compot-ui-0.2.3.tar.gz
Algorithm Hash digest
SHA256 56ffe96bb19b00abd0bf42d96df51665bdcb06d7f506a1e007aa5fd9ecb9a1f8
MD5 b14ac2403a20142beff1619267406c67
BLAKE2b-256 37501dc186e57095a68b767937c2e771887b6388afc5c2ef91cb1a6702db50a0

See more details on using hashes here.

File details

Details for the file compot_ui-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: compot_ui-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for compot_ui-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a4b763f6e6f5a458b66b01ce7413905d0d93e11c511f24bab76f70a1958d66cd
MD5 cb15db907bb711bd44c109d1bcb5d7fe
BLAKE2b-256 50b0fcd8fea98d38e4dfc48a653756e40534af0c162541caef78d845d1845c33

See more details on using hashes here.

Supported by

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