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 callingStatusBar
just makes a very small data structure that holds all the data required to build theStatusBar
, but until you callbuild
its measurements, its specs are all indeterminate. Callingbuild
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 withrender()
. - Everything is automatic! Where do I position the
Left Status
text? Where doesCenter Status
go? What aboutRight Status
? We don't care.StatusBar
figures it out (actually, thespacing=RowSpacing.SPACE_BETWEEN
) value given toRow
inStatusBar
forces the desiredStatusBar
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
Built Distribution
Hashes for compot_ui-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cf975daedd960ec0314649e4d11b7593b4569dab549ed88ad5115dd2daf186b |
|
MD5 | 814dd0f04647ae7a574f753dcb5915e5 |
|
BLAKE2b-256 | 53e62d4654c23332bc3100f2be9bbc272a5ee8263036f2fbb4ebbed3803619e2 |