This document contains the reference and the example image for all the components exposed in the standard library.
For each component you'll find its command API, the Properties it can handle and the State it'll return.
Aside of this, keep in mind that Every component will also reserve these two properties, as specified in the tui-realm documentation:
Attribute::Display(AttrValue::Flag): ifFalsethe component WON'T be rendered.Attribute::Focus(AttrValue::Flag): indicates whether the component is active or not. This property is always AUTOMATICALLY handled by the View.
This library also uses a few Custom attributes. These custom attributes are obviously of kind Attribute::Custom and their keys are defined in this document with a $ before their names. You can access to these values directly from the library module tui_realm_stdlib::props::$KEY_NAME.
✨ Check me out ✨
cargo run --example bar-chart
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
Commands:
| Cmd | CmdResult | Behaviour |
|---|---|---|
GoTo(Begin) |
None |
Move "cursor" to the first entry of the chart |
GoTo(End) |
None |
Move "cursor" to the end of chart |
Move(Left) |
None |
Move the cursor left |
Move(Right) |
None |
Move the cursor right |
State: None.
Properties:
Background(Color): background colorCustom($BAR_CHART_BARS_GAP, Size): sets gap for barsCustom($BAR_CHART_BARS_STYLE, Style): sets style for barsCustom($BAR_CHART_LABEL_STYLE, Style): Sets the style for data labelsCustom($BAR_CHART_MAX_BARS, Length): maximum amount of bars to display. If not provided, will be the maximum allowed by the area width.Custom($BAR_CHART_VALUES_STYLE, Style): Sets style for valuesDataset(Payload(LinkedList(Tup2(String, U64)))): set data for chart. Is a vec of tuple of labels and u64Disabled(Flag): Sets the chart in disabled modeForeground(Color): foreground colorTitle(Title): title for chartWidth(Size): Define bar width
✨ Check me out ✨
cargo run --example canvas
Canvas component can be used to draw shapes on the terminal.
Commands: None
State: None
Properties:
Background(Color): background colorBorders(Borders): set borders properties for componentCustom($CANVAS_X_BOUNDS, Payload(Tup2(F64, F64))): Something regarding the viewport; view tui-rs documentation (which doesn't exist actually). I don't know how it works actually.Custom($CANVAS_Y_BOUNDS, Payload(Tup2(F64, F64))): Something regarding the viewport; view tui-rs documentation (which doesn't exist actually). I don't know how it works actually.Foreground(Color): foreground colorShape(Payload(Vec(Shape))): set shapes for canvas.Title(Title): title for chart
✨ Check me out ✨
cargo run --example 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
Commands:
| Cmd | CmdResult | Behaviour |
|---|---|---|
GoTo(Begin) |
None |
Move "cursor" to the first entry of the chart |
GoTo(End) |
None |
Move "cursor" to the end of chart |
Move(Left) |
None |
Move the cursor left |
Move(Right) |
None |
Move the cursor right |
State: None.
Properties:
Background(Color): background colorBorders(Borders): set borders properties for componentCustom($CHART_X_BOUNDS, Payload(Tup2(F64, F64))): Something regarding the viewport; view tui-rs documentation (which doesn't exist actually). I don't know how it works actually.Custom($CHART_X_LABELS, Payload(Vec(String))): Set labels for x axisCustom($CHART_X_STYLE, Style): Set style for x axisCustom($CHART_X_TITLE, String): Set title for x axisCustom($CHART_Y_BOUNDS, Payload(Tup2(F64, F64))): Something regarding the viewport; view tui-rs documentation (which doesn't exist actually). I don't know how it works actually.Custom($CHART_Y_LABELS, Payload(Vec(String))): Set labels for y axisCustom($CHART_Y_STYLE, Style): Set style for x axisCustom($CHART_Y_TITLE, String): Set title for x axisDataset(Payload(Vec(Dataset))): set data for chart. Is a vec ofDatasetDisabled(Flag): Sets the chart in disabled modeFocusStyle(Style): inactive styleForeground(Color): foreground colorTitle(Title): title for chart
✨ Check me out ✨
cargo run --example 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.
Commands:
| Cmd | CmdResult | Behaviour |
|---|---|---|
Move(Left) |
None |
Decrement the selected choice index by 1 |
Move(Right) |
None |
Increment the selected choice index by 1 |
Submit |
Submit |
Just returns the selection |
Toggle |
Changed |
Check or uncheck the item at the current index |
State: the state returned is Vec(Usize) containing the indexes of the selected item in the checkbox group.
Properties:
Background(Color): color used when item is at current indexBorders(Borders): set borders properties for componentContent(Payload(Vec(String))): set checkbox optionsFocusStyle(Style): inactive styleForeground(Color): foreground colorRewind(Flag): if true, when moving beyond limits of component, the choice will be rewinded, instead of remaining the sameTitle(Title): set checkbox titleValue(Payload(Vec(Usize))): set selected by-default items by their index
✨ Check me out ✨
cargo run --example container
A container works a div. It is just an empty container which can contain other components.
You can mount children in it using the children() method on the constructor or with the children property when implementing the Component.
By default all Commands are forwarded to all children and a Batch of Command result is returned, but you can obviously implement it as you want overriding the perform() method in the Component.
While for attr() it will apply the properties for all the children by default. You can override this behaviour.
Commands: depends on children
State: None
Properties:
Background(Color): default background colorBorders(Borders): set borders properties for containerForeground(Color): default foreground colorLayout(Layout): set the layout to use to render children. Children will be rendered in order by index (soconstraints[0] => children[0], ...)Title(Title): set title for div
✨ Check me out ✨
cargo run --example 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 state is invoked, returns the current content of the input as String or as Number based on the current input type.
Commands:
| Command | Result | Behaviour |
|---|---|---|
Cancel |
`Changed | None` |
Delete |
`Changed | None` |
GoTo(Begin) |
None |
Move cursor at the end of input |
GoTo(End) |
None |
Move cursor at the beginning of input |
Move(Left) |
None |
Move cursor left |
Move(Right) |
None |
Move cursor right |
Submit |
`Submit | None` |
Type(ch) |
`Changed | None` |
State: the state returned is a State::Single(StateValue::String) if the input is valid, State::None otherwise.
Properties:
Background(Color): background colorBorders(Borders): set borders properties for componentCustom($INPUT_INVALID_STYLE, Style): Set style to apply to component when input is invalidCustom($INPUT_PLACEHOLDER, String): Set a placeholder to display when the input is emptyCustom($INPUT_PLACEHOLDER_STYLE, Style): Set style for placeholder textDisplay(Flag): if False component is hiddenFocusStyle(Style): style for when component is not activeForeground(Color): foreground colorInputLength(Length): set the maximum input lengthInputType(InputType): set the input typeTitle(Title): set input box titleValue(String): set value for the input
✨ Check me out ✨
cargo run --example label
A text label. Provides the possibility to display a simple text, with the possibility to set modifiers and colors.
Commands: None
State: None
Properties:
Alignment(Alignment): set text alignmentBackground(Color): set background colorForeground(Color): set foreground colorText(String): set label textTextProps(TextModifiers): set text modifiers
✨ Check me out ✨
cargo run --example line_gauge
A line indicating progress. The progress bar provides the possibility to show the current progress and to show a label above it.
Commands: None
State: None
Properties:
Background(Color): set background colorBorders(Borders): set border propertiesForeground(Color): set progress bar colorText(String): set progress bar labelTextProps(TextModifiers): set text modifiersTitle(Title): set progress bar titleValue(Payload(One(F64))): set progress. WARNING: must be in range 0.0,1.0Style(Payload(One(U8)))defines line gauge style. Allowed values are:$LINE_GAUGE_STYLE_NORMAL$LINE_GAUGE_STYLE_DOUBLE$LINE_GAUGE_STYLE_ROUND$LINE_GAUGE_STYLE_THICK
✨ Check me out ✨
cargo run --example list
a list of rows with the possibility to scroll text with arrows. In order to scroll, the component must be active.
Commands:
Events will be reported only when set as Scrollable
| Cmd | CmdResult | Behaviour |
|---|---|---|
GoTo(Begin) |
`Changed | None` |
GoTo(End) |
`OnKey | None` |
Move(Down) |
`OnKey | None` |
Move(Up) |
`OnKey | None` |
Scroll(Down) |
`OnKey | None` |
Scroll(Up) |
`OnKey | None` |
State: If scrollable, returns current list index as State(One(Usize)), otherwise None
Properties:
Background(Color): set background colorBorders(Borders): set border propertiesContent(Table): set entries as a tableFocusStyle(Style): inactive styleForeground(Color): set foreground colorRewind(Flag): rewind list if boundaries are reachedScroll(Flag): set whether list is scrollable (interactive)ScrollStep(Length): set scroll stepTextProps(TextModifiers): set text modifiersTitle(Title): set block titleValue(Payload(One(Usize))): set selected row in list (works only ifscrollable)
✨ Check me out ✨
cargo run --example 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.
Commands: None
State: None
Properties:
Alignment(Alignment): set text alignmentBackground(Color): set background colorBorders(Borders): set border propertiesForeground(Color): set foreground colorText(Payload(Vec(TextSpan))): set paragraph textTextProps(TextModifiers): set text modifiersTextWrap(Flag): select whether to trim rows when wrappingTitle(Title)set paragraph title
Phantom is a component which doesn't render and has no property. It is sole purpose is to be a global listener for some kinds of events.
This component suits well to work as a subscriber for some global events (such as an ESC key to terminate).
Commands: None
State: None
Properties: None
✨ Check me out ✨
cargo run --example 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.
Commands: None
State: None
Properties:
Background(Color): set background colorBorders(Borders): set border propertiesForeground(Color): set progress bar colorText(String): set progress bar labelTextProps(TextModifiers): set text modifiersTitle(Title): set progress bar titleValue(Payload(One(F64))): set progress. WARNING: must be in range 0.0,1.0
✨ Check me out ✨
cargo run --example 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.
Commands:
| Cmd | CmdResult | Behaviour |
|---|---|---|
Move(Left) |
Changed |
Change the selected option to current item index |
Move(Right) |
Changed |
Change the selected option to current item index |
Submit |
Submit |
Just returns the index of the selected item |
State: the state returned is One(Usize) containing the index of the selected item in the radio group.
Properties:
Background(Color): color used when item is at current indexBorders(Borders): set borders properties for componentContent(Payload(Vec(String))): set radio optionsFocusStyle(Style): inactive styleForeground(Color): foreground colorRewind(Flag): if true, when moving beyond limits of component, the choice will be rewinded, instead of remaining the sameTitle(Title): set radio titleValue(Payload(One(Usize))): set default selected item by its index
✨ Check me out ✨
cargo run --example select
A select like in HTML. Provides the possibility to select a single option in a group of options. When state is invoked returns the index of the selected option as Unsigned, but only if the selection tab is closed. Returns State::None otherwise. The tab can be opened with Cmd::Submit; once opened you can move with arrows to select the entry. To close the form, you need to press Cmd::Submit again. Once the tab is closed, a CmdResult::Submit 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.
Commands:
| Command | Result | Behaviour |
|---|---|---|
Move(Down) |
Changed |
None |
Move(Up) |
Changed |
None |
Cancel |
Changed |
The tab is closed and the value set before opening the tab is restored |
Submit |
Submit |
None |
State: the state returned is One(Usize) containing the index of the selected item in the radio group. This state is returned only when the select is closed; otherwise None is returned
Properties:
Background(Color): background colorBorders(Borders): set borders properties for componentContent(Payload(Vec(String))): set select optionsFocusStyle(Style): inactive styleForeground(Color): foreground colorHighlightedColor(Color): a different color for highlighted entry;foregroundotherwiseHighlightedStr(String): cursor for highlighted entry in selection tab.Rewind(Flag): if true, when moving beyond limits of component, the choice will be rewinded, instead of remaining the sameTitle(Title): set select titleValue(Payload(One(Usize))): set default selected item by its index
✨ Check me out ✨
cargo run --example span
A span is an in-line component which supports text with different styles.
Commands: None
State: None
Properties:
Alignment(Alignment): set text alignmentBackground(Color): set background colorForeground(Color): set foreground colorText(Payload(Vec(TextSpan)))set text spansTextProps(TextModifiers): set text modifiers
✨ Check me out ✨
cargo run --example sparkline
A sparkline chart.
Commands: None
State: None.
Properties:
Background(Color): background colorDataset(Payload(Vec(U64))): set data for sparkline. Is a vec of u64Foreground(Color): foreground colorTitle(Title): label for sparklineWidth(Length): maximum amount of entries to display. If not provided, will be the maximum allowed by the area width.
✨ Check me out ✨
cargo run --example spinner
A spinner is a spinner indicating a loading. It has a sequence of char to iterate over and on each view() call the step is increased by one.
So for example the sequence may be "⣾⣽⣻⢿⡿⣟⣯⣷", so at first view ⣾ will be rendered, on the 2nd step ⣽, etc.
Commands: None
State: None
Properties:
Background(Color): set background colorForeground(Color): set foreground colorText(String)set the spinner sequence. Each char of the string represents a step
✨ Check me out ✨
cargo run --example table
a table of rows with the possibility to scroll text with arrows. In order to scroll, the component must be active.
Commands:
Events will be reported only when set as Scrollable
| Cmd | CmdResult | Behaviour |
|---|---|---|
GoTo(Begin) |
`Changed | None` |
GoTo(End) |
`Changed | None` |
Move(Down) |
`Changed | None` |
Move(Up) |
`Changed | None` |
Scroll(Down) |
`Changed | None` |
Scroll(Up) |
`Changed | None` |
State: If scrollable, returns current One(Usize(index)), otherwise None
Properties:
Background(Color): set background colorBorders(Borders): set border propertiesContent(Table): set tableCustom($TABLE_COLUMN_SPACING, Size): column spacingFocusStyle(Style): inactive styleForeground(Color): set foreground colorHeight(Size): set row heightHighlightedColor(Color): set highlighted colorHighlightedStr(String): set highlighted stringRewind(Flag): rewind list if boundaries are reachedScroll(Flag): set whether is scrollableScrollStep(Length): set scroll stepText(Payload(Vec(String))): set table headersTextProps(TextModifiers): set text modifiersTitle(Title): set block titleValue(Payload(One(Usize))): set selected row in list (works only ifscrollableWidth(Payload(Vec(U16))): set col widths
✨ Check me out ✨
cargo run --example textarea
A textarea is like a paragraph, but has the possibility to scroll the text.
Commands:
| Cmd | Result | Behaviour |
|---|---|---|
GoTo(Begin) |
None |
Move cursor to first item |
GoTo(End) |
None |
Move cursor to last item |
Move(Down) |
None |
Move cursor down |
Move(Up) |
None |
Move cursor up |
Scroll(Down) |
None |
Move cursor down by 8 |
Scroll(Up) |
None |
Move cursor up by 8 |
Properties:
Background(Color): set background colorBorders(Borders): set border propertiesFocusStyle(Style): inactive styleForeground(Color): set foreground colorHighlightedStr(String): set highlighted stringScrollStep(Length): set scroll stepText(Payload(Vec(TextSpan))): set text spansTextProps(TextModifiers): set text modifiersTitle(Title): set block title
State: None
















