class Tput

Overview

Many Tput methods correspond to terminal sequences. Often times methods are named according to their purpose, and then aliased to the names of sequences used behind the scenes.

For example, method #delete_columns is directly implemented using sequence decdc. Therefore, it is also accessible under the alias #decdc.

Furthermore, for understanding the instructions on terminal sequences, the following names are important:

ESC - Sequence starting with ESC (\e)
CSI - Control Sequence Introducer: sequence starting with ESC [ (7bit) or CSI (\x9B, 8bit)
DCS - Device Control String: sequence starting with ESC P (7bit) or DCS (\x90, 8bit)
OSC - Operating System Command: sequence starting with ESC ] (7bit) or OSC (\x9D, 8bit)
C0: single byte command (7bit control codes, byte range \x00 .. \x1F, \x7F)
C1: single byte command (8bit control codes, byte range \x80 .. \x9F)

Some sequences accept arguments. Their naming and types correspond to those used in XTerm documentation:

Ps: A single (usually optional) numeric parameter, composed of one or more decimal digits.
Pm: A multiple numeric parameter composed of any number of single numeric parameters, separated by ";", e.g. ` Ps ; Ps ; … `.
Pt: A text parameter composed of printable characters.

In all of the examples above, spaces exist just for clarity and are not part of actual escape sequences. For example, in "ESC [" or " Ps ; Ps ;" there are no actual spaces.

Included Modules

Defined in:

tput.cr
tput/acsc.cr
tput/coordinates.cr
tput/emulator.cr
tput/features.cr
tput/input.cr
tput/keys.cr
tput/macros.cr
tput/namespace.cr
tput/output.cr
tput/output/bell.cr
tput/output/charset.cr
tput/output/colors.cr
tput/output/cursor.cr
tput/output/emulator.cr
tput/output/misc.cr
tput/output/mouse.cr
tput/output/rectangles.cr
tput/output/screen.cr
tput/output/scrolling.cr
tput/output/terminal.cr
tput/output/text.cr

Constant Summary

CSI7 = "\e["
CSI8 = "\x9B"
DCS7 = "\eP"
DCS8 = "\x90"
DEFAULT_SCREEN_SIZE = Size.new(80, 24)
ESC = "\e"
Log = ::Log.for((self.name.gsub("::", '.')).underscore)
OSC7 = "\e]"
OSC8 = "\x9D"
VERSION = "1.0.8"

Constructors

Instance Method Summary

Instance methods inherited from module Tput::Input

listen(&block : Proc(Char, Key | Nil, Array(Char), Nil)) listen, next_char(timeout : Bool = false, &) next_char, with_raw_input(&) with_raw_input, with_sync_output(&) with_sync_output

Instance methods inherited from module Tput::Output

_oprint(*args) _oprint, _owrite(*args) _owrite, _pad_write(code, prn = ->_write(Bytes), done = nil) _pad_write, _print(*args)
_print(&block : IO -> Nil)
_print
, _tprint(data) _tprint, _with_io(&block : IO -> Nil) _with_io, _write(*args) _write, flush flush

Instance methods inherited from module Tput::Output::Terminal

decrst(*arguments) decrst, decset(*arguments) decset, request_ansi_mode(param = "") request_ansi_mode, request_private_mode(param = "") request_private_mode, reset reset, reset_mode(*arguments) reset_mode, set_conformance_level(*arguments) set_conformance_level, set_mode(*arguments) set_mode, soft_reset soft_reset

Instance methods inherited from module Tput::Output::Screen

alternate_buffer alternate_buffer, clear clear, erase_in_display(param = Erase::Below) erase_in_display, normal_buffer normal_buffer

Instance methods inherited from module Tput::Output::Mouse

enable_filter_rectangle(*arguments) enable_filter_rectangle, enable_locator_reporting(*arguments) enable_locator_reporting, set_locator_events(*arguments) set_locator_events

Instance methods inherited from module Tput::Output::Rectangles

copy_rectangle(*arguments) copy_rectangle, erase_rectangle(top = 0, left = 0, bottom = @screen.height - 1, right = @screen.width - 1) erase_rectangle, fill_rectangle(*arguments) fill_rectangle, reverse_attr_in_rectangle(*arguments) reverse_attr_in_rectangle, select_change_extent(param = 0) select_change_extent, selective_erase_rectangle(top = 0, left = 0, bottom = @screen.height - 1, right = @screen.width - 1) selective_erase_rectangle, set_attr_in_rectangle(*arguments) set_attr_in_rectangle

Instance methods inherited from module Tput::Output::Bell

bell bell, margin_bell_volume=(param : Volume) margin_bell_volume=, warning_bell_volume=(param : Volume) warning_bell_volume=

Instance methods inherited from module Tput::Output::Emulator

copy_to_clipboard(text) copy_to_clipboard, disable_modifiers(param = "") disable_modifiers, reset_title_modes(*arguments) reset_title_modes, set_pointer_mode(param = "") set_pointer_mode, set_resources(*arguments) set_resources, set_title_mode_feature(*arguments) set_title_mode_feature, title=(title : String) title=

Instance methods inherited from module Tput::Output::Charset

charset=(charset : C | Nil) charset=, enter_alt_charset_mode enter_alt_charset_mode, exit_alt_charset_mode exit_alt_charset_mode, set_g(val) set_g

Instance methods inherited from module Tput::Output::Scrolling

index index, reverse_index reverse_index, scroll_down(param = 1) scroll_down, scroll_up(param = 1) scroll_up, set_scroll_region(top : Int = 0, bottom : Int = (@screen.height - 1)) set_scroll_region

Instance methods inherited from module Tput::Output::Misc

escape escape, load_leds(param = 0) load_leds, mc0 mc0, mc4 mc4, mc5 mc5, mc5p mc5p, media_copy(*arguments) media_copy, null null, repeat(str, i = 1) repeat

Instance methods inherited from module Tput::Output::Text

_attr(param : Array | String, val = true) _attr, backspace backspace, carriage_return carriage_return, char_attributes(param, val) char_attributes, delete_chars(param = 1) delete_chars, delete_columns(n = 1) delete_columns, delete_line(param : Int = 1) delete_line, echo(text, attr = nil) echo, erase_character(param : Int = 1) erase_character, erase_in_line(param = LineDirection::Right) erase_in_line, form_feed form_feed, horizontal_tabulation_set horizontal_tabulation_set, insert_chars(param = 1) insert_chars, insert_columns(n = 1) insert_columns, insert_line(param : Int = 1) insert_line, line_feed line_feed, line_height line_height, repeat_preceding_character(param = 1) repeat_preceding_character, sel_data(a, b) sel_data, set_background(color, val) set_background, set_char_protection_attr(param = 0) set_char_protection_attr, set_foreground(color, val) set_foreground, shift_in shift_in, shift_out shift_out, simple_insert(str, i = 1, attr = nil) simple_insert, tab_clear(param = 0) tab_clear, text(text, attr) text, vertical_tab vertical_tab

Instance methods inherited from module Tput::Output::Cursor

char_pos_absolute(param : Int32 | Nil = 1) char_pos_absolute, cursor_backward(param = 1) cursor_backward, cursor_backward_tab(param = 1) cursor_backward_tab, cursor_char_absolute(point : Point)
cursor_char_absolute(param = 0)
cursor_char_absolute
, cursor_color(color : String)
cursor_color(color : Color)
cursor_color
, cursor_down(param = 1) cursor_down, cursor_forward(param : Int = 1) cursor_forward, cursor_forward_tab(param = 1) cursor_forward_tab, cursor_line_absolute(point : Point)
cursor_line_absolute(param = 1)
cursor_line_absolute
, cursor_next_line(param = 1) cursor_next_line, cursor_position(row : Int = 0, column : Int = 0)
cursor_position(point : Tput::Point)
cursor_position
, cursor_preceding_line(param = 1) cursor_preceding_line, cursor_shape(shape, blink = false) cursor_shape, cursor_up(param = 1) cursor_up, dynamic_cursor_color(param) dynamic_cursor_color, h_position_relative(param = 1) h_position_relative, hide_cursor hide_cursor, hv_position(row = 0, col = 0) hv_position, lrestore_cursor(key = :local, hide = false) lrestore_cursor, lsave_cursor(key = :local) lsave_cursor, move(point : Point)
move(x = nil, y = nil)
move
, omove(point : Point)
omove(x = 0, y = 0)
omove
, reset_cursor reset_cursor, reset_cursor_color reset_cursor_color, restore_cursor(key : String | Nil = nil, hide : Bool = false) restore_cursor, restore_cursor_a restore_cursor_a, restore_reported_cursor restore_reported_cursor, rmove(dx, dy)
rmove(point : Point)
rmove
, rsetx(dx) rsetx, rsety(dy) rsety, save_cursor(key : String | Nil = nil) save_cursor, save_cursor_a save_cursor_a, set_cursor_style(style = CursorStyle::SteadyBlock) set_cursor_style, show_cursor show_cursor, v_position_relative(param = 1) v_position_relative

Instance methods inherited from module Tput::Coordinates

_adjust_xy_abs(x = 0, y = 0) _adjust_xy_abs, _adjust_xy_rel(x = 0, y = 0) _adjust_xy_rel, _ncoords _ncoords, get_screen_size get_screen_size, reset_screen_size reset_screen_size

Constructor Detail

def self.new(pull : JSON::PullParser) #

[View source]
def self.new(terminfo : Nil | Unibilium::Terminfo = nil, input : IO = STDIN, output : IO = STDOUT.dup, error : IO = STDERR.dup, force_unicode = nil, use_buffer : Bool = true, screen_size = nil) #

[View source]

Instance Method Detail

def _exiting=(_exiting : Bool) #

[View source]
def _exiting? : Bool #

[View source]
def _saved : Hash(String | Symbol | UInt64, Tput::Namespace::CursorState) #

[View source]
def _saved=(_saved : Hash(String | Symbol | UInt64, Tput::Namespace::CursorState)) #

[View source]
def _title : String #

[View source]
def cursor : Point #

[View source]
def cursor_hidden? : Bool #

[View source]
def emulator : Emulator #

[View source]
def emulator? : Emulator | Nil #

[View source]
def error : IO #

[View source]
def error=(error : IO) #

[View source]
def features : Features #

[View source]
def features? : Features | Nil #

[View source]
def force_unicode? : Bool #

[View source]
def has?(&) #

[View source]
def input : IO #

[View source]
def input=(input : IO) #

[View source]
def is_alt : Bool #

[View source]
def name?(nam : String) #

[View source]
def name?(*names) #

[View source]
def output : IO #

[View source]
def output=(output : IO) #

[View source]
def pause(callback : Proc | Nil = nil) #

[View source]
def put(&) #

Outputs a string capability to the designated @output, if the capability exists.

For this method to work, the Tput instance needs to be initialized with Terminfo data. If Terminfo data is not present, nil will be returned.

put &.smcup?

put &.cursor_pos?(10, 20)

[View source]
def read_timeout : Time::Span #

Timeout when reading escape sequences. If an escape sequence (ESC) comes in on input, we have no way of telling whether this is an ESC key or the start of an escape sequence. So we read with a timeout. If there is no input by the time it times out, we consider it was a key press.

All other apps like Vi etc. read the escape key in the terminal this way.

The default timeout is 400 milliseconds, the same as in Qt.


[View source]
def resume #

[View source]
def ret : IO | Nil #

[View source]
def ret=(ret : IO | Nil) #

[View source]
def saved_cursor : Point | Nil #

[View source]
def screen : Size #

[View source]
def scroll_bottom : Int32 #

[View source]
def scroll_top : Int32 #

[View source]
def shim : Unibilium::Terminfo::Shim | Nil #

[View source]
def sigtstp(callback) #

[View source]
def terminfo : Unibilium::Terminfo | Nil #

[View source]
def use_buffer? : Bool #

[View source]