module Tput::Output::Emulator

Included Modules

Direct including types

Defined in:

tput/output/emulator.cr

Instance Method Summary

Instance Method Detail

def begin_hyperlink(uri : String, id : String | Nil = nil) : Nil #

OSC 8: begins a hyperlink to uri. Text emitted until #end_hyperlink (or the next #begin_hyperlink) is clickable. id groups links that should highlight as one when hovered — use the same id for a link split across cells/lines. Widely supported (VTE, kitty, iTerm2, WezTerm, foot, …) and ignored elsewhere.


[View source]
def begin_synchronized_update : Nil #

Begins a synchronized update (DEC private mode 2026): the terminal holds off presenting output until #end_synchronized_update, then repaints the whole frame at once, removing flicker/tearing from a multi-write redraw. Harmless where unsupported (ignored, and auto-released after a short timeout so a missing end can't freeze the screen). Prefer the #synchronized_update block, which always pairs the end marker.


[View source]
def clear_clipboard(selection : String = "c") : Nil #

OSC 52: clears the terminal clipboard selection.


[View source]
def copy_to_clipboard(text) #

Copies text to clipboard. Does nothing if terminal emulator is not iTerm2.

Fall back to an external clipboard program when this capability is missing:

Example: unless copy_to_clipboard text exec_clipboard_program text end


[View source]
def disable_color_scheme_notifications : Nil #

Disables color-scheme change notifications (DEC 2031).


[View source]
def disable_grapheme_clustering : Nil #

Disables Unicode grapheme clustering (DEC 2027).


[View source]
def disable_modifiers(param = "") #

CSI > Ps n Disable modifiers which may be enabled via the CSI > Ps; Ps m sequence. This corresponds to a resource value of "-1", which cannot be set with the other sequence. The parameter identi- fies the resource to be disabled: Ps = 1 -> modifyCursorKeys. Ps = 2 -> modifyFunctionKeys. Ps = 4 -> modifyOtherKeys. If the parameter is omitted, modifyFunctionKeys is disabled. When modifyFunctionKeys is disabled, xterm uses the modifier keys to make an extended sequence of functions rather than adding a parameter to each function key to denote the modi- fiers.


[View source]
def enable_color_scheme_notifications : Nil #

Enables color-scheme (light/dark) change notifications (DEC private mode 2031). The terminal reports theme changes in-band as CSI ? 997 ; 1 n (dark) / CSI ? 997 ; 2 n (light), surfaced as the color_scheme of Tput::Input#listen events. Query the current scheme with #request_color_scheme. Harmless where unsupported.


[View source]
def enable_grapheme_clustering : Nil #

Enables Unicode grapheme clustering (DEC private mode 2027): the terminal advances the cursor by grapheme cluster (emoji ZWJ sequences, base + combining marks, regional-indicator flags) rather than by codepoint, matching this library's full_unicode cell model. Harmless where unsupported.


[View source]
def end_hyperlink : Nil #

OSC 8: ends the current hyperlink (empty URI), so following text is no longer clickable.


[View source]
def end_synchronized_update : Nil #

Ends a synchronized update (DEC 2026), presenting the buffered frame.


[View source]
def hyperlink(text : String, uri : String, id : String | Nil = nil) : Nil #

OSC 8: emits text as a hyperlink to uri (begin + text + end).


[View source]
def mouse_cursor_shape(name : String) #

OSC 22 ; Pt ST Set the GUI mouse-pointer shape (the windowing-system cursor the user moves with the mouse) while the pointer is over this terminal window. This is distinct from Output::Cursor#cursor_shape, which styles the blinking text caret.

Pt is an X11 cursor-font glyph name — pass a MouseCursorShape (whose #cursor_name supplies it) or the raw name string. Per-window and best-effort: xterm honors OSC 22, but most other emulators (and Wayland-native terminals) ignore it, and an Xcursor theme may remap the glyph. Persists until #reset_mouse_cursor_shape, the pointer leaves the window, or the program exits — callers should arrange to reset it (e.g. on mouse-out).


[View source]
def mouse_cursor_shape(shape : MouseCursorShape) #

OSC 22 ; Pt ST Set the GUI mouse-pointer shape (the windowing-system cursor the user moves with the mouse) while the pointer is over this terminal window. This is distinct from Output::Cursor#cursor_shape, which styles the blinking text caret.

Pt is an X11 cursor-font glyph name — pass a MouseCursorShape (whose #cursor_name supplies it) or the raw name string. Per-window and best-effort: xterm honors OSC 22, but most other emulators (and Wayland-native terminals) ignore it, and an Xcursor theme may remap the glyph. Persists until #reset_mouse_cursor_shape, the pointer leaves the window, or the program exits — callers should arrange to reset it (e.g. on mouse-out).


[View source]
def pop_title : Nil #

Restores the titles last saved with #push_title (CSI 23 ; 0 t).


[View source]
def progress(progress : Int32 = 0, state : Int32 = 1) : Nil #

OSC 9;4: drives the terminal's progress indicator (taskbar / tab badge). state: 0 = clear, 1 = normal (show progress, 0–100), 2 = error, 3 = indeterminate, 4 = warning/paused. Supported by ConEmu, Windows Terminal, WezTerm, ghostty, … and ignored elsewhere.


[View source]
def push_title : Nil #

Saves the terminal's window and icon titles on its title stack (XTWINOPS CSI 22 ; 0 t; xterm, VTE, kitty, Ghostty, iTerm2, foot…; ignored elsewhere). #title= does it before the first title.


[View source]
def report_cwd(path : String, host : String = "") : Nil #

OSC 7: reports path to the terminal as the current working directory (as a file:// URI), so terminals that track cwd — "open new tab/split here", window/tab titles — follow along. host is the URI host (empty = local). Ignored where unsupported.


[View source]
def request_clipboard(selection : String = "c") : Nil #

OSC 52: asks the terminal to report the clipboard selection without waiting for the reply (\e]52;<sel>;?\a). Use this while #listen is active — the reply arrives through the input stream and is surfaced as a paste. (Response#get_clipboard is the synchronous counterpart, for use outside the input loop.)


[View source]
def reset_mouse_cursor_shape #

OSC 22 ; ST Restore the GUI mouse-pointer to the terminal's default shape, undoing a previous #mouse_cursor_shape. xterm treats an empty Pt as "reset to default"; terminals without OSC 22 ignore it.


[View source]
def reset_title_modes(*arguments) #

CSI > Ps; Ps T Reset one or more features of the title modes to the default value. Normally, "reset" disables the feature. It is possi- ble to disable the ability to reset features by compiling a different default for the title modes into xterm. Ps = 0 -> Do not set window/icon labels using hexadecimal. Ps = 1 -> Do not query window/icon labels using hexadeci- mal. Ps = 2 -> Do not set window/icon labels using UTF-8. Ps = 3 -> Do not query window/icon labels using UTF-8. (See discussion of "Title Modes").


[View source]
def restore_title : Nil #

Puts back the title the terminal had before the first #title=, when one was set; a later #title= saves it again. Called when the program hands the terminal back.


[View source]
def set_clipboard(text : String, selection : String = "c") : Nil #

OSC 52: sets the terminal clipboard selection to text (base64-encoded as the protocol requires). selection is "c" for the clipboard, "p" for primary, etc. Unlike OS-level clipboard tools this works through SSH and tmux. Read back with #get_clipboard. Harmless on terminals without OSC 52 support (they ignore it).


[View source]
def set_pointer_mode(param = "") #

CSI > Ps p Set resource value pointerMode. This is used by xterm to decide whether to hide the pointer cursor as the user types. Valid values for the parameter: Ps = 0 -> never hide the pointer. Ps = 1 -> hide if the mouse tracking mode is not enabled. Ps = 2 -> always hide the pointer. If no parameter is given, xterm uses the default, which is 1 .


[View source]
def set_resources(*arguments) #

CSI > Ps; Ps m Set or reset resource-values used by xterm to decide whether to construct escape sequences holding information about the modifiers pressed with a given key. The first parameter iden- tifies the resource to set/reset. The second parameter is the value to assign to the resource. If the second parameter is omitted, the resource is reset to its initial value. Ps = 1 -> modifyCursorKeys. Ps = 2 -> modifyFunctionKeys. Ps = 4 -> modifyOtherKeys. If no parameters are given, all resources are reset to their initial values.


[View source]
def set_title_mode_feature(*arguments) #

CSI > Ps; Ps t Set one or more features of the title modes. Each parameter enables a single feature. Ps = 0 -> Set window/icon labels using hexadecimal. Ps = 1 -> Query window/icon labels using hexadecimal. Ps = 2 -> Set window/icon labels using UTF-8. Ps = 3 -> Query window/icon labels using UTF-8. (See dis- cussion of "Title Modes") XXX VTE bizarelly echos this:


[View source]
def synchronized_update(&) #

Brackets block's output in a synchronized update (DEC 2026) so the frame it draws is presented atomically. The end marker is emitted even if the block raises, so a failure cannot leave the terminal frozen.


[View source]
def title=(title) #

Sets the terminal's window and icon title (OSC 0 ; Pt BEL), kept in #_title.

Sent on every terminal: one that has no title ignores the OSC, as every terminal does with an OSC it does not know. Sent as is under tmux and GNU screen, which take the title themselves (tmux as the pane's title, passed on to the outer terminal with set-titles) where a passthrough-wrapped one only got through with tmux's allow-passthrough, off by default. Control characters in title (a file name may hold an ESC or a BEL) are dropped, so they cannot end the OSC early and run the rest as escape sequences.

The first title saves the terminal's own on its title stack (#push_title) and #restore_title puts it back, as #pause and #restore_terminal do, so the program's title does not outlive it.


[View source]
def title_pushed? #

Whether #title= saved the terminal's title, for #restore_title to put back.


[View source]