Expand description
§tui-realm
tui-realm is a framework for ratatui
to simplify the implementation of terminal user interfaces adding the possibility to work
with re-usable components with properties and states, as youâd do in React. But thatâs not all:
the components communicate with the ui engine via a system based on Messages and Events,
providing you with the possibility to implement update routines as happens in Elm.
In addition, the components are organized inside the View, which manages mounting/umounting, focus and event forwarding for you.
tui-realm also comes with a standard library of components, which can be added to your dependencies, that you may find very useful.
§Get started đ
â ïž Warning: currently tui-realm supports these backends: crossterm, termion
§Add tui-realm to your Cargo.toml đŠ
If you want the default features, just add tuirealm 1.x version:
tuirealm = "2"otherwise you can specify the features you want to add:
tuirealm = { version = "2", default-features = false, features = [ "derive", "serialize", "termion" ] }Supported features are:
derive(default): add the#[derive(MockComponent)]proc macro to automatically implementMockComponentforComponent. Read more.serialize: add the serialize/deserialize trait implementation forKeyEventandKey.crossterm: use the crossterm terminal backendtermion: use the termion terminal backend
§Create a tui-realm application đȘ
You can read the guide to get started with tui-realm on Github
§Run examples đ
Still confused about how tui-realm works? Donât worry, try with the examples:
-
demo: a simple application which shows how tui-realm works
cargo run --example demo
Re-exports§
pub use listener::EventListenerCfg;pub use listener::ListenerError;
Modules§
- Application
- Command
- events
- Listener
- props
- ratatui
- terminal
- Utils
Macros§
- A macro to generate a chain of
crate::SubClause::Andfrom a list of Ids with the casecrate::SubClause::IsMountedfor every id. - A macro to generate a chain of
crate::SubClause::Andfrom a list of Ids with the casecrate::SubClause::Notcontainingcrate::SubClause::IsMountedfor every id. - A macro to generate a chain of
crate::SubClause::Orfrom a list of Ids with the casecrate::SubClause::IsMountedfor every id.
Structs§
- The application defines a tui-realm application. It will handle events, subscriptions and the view too. It provides functions to interact with the view (mount, umount, query, etc), but also the main function:
Application::tick. - A consistent view into the terminal state for rendering a single frame.
- The props struct holds all the attributes associated to the component. Properties have been designed to be versatile for all kind of components, but without introducing too many attributes at the same time.
- Public type to define a subscription.
Enums§
- Error variants returned by
Application - Describes a single attribute in the component properties.
- Describes a âselectorâ to query an attribute on props. The selector must identify uniquely an attribute in the properties. Check each attribute documentation to see how theyâre supposed to be used, but remember that when implementing a component, youâre free to use each attribute as you prefer!
- An event raised by a user interaction
- When using event you can use this as type parameter if you donât want to use user events
- Poll strategy defines how to call
Application::pollon the event listener. - State describes a component state
- StateValue describes the value contained in a State
- A subclause indicates the condition that must be satisfied in order to forward
evtotarget. Usually clauses are single conditions, but there are also some special condition, to create âligaturesâ, which are: - An event clause indicates on which kind of event the event must be forwarded to the
targetcomponent. - An error returned by the view
Traits§
- The component describes the application level component, which is a wrapper around the
MockComponent, which, in addition to all the methods exposed by the mock, it will handle the event coming from theView. The Event are passed to theonmethod, which will eventually return aMsg, which is defined in your application as an enum. (Donât forget to derivePartialEqfor your enum). In your application you should have a Component for each element on your UI, but the logic to implement is very tiny, since the most of the work should already be done into theMockComponentand many of them are available in the standard library at https://github.com/veeso/tui-realm-stdlib. - A Mock Component represents a component which defines all the properties and states it can handle and represent and the way it should be rendered. It must also define how to behave in case of a
Cmd(command). Despite that, it wonât define how to behave after anEventand it wonât send anyMsg. The MockComponent is intended to be used as a reusable component to implement your application component. - The update trait defines the prototype of the function to be used to handle the events coming from the View.