Aptivi - Manual
ProjectsWebsiteBlog
Terminaux - Manual
Terminaux - Manual
  • Welcome!
  • Breaking changes
    • API v1.0
    • API v2.0
    • API v3.0
    • API v4.0
    • API v5.0
    • API v6.0
    • API v7.0
  • Usage
    • Preface
    • Console Tools
      • Console Checker
        • Console Size Requirements
      • Image Rendering
        • Icons
      • Console Writers
        • Individual Writers
        • Cyclic Writers
          • Geometric Shapes
          • Charts
          • Text
          • Artistic
          • Progress Bars
          • Lists and Calendars
          • Miscellaneous
        • Informational Boxes
      • Textual UI
        • Interactive TUI
        • Console Screen
        • Console Resize Listener
        • VT Sequences
      • Console Wrapper
      • Console Colors
      • Color Templates
      • Presentation System
      • Console Extensions
      • Nerd Fonts
      • Terminal Info
      • Test Fixtures
      • Terminal Structures
      • Console Logging
    • Input Reader
      • Shells
        • Shell Structure
          • Help System
          • Command Parsing
          • Command Information
          • Command Switches
          • Shell Presets
          • Command Aliasing
      • Other Input
        • Keybindings
        • Choice-based inputs
        • Editors and Viewers
        • Figlet Font Selector
        • Color Wheel
        • Spinner Selector
      • Reader State
      • Reader Settings
      • Syntax Highlighting
      • Pointer Events
    • Color Sequences
      • Color Model Conversions
      • Color Model Parsing
      • Interop with System.Drawing.Color
  • Report an issue
  • Source code
  • API Reference
Powered by GitBook
On this page
  • Examples
  • Defining Keybindings
Edit on GitHub
  1. Usage
  2. Console Tools

Textual UI

More control in your TUIs!

Last updated 5 months ago

This feature is the new form of interactive TUIs that not only allow you to make an interactive TUI based on a set of data for either a single pane or two panes, but you can also make your own interactive applications seamlessly by separating the rendering code and the key handling code into small functions. This achieves the goal of making textual UI code maintenance easier, while providing the most dynamic UI setup along with support for resize thanks to the feature.

To get started using this awesome feature, you can create a new class that implements the TextualUI abstract class and overrides the Render() function. Inside the function, you can return a string that consists of VT sequences resulting from several console writers, especially the renderables. You can find out more about the renderables here.

Before this feature has been implemented, the interactive TUI feature consisted of just data arrays with two panes, which made cases that required something outside that scope unsolvable. The new feature promises to remove this limitation. Meanwhile, you can still use the older interactive TUI, which was first implemented in the Nitrocid KS 0.1.0 milestones in 2022, .

In the class, there are several properties that you can modify at your discretion, such as the name and the refresh delay. You can use the following properties:

  • Guid: Unique ID for the textual UI (reserved for future use)

  • State: State of the textual UI, which is one of the following:

    • Ready: This textual UI is ready, but hasn't started yet.

    • Rendering: This textual UI is waiting for the render code to complete.

    • Waiting: This textual UI is waiting for user input.

    • Busy: This textual UI is busy because it's processing user input.

    • Bailing: This textual UI is about to exit and go back to the Ready state.

  • Name: Display name of the textual UI (reserved for future use)

  • RefreshDelay: Sets the refresh delay in milliseconds. If set to zero or less than zero, this TUI doesn't refresh.

  • Keybindings: List of keybindings that you can use within the TUI.

  • Fallback: Fallback binding in case a key doesn't bind to anything.

  • Renderables: List of renderables that get rendered on top of what the Render() function has rendered.

If you want the TUI to refresh in the next render, you'll have to call the RequireRefresh() function, which calls the refresh requirement function on the screen instance.

You can edit the Keybindings property to add your custom keybindings, but it's preferrable to either place them in a constructor or in the overridden value, and to define the delegates in separate private functions inside the UI class. Also, make sure that you don't place conflicting keybindings when trying to add them.

In addition to that, you can also access the TextualUITools class to perform the following operations:

  • RunTui(): Starts the TUI main loop, clears the screen, waits for user input, and processes it until the TUI has been requested to exit.

  • ExitTui(): Sets the state of the interactive TUI to Bailing so that the TUI can exit gracefully.

Examples

There are two examples as defined in the test application bundled with the source code of Terminaux:

This example provides you with a simple interactive TUI showing three boxes that you can control using the keybindings defined in the constructor of the interactive TUI.

Here's the companion code to start the interactive TUI for the above class:

Here's the resulting picture of the interactive TUI:

This example provides you with a refreshing interactive TUI showing three boxes, one of which is constantly changing color according to the number of frames rendered, that you can control using the keybindings defined in the constructor of the interactive TUI.

Here's the companion code that executes the above TUI class:

Here's the resulting picture for the TUI:

Defining Keybindings

When defining keybindings, it's recommended to do so from either the constructor of the interactive TUI or in the overridden value of the Keybindings list, except if you want this keybinding list to always change during the runtime of the textual UI, such as the color selector. We also recommend to define their actions in separate private functions, passing in the parameters as needed.

  • To define a keybinding in your interactive TUI, use the Keybindings.Add() statement to pass in a tuple of the following two variables:

    • An action delegate or lambda function that tells the interactive TUI what to do. The following four arguments are optional for lambda expressions, but required for delegates:

      • Interactive TUI instance that specifies the running TUI.

  • To remove a keybinding in your interactive TUI, use the Keybindings.RemoveAt() function.

  • To remove all keybindings in your interactive TUI, use the Keybindings.Clear() function.

A instance that matches the key and its modifiers (mouse or keyboard) that you want to bind a specific action to.

Keyboard press info defined by the struct.

Mouse event info defined by the class.

screen
Cyclic Writers
here
Keybinding
ConsoleKeyInfo
PointerEventContext
https://github.com/Aptivi/Terminaux/blob/main/Terminaux.Console/Fixtures/Cases/CaseData/TextualUiSimpleTestData.cs
https://github.com/Aptivi/Terminaux/blob/main/Terminaux.Console/Fixtures/Cases/Tui/TestScreenPartVisibilityRefreshTui.cs
https://github.com/Aptivi/Terminaux/blob/main/Terminaux.Console/Fixtures/Cases/CaseData/TextualUiRefreshTestData.cs
https://github.com/Aptivi/Terminaux/blob/main/Terminaux.Console/Fixtures/Cases/Tui/TestScreenPartVisibilityTui.cs