tui-realm-stdlib
Developed by Christian Visintin
Current version: 0.6.3 (04/10/2021)
- tui-realm-stdlib
About tui-realm-stdlib 👑
tui-realm-stdlib is the standard component library for tui-realm.
Get started 🏁
⚠ Warning: tui-realm works only with crossterm as backend ⚠
Add tui-realm to your Cargo.toml 🦀
= "0.6.2"
Since this library requires crossterm too, you'll also need to add it to your Cargo.toml
= "0.20.0"
Latest version of tui-realm-stdlib requires tui-realm 0.6.0
= "0.6.0"
Examples
Want to have a demo of components? Try with examples
such as
Buy me a coffee ☕
If you like tui-realm-stdlib and you're grateful for the work I've done, please consider a little donation 🥳
Components 🎨
BarChart
A chart with bars. The bar chart can work both in "active" and "disabled" mode.
When in disabled mode, the chart won't be interactive, so you won't be able to move through data using keys. If you have more data than the maximum amount of bars that can be displayed, you'll have to update data to display the remaining entries
While in active mode (default) you can put as many entries as you wish. You can move with arrows and END/HOME keys
Events:
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Right |
None |
Move the cursor right |
KeyCode::Left |
None |
Move the cursor left |
KeyCode::End |
None |
Move "cursor" to the end of chart |
KeyCode::Home |
None |
Move "cursor" to the first entry of the chart |
KeyCode::Char(_) |
OnKey |
State: None.
Properties:
disabled: Sets the chart in disabled modewith_foreground: foreground colorwith_background: background colorwith_title: title for chartwith_label_style: Sets the style for data labelswith_max_bars: maximum amount of bars to display. If not provided, will be the maximum allowed by the area width.with_bar_style: sets style for barswith_bar_gap: sets gap for barswith_value_style: Sets style for valueswith_data: set data for chart. Is a vec of tuple of labels and u64push_record_back: Just push the provided record to the back of data (end)push_record_front: Just push the provided record to the front of data (begin)pop_record_front: Pops the first element of datapop_record_back: Pops the last element of data
Chart
A chart displayed on a cartesian axis system. Can work both in "active" and "disabled" mode.
When in disabled mode, the chart won't be interactive, so you won't be able to move through data using keys. If you have more data than the maximum amount of bars that can be displayed, you'll have to update data to display the remaining entries
While in active mode (default) you can put as many entries as you wish. You can move with arrows and END/HOME keys
Events:
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Right |
None |
Move the cursor right |
KeyCode::Left |
None |
Move the cursor left |
KeyCode::End |
None |
Move "cursor" to the end of chart |
KeyCode::Home |
None |
Move "cursor" to the first entry of the chart |
KeyCode::Char(_) |
OnKey |
State: None.
Properties:
disabled: Sets the chart in disabled modewith_foreground: foreground colorwith_background: background colorwith_title: title for chartwith_label_style: Sets the style for data labelswith_*_bounds: Something regarding the viewport; view tui-rs documentation (which doesn't exist actually). I don't know how it works actually.with_*_labels: Set labels for provided axiswith_*_style: Set style for provided axiswith_*_title: Set title for axiswith_data: set data for chart. Is a vec ofDatasetpush_record: Just push the provided record to the back of data (end)pop_record_front: Pops the first element of datapop_record_back: Pops the last element of data
Checkbox
A checkbox group. Provides the possibility to select between multiple options, when get_state is invoked returns a vector of index; each index represents the index of the item selected.
Events:
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Right |
None |
Increment the selected choice index by 1 |
KeyCode::Left |
None |
Decrement the selected choice index by 1 |
KeyCode::Char(' ') |
OnChange |
Check or uncheck the item at the current index |
KeyCode::Enter |
OnSubmit |
Just returns the selection |
KeyCode::Char(_) |
OnKey |
Update: Msg::OnChange if the selection changed, Msg::None otherwise.
State: the state returned is a VecOfUsize containing the indexes of the selected item in the checkbox group.
Properties:
with_color: foreground colorwith_inverted_colors: color used when item is at current indexwith_borders: set borders properties for componentwith_options: set checkbox optionswith_title: set checkbox titlewith_value: set selected by-default items by their indexrewind: if true, when moving beyond limits of component, the choice will be rewinded, instead of remaining the same
Input
An input text. Provides the possiblity to input a text with the possibility to set the input length and the input type (number, password, text). It also allows to use arrows to move the cursor inside of the input box. When get_state is invoked, returns the current content of the input as String or as Number based on the current input type.
Events:
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Backspace |
`OnChange | None` |
KeyCode::Delete |
`OnChange | None` |
KeyCode::Enter |
OnSubmit |
Submit input |
KeyCode::Left |
None |
Move cursor left |
KeyCode::Right |
None |
Move cursor right |
KeyCode::End |
None |
Move cursor at the end of input |
KeyCode::Home |
None |
Move cursor at the beginning of input |
KeyCode::Char(_) |
`OnChange | None` |
Update: Msg::OnChange if the value changed, Msg::None otherwise.
State: the state returned is a Str or an Unsigned based on the selected input type containing the current value of the input.
Properties:
with_foreground: foreground colorwith_background: background colorwith_borders: set borders properties for componentwith_label: set input labelwith_input: set the input typewith_input_len: set the maximum input lengthwith_value: set initial value for the input
Label
A text label. Provides the possibility to display a simple text, with the possibility to set modifiers and colors.
Events:
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Char(_) |
OnKey |
Return pressed key |
Update: None
State: None
Properties:
with_foreground: set foreground colorwith_background: set background colorbold: set text bolditalic: set text italicrapid_blink: set rapid blink for textreversed: reverses colorsslow_blinkset slow blink for teststrikethrough: set strikethrough for textunderlined: set underlined textwith_text: set label textwith_text_alignment: set text alignment
Line gauge
A line indicating progress. The progress bar provides the possibility to show the current progress and to show a label above it.
Events:
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Char(_) |
OnKey |
Return pressed key |
Update: None
State: None
Properties:
with_progbar_color: set progress bar colorwith_background: set background colorwith_progress: set progress. WARNING: must be in range 0.0,1.0with_borders: set border propertieswith_label: set progress bar labelwith_title: set progress bar titlewith_line_normal: use default linewith_line_rounded: use roundeed linewith_line_tick: use thick linewith_line_doubleduse double line
List
a list of rows with the possibility to scroll text with arrows. In order to scroll, the component must be active.
Events:
Events will be reported only when set as Scrollable
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Down |
OnKey |
Move cursor down |
KeyCode::Up |
OnKey |
Move cursor up |
KeyCode::PageDown |
OnKey |
Move cursor down by 8 |
KeyCode::PageUp |
OnKey |
Move cursor up by 8 |
KeyCode::End |
OnKey |
Move cursor to last item |
KeyCode::Home |
OnKey |
Move cursor to first item |
KeyCode::Char(_) |
OnKey |
Return pressed key |
Update: None
State: If scrollable, returns current list index, otherwise None
Properties:
with_foreground: set foreground colorwith_background: set background colorscrollable: mark the list as scrollablebold: set text bolditalic: set text italicrapid_blink: set rapid blink for textreversed: reverses colorsslow_blinkset slow blink for teststrikethrough: set strikethrough for textunderlined: set underlined textwith_borders: set border propertieswith_rows: set table entrieswith_title: set block title
Paragraph
A text paragraph. Like in HTML this has to be considered a block element, and supports multi-line texts with different styles. The text is automatically wrapped.
Events:
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Char(_) |
OnKey |
Return pressed key |
Update: None
State: None
Properties:
with_foreground: set foreground colorwith_background: set background colorbold: set text bolditalic: set text italicrapid_blink: set rapid blink for textreversed: reverses colorsslow_blinkset slow blink for teststrikethrough: set strikethrough for textunderlined: set underlined textwith_borders: set border propertieswith_texts: set paragraph textwith_titleset paragraph titlewith_text_alignment: set text alignmentwith_trim: select whether to trim rows when wrapping
Progress bar
A progress bar or basically a gauge. The progress bar provides the possibility to show the current progress and to show a label above it.
Events:
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Char(_) |
OnKey |
Return pressed key |
Update: None
State: None
Properties:
with_progbar_color: set progress bar colorwith_background: set background colorwith_progress: set progress. WARNING: must be in range 0.0,1.0with_borders: set border propertieswith_label: set progress bar labelwith_title: set progress bar title
Radio
A radio button group. Provides the possibility to select a single option in a group of options. When get_state is invoked returns the index of the selected option as Unsigned.
Events:
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Right |
OnChange |
Change the selected option to current item index |
KeyCode::Left |
OnChange |
Change the selected option to current item index |
KeyCode::Enter |
OnSubmit |
Just returns the index of the selected item |
KeyCode::Char(_) |
OnKey |
Update: Msg::OnChange if the choice changed, Msg::None otherwise.
State: the state returned is an Unsigned containing the index of the selected item in the radio group.
Properties:
with_color: foreground colorwith_inverted_colors: color used when item is at current indexwith_borders: set borders properties for componentwith_options: set radio optionswith_title: set radio titlewith_value: set default selected item by its indexrewind: if true, when moving beyond limits of component, the choice will be rewinded, instead of remaining the same
Select
A select like in HTML. Provides the possibility to select a single option in a group of options. When get_state is invoked returns the index of the selected option as Unsigned, but only if the selection tab is closed. Returns Payload::None otherwise. The tab can be opened with <ENTER>; once opened you can move with arrows to select the entry. To close the form, you need to press <ENTER> again. Once the tab is closed, a Msg::OnSubmit is raised with the selected index.
If the component loses focus, the selection tab is automatically closed
This component should have a variable size in the layout to be displayed properly. Please view the example: examples/select.rs.
Events:
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Up |
OnChange |
None |
KeyCode::Down |
OnChange |
None |
KeyCode::Enter |
OnSubmit |
None |
KeyCode::Char(_) |
OnKey |
Update: Msg::OnChange if the choice changed, Msg::None otherwise.
State: the state returned is an Unsigned containing the index of the selected item in the radio group.
Properties:
with_foreground: foreground colorwith_background: background colorwith_highlighted_color: a different color for highlighted entry;foregroundotherwisewith_highlighted_symbol: cursor for highlighted entry in selection tab.with_borders: set borders properties for componentwith_options: set select optionswith_title: set select titlewith_value: set default selected item by its indexrewind: if true, when moving beyond limits of component, the choice will be rewinded, instead of remaining the same
Sparkline
A sparkline chart.
Events:
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Char(_) |
OnKey |
State: None.
Properties:
with_foreground: foreground colorwith_background: background colorwith_label: label for sparklinewith_max_entries: maximum amount of entries to display. If not provided, will be the maximum allowed by the area width.with_data: set data for sparkline. Is a vec of u64push_record_back: Just push the provided record to the back of data (end)push_record_front: Just push the provided record to the front of data (begin)pop_record_front: Pops the first element of datapop_record_back: Pops the last element of data
Span
A span is an in-line component which supports text with different styles.
Events:
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Char(_) |
OnKey |
Return pressed key |
Update: None
State: None
Properties:
with_foreground: set foreground colorwith_background: set background colorbold: set text bolditalic: set text italicrapid_blink: set rapid blink for textreversed: reverses colorsslow_blinkset slow blink for teststrikethrough: set strikethrough for textunderlined: set underlined textwith_borders: set border propertieswith_spans: set paragraph textwith_titleset block titlewith_text_alignment: set text alignment
Table
a table of rows with the possibility to scroll text with arrows. In order to scroll, the component must be active.
Events:
Events will be reported only when set as Scrollable
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Down |
OnKey |
Move cursor down |
KeyCode::Up |
OnKey |
Move cursor up |
KeyCode::PageDown |
OnKey |
Move cursor down by 8 |
KeyCode::PageUp |
OnKey |
Move cursor up by 8 |
KeyCode::End |
OnKey |
Move cursor to last item |
KeyCode::Home |
OnKey |
Move cursor to first item |
KeyCode::Char(_) |
OnKey |
Return pressed key |
Update: None
State: If scrollable, returns current list index, otherwise None
Properties:
with_foreground: set foreground colorwith_background: set background colorscrollable: mark the list as scrollablebold: set text bolditalic: set text italicrapid_blink: set rapid blink for textreversed: reverses colorsslow_blinkset slow blink for teststrikethrough: set strikethrough for textunderlined: set underlined textwith_borders: set border propertieswith_headers: define headers for tablewith_col_spacing: spacing between columnswith_row_height: Height of each rowwith_table: set block title and table entries
Textarea
A textarea is like a paragraph, but has the possibility to scroll the text.
Events:
| Event | Message | Behaviour |
|---|---|---|
KeyCode::Down |
OnKey |
Move cursor down |
KeyCode::Up |
OnKey |
Move cursor up |
KeyCode::PageDown |
OnKey |
Move cursor down by 8 |
KeyCode::PageUp |
OnKey |
Move cursor up by 8 |
KeyCode::End |
OnKey |
Move cursor to last item |
KeyCode::Home |
OnKey |
Move cursor to first item |
KeyCode::Char(_) |
OnKey |
Return pressed key |
Properties:
with_foreground: set foreground colorwith_background: set background colorbold: set text bolditalic: set text italicrapid_blink: set rapid blink for textreversed: reverses colorsslow_blinkset slow blink for teststrikethrough: set strikethrough for textunderlined: set underlined textwith_borders: set border propertieswith_title: set block titlewith_texts: set and text spans
Utilities
The standard components library also exports the utils module, which provides these very handy functions:
- wrap_spans: Creates span lines from text spans, in order to wrap lines
- use_or_default_styles: use colors and modifiers of the text spans if not
Color::ResetorModifiers::empty(), otherwise use the properties defined theProps. - get_block: creates the block for the widget. If focus is true, the colors are applied, otherwise
Color::Reset.
Documentation 📚
The developer documentation can be found on Rust Docs at https://docs.rs/tuirealm
Contributing and issues 🤝🏻
Contributions, bug reports, new features and questions are welcome! 😉 If you have any question or concern, or you want to suggest a new feature, or you want just want to improve tui-realm-stdlib, feel free to open an issue or a PR.
Please follow our contributing guidelines
Changelog ⏳
View tui-realm's changelog HERE
License 📃
tui-realm-stdlib is licensed under the MIT license.
You can read the entire license HERE