class Termisu
- Termisu
- Reference
- Object
Overview
Version information for Termisu.
All version components are parsed from shard.yml at compile time. Format: MAJOR.MINOR.PATCH[-STATE] (e.g., "0.1.0-alpha", "1.0.0")
Defined in:
termisu.crtermisu/log.cr
termisu/version.cr
Constant Summary
-
Log =
::Log.for("termisu") -
Main log instance for Termisu library
-
VERSION =
{{ (`shards version`).chomp.stringify }} -
Full version string from shard.yml
-
VERSION_MAJOR =
0 -
VERSION_MINOR =
0 -
VERSION_PATCH =
1 -
VERSION_STATE =
nil
Constructors
-
.new
Initializes Termisu with all required components.
Instance Method Summary
-
#clear
Clears the cell buffer (fills with spaces).
-
#close
Closes Termisu and cleans up all resources.
-
#disable_enhanced_keyboard(*args, **options)
Enables enhanced keyboard protocol for disambiguated key reporting.
-
#disable_enhanced_keyboard(*args, **options, &)
Enables enhanced keyboard protocol for disambiguated key reporting.
-
#disable_mouse(*args, **options)
Enables mouse input tracking.
-
#disable_mouse(*args, **options, &)
Enables mouse input tracking.
-
#each_event(timeout_ms : Int32 = -1, &)
Yields each event as it becomes available.
-
#enable_enhanced_keyboard(*args, **options)
Enables enhanced keyboard protocol for disambiguated key reporting.
-
#enable_enhanced_keyboard(*args, **options, &)
Enables enhanced keyboard protocol for disambiguated key reporting.
-
#enable_mouse(*args, **options)
Enables mouse input tracking.
-
#enable_mouse(*args, **options, &)
Enables mouse input tracking.
-
#enhanced_keyboard?(*args, **options)
Enables enhanced keyboard protocol for disambiguated key reporting.
-
#enhanced_keyboard?(*args, **options, &)
Enables enhanced keyboard protocol for disambiguated key reporting.
-
#hide_cursor(*args, **options)
Sets cursor position and makes it visible.
-
#hide_cursor(*args, **options, &)
Sets cursor position and makes it visible.
-
#input_available? : Bool
Checks if input data is available.
-
#mouse_enabled?(*args, **options)
Enables mouse input tracking.
-
#mouse_enabled?(*args, **options, &)
Enables mouse input tracking.
- #peek_byte(*args, **options)
- #peek_byte(*args, **options, &)
-
#poll_event(timeout_ms : Int32 = -1) : Event::Any | Nil
Polls for an input event with optional timeout.
- #read_byte(*args, **options)
- #read_byte(*args, **options, &)
- #read_bytes(*args, **options)
- #read_bytes(*args, **options, &)
-
#render(*args, **options)
Renders cell buffer changes to the screen.
-
#render(*args, **options, &)
Renders cell buffer changes to the screen.
-
#set_cell(*args, **options)
Sets a cell at the specified position.
-
#set_cell(*args, **options, &)
Sets a cell at the specified position.
-
#set_cursor(*args, **options)
Sets cursor position and makes it visible.
-
#set_cursor(*args, **options, &)
Sets cursor position and makes it visible.
-
#show_cursor(*args, **options)
Sets cursor position and makes it visible.
-
#show_cursor(*args, **options, &)
Sets cursor position and makes it visible.
-
#size(*args, **options)
Returns terminal size as {width, height}.
-
#size(*args, **options, &)
Returns terminal size as {width, height}.
-
#sync(*args, **options)
Forces a full redraw of all cells.
-
#sync(*args, **options, &)
Forces a full redraw of all cells.
-
#terminal : Terminal
Returns the underlying terminal for direct access.
-
#wait_event : Event::Any
Waits for and returns the next input event (blocking).
-
#wait_for_input(timeout_ms : Int32) : Bool
Waits for input data with a timeout in milliseconds.
Constructor Detail
Initializes Termisu with all required components.
Sets up terminal I/O, rendering, and input reader. Automatically enables raw mode and enters alternate screen.
Instance Method Detail
Clears the cell buffer (fills with spaces).
Note: This clears the buffer, not the screen. Call render() to apply.
Closes Termisu and cleans up all resources.
Exits alternate screen, disables raw mode, and closes all components.
Enables enhanced keyboard protocol for disambiguated key reporting.
In standard terminal mode, certain keys are indistinguishable:
- Tab sends the same byte as Ctrl+I (0x09)
- Enter sends the same byte as Ctrl+M (0x0D)
- Backspace may send the same byte as Ctrl+H (0x08)
Enhanced mode enables the Kitty keyboard protocol and/or modifyOtherKeys, which report keys in a way that preserves the distinction.
Note: Not all terminals support these protocols. Unsupported terminals will silently ignore the escape sequences and continue with legacy mode. Supported terminals include: Kitty, WezTerm, foot, Ghostty, recent xterm.
Example:
termisu.enable_enhanced_keyboard
loop do
if event = termisu.poll_event(100)
case event
when Termisu::Event::Key
# Now Ctrl+I and Tab are distinguishable!
if event.ctrl? && event.key.lower_i?
puts "Ctrl+I pressed"
elsif event.key.tab?
puts "Tab pressed"
end
end
end
end
termisu.disable_enhanced_keyboard
Enables enhanced keyboard protocol for disambiguated key reporting.
In standard terminal mode, certain keys are indistinguishable:
- Tab sends the same byte as Ctrl+I (0x09)
- Enter sends the same byte as Ctrl+M (0x0D)
- Backspace may send the same byte as Ctrl+H (0x08)
Enhanced mode enables the Kitty keyboard protocol and/or modifyOtherKeys, which report keys in a way that preserves the distinction.
Note: Not all terminals support these protocols. Unsupported terminals will silently ignore the escape sequences and continue with legacy mode. Supported terminals include: Kitty, WezTerm, foot, Ghostty, recent xterm.
Example:
termisu.enable_enhanced_keyboard
loop do
if event = termisu.poll_event(100)
case event
when Termisu::Event::Key
# Now Ctrl+I and Tab are distinguishable!
if event.ctrl? && event.key.lower_i?
puts "Ctrl+I pressed"
elsif event.key.tab?
puts "Tab pressed"
end
end
end
end
termisu.disable_enhanced_keyboard
Enables mouse input tracking.
Once enabled, mouse events will be reported via poll_event. Supports SGR extended protocol (mode 1006) for large terminals and falls back to normal mode (1000) for compatibility.
Example:
termisu.enable_mouse
loop do
if event = termisu.poll_event(100)
case event
when Termisu::Event::Mouse
puts "Click at #{event.x},#{event.y}"
end
end
end
termisu.disable_mouse
Enables mouse input tracking.
Once enabled, mouse events will be reported via poll_event. Supports SGR extended protocol (mode 1006) for large terminals and falls back to normal mode (1000) for compatibility.
Example:
termisu.enable_mouse
loop do
if event = termisu.poll_event(100)
case event
when Termisu::Event::Mouse
puts "Click at #{event.x},#{event.y}"
end
end
end
termisu.disable_mouse
Yields each event as it becomes available.
This is a convenient way to process events in a loop. Use timeout_ms to control polling behavior.
Example:
termisu.each_event(100) do |event|
case event
when Termisu::Event::Key
break if event.key.escape?
end
termisu.render
end
Enables enhanced keyboard protocol for disambiguated key reporting.
In standard terminal mode, certain keys are indistinguishable:
- Tab sends the same byte as Ctrl+I (0x09)
- Enter sends the same byte as Ctrl+M (0x0D)
- Backspace may send the same byte as Ctrl+H (0x08)
Enhanced mode enables the Kitty keyboard protocol and/or modifyOtherKeys, which report keys in a way that preserves the distinction.
Note: Not all terminals support these protocols. Unsupported terminals will silently ignore the escape sequences and continue with legacy mode. Supported terminals include: Kitty, WezTerm, foot, Ghostty, recent xterm.
Example:
termisu.enable_enhanced_keyboard
loop do
if event = termisu.poll_event(100)
case event
when Termisu::Event::Key
# Now Ctrl+I and Tab are distinguishable!
if event.ctrl? && event.key.lower_i?
puts "Ctrl+I pressed"
elsif event.key.tab?
puts "Tab pressed"
end
end
end
end
termisu.disable_enhanced_keyboard
Enables enhanced keyboard protocol for disambiguated key reporting.
In standard terminal mode, certain keys are indistinguishable:
- Tab sends the same byte as Ctrl+I (0x09)
- Enter sends the same byte as Ctrl+M (0x0D)
- Backspace may send the same byte as Ctrl+H (0x08)
Enhanced mode enables the Kitty keyboard protocol and/or modifyOtherKeys, which report keys in a way that preserves the distinction.
Note: Not all terminals support these protocols. Unsupported terminals will silently ignore the escape sequences and continue with legacy mode. Supported terminals include: Kitty, WezTerm, foot, Ghostty, recent xterm.
Example:
termisu.enable_enhanced_keyboard
loop do
if event = termisu.poll_event(100)
case event
when Termisu::Event::Key
# Now Ctrl+I and Tab are distinguishable!
if event.ctrl? && event.key.lower_i?
puts "Ctrl+I pressed"
elsif event.key.tab?
puts "Tab pressed"
end
end
end
end
termisu.disable_enhanced_keyboard
Enables mouse input tracking.
Once enabled, mouse events will be reported via poll_event. Supports SGR extended protocol (mode 1006) for large terminals and falls back to normal mode (1000) for compatibility.
Example:
termisu.enable_mouse
loop do
if event = termisu.poll_event(100)
case event
when Termisu::Event::Mouse
puts "Click at #{event.x},#{event.y}"
end
end
end
termisu.disable_mouse
Enables mouse input tracking.
Once enabled, mouse events will be reported via poll_event. Supports SGR extended protocol (mode 1006) for large terminals and falls back to normal mode (1000) for compatibility.
Example:
termisu.enable_mouse
loop do
if event = termisu.poll_event(100)
case event
when Termisu::Event::Mouse
puts "Click at #{event.x},#{event.y}"
end
end
end
termisu.disable_mouse
Enables enhanced keyboard protocol for disambiguated key reporting.
In standard terminal mode, certain keys are indistinguishable:
- Tab sends the same byte as Ctrl+I (0x09)
- Enter sends the same byte as Ctrl+M (0x0D)
- Backspace may send the same byte as Ctrl+H (0x08)
Enhanced mode enables the Kitty keyboard protocol and/or modifyOtherKeys, which report keys in a way that preserves the distinction.
Note: Not all terminals support these protocols. Unsupported terminals will silently ignore the escape sequences and continue with legacy mode. Supported terminals include: Kitty, WezTerm, foot, Ghostty, recent xterm.
Example:
termisu.enable_enhanced_keyboard
loop do
if event = termisu.poll_event(100)
case event
when Termisu::Event::Key
# Now Ctrl+I and Tab are distinguishable!
if event.ctrl? && event.key.lower_i?
puts "Ctrl+I pressed"
elsif event.key.tab?
puts "Tab pressed"
end
end
end
end
termisu.disable_enhanced_keyboard
Enables enhanced keyboard protocol for disambiguated key reporting.
In standard terminal mode, certain keys are indistinguishable:
- Tab sends the same byte as Ctrl+I (0x09)
- Enter sends the same byte as Ctrl+M (0x0D)
- Backspace may send the same byte as Ctrl+H (0x08)
Enhanced mode enables the Kitty keyboard protocol and/or modifyOtherKeys, which report keys in a way that preserves the distinction.
Note: Not all terminals support these protocols. Unsupported terminals will silently ignore the escape sequences and continue with legacy mode. Supported terminals include: Kitty, WezTerm, foot, Ghostty, recent xterm.
Example:
termisu.enable_enhanced_keyboard
loop do
if event = termisu.poll_event(100)
case event
when Termisu::Event::Key
# Now Ctrl+I and Tab are distinguishable!
if event.ctrl? && event.key.lower_i?
puts "Ctrl+I pressed"
elsif event.key.tab?
puts "Tab pressed"
end
end
end
end
termisu.disable_enhanced_keyboard
Sets cursor position and makes it visible. Hides the cursor (rendered on next render()). Shows the cursor (rendered on next render()).
Sets cursor position and makes it visible. Hides the cursor (rendered on next render()). Shows the cursor (rendered on next render()).
Enables mouse input tracking.
Once enabled, mouse events will be reported via poll_event. Supports SGR extended protocol (mode 1006) for large terminals and falls back to normal mode (1000) for compatibility.
Example:
termisu.enable_mouse
loop do
if event = termisu.poll_event(100)
case event
when Termisu::Event::Mouse
puts "Click at #{event.x},#{event.y}"
end
end
end
termisu.disable_mouse
Enables mouse input tracking.
Once enabled, mouse events will be reported via poll_event. Supports SGR extended protocol (mode 1006) for large terminals and falls back to normal mode (1000) for compatibility.
Example:
termisu.enable_mouse
loop do
if event = termisu.poll_event(100)
case event
when Termisu::Event::Mouse
puts "Click at #{event.x},#{event.y}"
end
end
end
termisu.disable_mouse
Polls for an input event with optional timeout.
This is the recommended way to handle keyboard and mouse input. Returns structured Event objects (Event::Key, Event::Mouse, Event::Resize, Event::Tick) instead of raw bytes.
Parameters:
- timeout_ms: Timeout in milliseconds (-1 for blocking, 0 for non-blocking)
Returns an Event or nil if timeout/no data.
Example:
loop do
if event = termisu.poll_event(100)
case event
when Termisu::Event::Key
break if event.ctrl_c? || event.key.escape?
puts "Key: #{event.key}"
when Termisu::Event::Mouse
puts "Mouse: #{event.x},#{event.y}"
end
end
termisu.render
end
Renders cell buffer changes to the screen.
Only cells that have changed since the last render are redrawn (diff-based). This is more efficient than clear_screen + write for partial updates.
Renders cell buffer changes to the screen.
Only cells that have changed since the last render are redrawn (diff-based). This is more efficient than clear_screen + write for partial updates.
Sets a cell at the specified position.
Parameters:
- x: Column position (0-based)
- y: Row position (0-based)
- ch: Character to display
- fg: Foreground color (default: white)
- bg: Background color (default: default terminal color)
- attr: Text attributes (default: None)
Returns false if coordinates are out of bounds.
Example:
termisu.set_cell(10, 5, 'A', fg: Color.red, attr: Attribute::Bold)
termisu.render # Apply changes
Sets a cell at the specified position.
Parameters:
- x: Column position (0-based)
- y: Row position (0-based)
- ch: Character to display
- fg: Foreground color (default: white)
- bg: Background color (default: default terminal color)
- attr: Text attributes (default: None)
Returns false if coordinates are out of bounds.
Example:
termisu.set_cell(10, 5, 'A', fg: Color.red, attr: Attribute::Bold)
termisu.render # Apply changes
Sets cursor position and makes it visible. Hides the cursor (rendered on next render()). Shows the cursor (rendered on next render()).
Sets cursor position and makes it visible. Hides the cursor (rendered on next render()). Shows the cursor (rendered on next render()).
Sets cursor position and makes it visible. Hides the cursor (rendered on next render()). Shows the cursor (rendered on next render()).
Sets cursor position and makes it visible. Hides the cursor (rendered on next render()). Shows the cursor (rendered on next render()).
Forces a full redraw of all cells.
Useful after terminal resize or screen corruption.
Forces a full redraw of all cells.
Useful after terminal resize or screen corruption.
Waits for and returns the next input event (blocking).
This method blocks until an event is available.
Example:
event = termisu.wait_event
puts "Got event: #{event}"
Waits for input data with a timeout in milliseconds.