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 = "3"otherwise you can specify the features you want to add:
tuirealm = { version = "3", default-features = false, features = [ "derive", "serialize", "termion" ] }Supported features are:
derive(default): add the#[derive(MockComponent)]proc macro to automatically implementMockComponentforComponent. Read more.async-ports: add support for async portsserialize: 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
- Application
- command
- Command
- event
- events
- listener
- Listener
- macros
- props
- props
- ratatui
- ratatui
- terminal
- terminal
- utils
- Utils
Macros§
- subclause_
and - A macro to generate a chain of
crate::SubClause::AndManyfrom a list of Ids with the casecrate::SubClause::IsMountedfor every id. - subclause_
and_ not - A macro to generate a chain of
crate::SubClause::Andfrom a list of Ids with the casecrate::SubClause::Notcontainingcrate::SubClause::IsMountedfor every id. - subclause_
or - A macro to generate a chain of
crate::SubClause::OrManyfrom a list of Ids with the casecrate::SubClause::IsMountedfor every id.
Structs§
- Application
- 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. - Frame
- A consistent view into the terminal state for rendering a single frame.
- Props
- 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.
- Sub
- Public type to define a subscription.
Enums§
- Application
Error - Error variants returned by
Application - Attr
Value - Describes a single attribute in the component properties.
- Attribute
- 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!
- Event
- An event raised by a user interaction
- NoUser
Event - When using event you can use this as type parameter if you donât want to use user events
- Poll
Strategy - Poll strategy defines how to call
Application::pollon the event listener. - State
- State describes a component state
- State
Value - StateValue describes the value contained in a State
- SubClause
- 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: - SubEvent
Clause - An event clause indicates on which kind of event the event must be forwarded to the
targetcomponent. - View
Error - An error returned by the view
Traits§
- Component
- 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. - Injector
- An injector is a trait object which can provide properties to inject to a certain component.
The injector is called each time a component is mounted, providing the id of the mounted
component and may return a list of (
Attribute,AttrValue) to inject. - Mock
Component - 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. - Update
- The update trait defines the prototype of the function to be used to handle the events coming from the View.
Attribute Macros§
- async_
trait async-ports