module

Term2

Term2 is a Crystal port of the Bubble Tea terminal UI library.

Constants

KEY_NAMES = {KeyType::Null => "ctrl+@", KeyType::CtrlA => "ctrl+a", KeyType::CtrlB => "ctrl+b", KeyType::CtrlC => "ctrl+c", KeyType::CtrlD => "ctrl+d", KeyType::CtrlE => "ctrl+e", KeyType::CtrlF => "ctrl+f", KeyType::CtrlG => "ctrl+g", KeyType::CtrlH => "ctrl+h", KeyType::Tab => "tab", KeyType::CtrlJ => "ctrl+j", KeyType::CtrlK => "ctrl+k", KeyType::CtrlL => "ctrl+l", KeyType::Enter => "enter", KeyType::CtrlN => "ctrl+n", KeyType::CtrlO => "ctrl+o", KeyType::CtrlP => "ctrl+p", KeyType::CtrlQ => "ctrl+q", KeyType::CtrlR => "ctrl+r", KeyType::CtrlS => "ctrl+s", KeyType::CtrlT => "ctrl+t", KeyType::CtrlU => "ctrl+u", KeyType::CtrlV => "ctrl+v", KeyType::CtrlW => "ctrl+w", KeyType::CtrlX => "ctrl+x", KeyType::CtrlY => "ctrl+y", KeyType::CtrlZ => "ctrl+z", KeyType::Esc => "esc", KeyType::CtrlBackslash => "ctrl+\\", KeyType::CtrlCloseBracket => "ctrl+]", KeyType::CtrlCaret => "ctrl+^", KeyType::CtrlUnderscore => "ctrl+_", KeyType::Backspace => "backspace", KeyType::Runes => "runes", KeyType::Up => "up", KeyType::Down => "down", KeyType::Right => "right", KeyType::Left => "left", KeyType::ShiftTab => "shift+tab", KeyType::Home => "home", KeyType::End => "end", KeyType::CtrlHome => "ctrl+home", KeyType::CtrlEnd => "ctrl+end", KeyType::ShiftHome => "shift+home", KeyType::ShiftEnd => "shift+end", KeyType::CtrlShiftHome => "ctrl+shift+home", KeyType::CtrlShiftEnd => "ctrl+shift+end", KeyType::PgUp => "pgup", KeyType::PgDown => "pgdown", KeyType::CtrlPgUp => "ctrl+pgup", KeyType::CtrlPgDown => "ctrl+pgdown", KeyType::Delete => "delete", KeyType::Insert => "insert", KeyType::Space => " ", KeyType::CtrlUp => "ctrl+up", KeyType::CtrlDown => "ctrl+down", KeyType::CtrlRight => "ctrl+right", KeyType::CtrlLeft => "ctrl+left", KeyType::ShiftUp => "shift+up", KeyType::ShiftDown => "shift+down", KeyType::ShiftRight => "shift+right", KeyType::ShiftLeft => "shift+left", KeyType::CtrlShiftUp => "ctrl+shift+up", KeyType::CtrlShiftDown => "ctrl+shift+down", KeyType::CtrlShiftLeft => "ctrl+shift+left", KeyType::CtrlShiftRight => "ctrl+shift+right", KeyType::F1 => "f1", KeyType::F2 => "f2", KeyType::F3 => "f3", KeyType::F4 => "f4", KeyType::F5 => "f5", KeyType::F6 => "f6", KeyType::F7 => "f7", KeyType::F8 => "f8", KeyType::F9 => "f9", KeyType::F10 => "f10", KeyType::F11 => "f11", KeyType::F12 => "f12", KeyType::F13 => "f13", KeyType::F14 => "f14", KeyType::F15 => "f15", KeyType::F16 => "f16", KeyType::F17 => "f17", KeyType::F18 => "f18", KeyType::F19 => "f19", KeyType::F20 => "f20", KeyType::FocusIn => "focus_in", KeyType::FocusOut => "focus_out"}

Human-readable names for key types.

Maps KeyType enum values to their string representations used in Key#to_s and for matching in Key#matches?.

Term2::KEY_NAMES[KeyType::CtrlC] # => "ctrl+c"
Term2::KEY_NAMES[KeyType::Up]    # => "up"
Term2::KEY_NAMES[KeyType::F1]    # => "f1"
NO_TAB_CONVERSION = -1

NoTabConversion can be passed to TabWidth to disable tab replacement

TAB_WIDTH_DEFAULT = 4

Tab width default

VERSION = "0.1.0"

Class methods

batch(*cmds : Cmd) : Cmd

Batch performs a bunch of commands concurrently with no ordering guarantees. Use a Batch to return several commands from Init or Update.

def init : Term2::Cmd
  Term2.batch(load_data_cmd, start_timer_cmd)
end
Source
get_first_rune_as_string(str : String) : String

Gets the first UTF-8 rune from a string

Source
has_dark_background=(has_dark_background : Bool)

Global setting for adaptive colors

Source
has_dark_background?

Global setting for adaptive colors

Source
height(str : String) : Int32

Measure height of rendered string (line count)

Source
join_horizontal(pos : Position, blocks : Array(String)) : String
Source
join_horizontal(pos : Float64, blocks : Array(String)) : String
Source
join_horizontal(pos : Position, *blocks : String) : String

Join strings horizontally with alignment

Source
join_horizontal(pos : Float64, *blocks : String) : String
Source
join_vertical(pos : Position, blocks : Array(String)) : String
Source
join_vertical(pos : Float64, blocks : Array(String)) : String
Source
join_vertical(pos : Position, *blocks : String) : String

Join strings vertically with alignment

Source
join_vertical(pos : Float64, *blocks : String) : String
Source
log_to_file(path : String, prefix : String) : File

Log to a file with prefix, returning the opened file.

Source
new_renderer(_io : IO, *_opts) : LipglossRenderer
Source
new_style

Create a new style (convenience)

Source
place(width : Int32, height : Int32, h_pos : Position, v_pos : Position, content : String) : String

Place content within a box of given dimensions

Source
place_horizontal(width : Int32, pos : Position, content : String) : String
Source
place_vertical(height : Int32, pos : Position, content : String) : String
Source
quit

Quit is a command that tells the program to exit.

Source
run(model : M, input : IO | Nil = STDIN, output : IO = STDOUT, options : ProgramOptions = ProgramOptions.new) forall M

Dispatcher bridges commands to the program's message mailbox. Run the program with the given model.

Source
sequence(*cmds : Cmd) : Cmd

Sequence runs the given commands one at a time, in order. Contrast this with Batch, which runs commands concurrently.

Source
setup_logging_from_env

Configure Log from environment (LOG_LEVEL, LOG_OUTPUT)

Source
size(str : String) : Tuple(Int32, Int32)

Get both width and height

Source
style_ranges(str : String, ranges : Array(Range)) : String
Source
style_runes(str : String, indices : Array(Int32), matched : Style, unmatched : Style) : String

Apply styles to specific rune (grapheme) indices.

Source
width(str : String) : Int32

Measure width of rendered string (max line width)

Source

Nested types