class Term::Reader

Defined in:

reader/console.cr
reader/history.cr
reader/key_event.cr
reader/keys.cr
reader/line.cr
reader/mode.cr
reader/version.cr
term-reader.cr

Constant Summary

BACKSPACE = 8
CARRIAGE_RETURN = 13

Key codes

CONTROL_KEYS = {"\u0001" => "ctrl_a", "\u0002" => "ctrl_b", "\u0003" => "ctrl_c", "\u0004" => "ctrl_d", "\u0005" => "ctrl_e", "\u0006" => "ctrl_f", "\a" => "ctrl_g", "\b" => "ctrl_h", "\t" => "ctrl_i", "\n" => "ctrl_j", "\v" => "ctrl_k", "\f" => "ctrl_l", "\r" => "ctrl_m", "\u000E" => "ctrl_n", "\u000F" => "ctrl_o", "\u0010" => "ctrl_p", "\u0011" => "ctrl_q", "\u0012" => "ctrl_r", "\u0013" => "ctrl_s", "\u0014" => "ctrl_t", "\u0015" => "ctrl_u", "\u0016" => "ctrl_v", "\u0017" => "ctrl_w", "\u0018" => "ctrl_x", "\u0019" => "ctrl_y", "\u001A" => "ctrl_z", "\u0000" => "ctrl_space", "\u001C" => "ctrl_backslash", "\u001D" => "ctrl_square_close", "\e[1;5A" => "ctrl_up", "\e[1;5B" => "ctrl_down", "\e[1;5C" => "ctrl_right", "\e[1;5D" => "ctrl_left"}
DELETE = 27
KEYS = {"\t" => "tab", "\n" => "enter", "\r" => "return", "\e" => "escape", " " => "space", "\u007F" => "backspace", "\e[1~" => "home", "\e[2~" => "insert", "\e[3~" => "delete", "\e[3;2~" => "shift_delete", "\e[3;5~" => "ctrl_delete", "\e[4~" => "end", "\e[5~" => "page_up", "\e[6~" => "page_down", "\e[7~" => "home", "\e[8~" => "end", "\e[A" => "up", "\e[B" => "down", "\e[C" => "right", "\e[D" => "left", "\e[E" => "clear", "\e[H" => "home", "\e[F" => "end", "\e[Z" => "back_tab", "\eOA" => "up", "\eOB" => "down", "\eOC" => "right", "\eOD" => "left", "\eOE" => "clear", "\eOF" => "end", "\eOH" => "home", "\eOP" => "f1", "\eOQ" => "f2", "\eOR" => "f3", "\eOS" => "f4", "\e[[A" => "f1", "\e[[B" => "f2", "\e[[C" => "f3", "\e[[D" => "f4", "\e[[E" => "f5", "\e[11~" => "f1", "\e[12~" => "f2", "\e[13~" => "f3", "\e[14~" => "f4", "\e[15~" => "f5", "\e[17~" => "f6", "\e[18~" => "f7", "\e[19~" => "f8", "\e[20~" => "f9", "\e[21~" => "f10", "\e[23~" => "f11", "\e[24~" => "f12", "\e[25~" => "f13", "\e[26~" => "f14", "\e[28~" => "f15", "\e[29~" => "f16", "\e[31~" => "f17", "\e[32~" => "f18", "\e[33~" => "f19", "\e[34~" => "f20", "\e[1;2P" => "f13", "\e[2;2Q" => "f14", "\e[1;2S" => "f16", "\e[15;2~" => "f17", "\e[17;2~" => "f18", "\e[18;2~" => "f19", "\e[19;2~" => "f20", "\e[20;2~" => "f21", "\e[21;2~" => "f22", "\e[23;2~" => "f23", "\e[24;2~" => "f24"}
NEWLINE = 10
VERSION = "0.1.0"
WINDOWS_KEYS = {"\t" => "tab", "\n" => "enter", "\r" => "return", "\e" => "escape", " " => "space", "\b" => "backspace", "àG" => "home", "àO" => "end", "àR" => "insert", "àS" => "clear", "àI" => "page_up", "àQ" => "page_down", "àH" => "up", "àP" => "down", "àM" => "right", "àK" => "left", "\u0000;" => "f1", "\u0000<" => "f2", "\u0000" => "f3", "\u0000=" => "f4", "\u0000?" => "f5", "\u0000@" => "f6", "\u0000A" => "f7", "\u0000B" => "f8", "\u0000C" => "f9", "\u0000D" => "f10", "\u0000\x85" => "f11", "\u0000\x86" => "f12"}

Constructors

Instance Method Summary

Macro Summary

Constructor Detail

def self.new(input : IO::FileDescriptor = STDIN, output : IO::FileDescriptor = STDOUT, env : Hash(String, String) = ENV.to_h, interrupt : Symbol = :error, track_history : Bool = true, history_cycle : Bool = false, history_exclude : String -> Bool = ->(s : String) do s.strip.empty? end, history_duplicates : Bool = false) #

[View source]

Instance Method Detail

def add_to_history(line : String) #

[View source]
def clear_display(line : Line, screen_width : Int32) : Nil #

Clear display for the current line input

Handles clearing input that is longer than the current terminal width, which allows copy + pasting long strings.


[View source]
def console : Console #

[View source]
def count_screen_lines(line : String, screen_width : Int32) : Int32 #

Count the number of screen lines the given line takes up in the terminal.


[View source]
def count_screen_lines(size : Int, screen_width : Int32) : Int32 #

ditto


[View source]
def cursor : Term::Cursor.class #

[View source]
def env : Hash(String, String) #

[View source]
def get_codes(echo : Bool, raw : Bool, nonblock : Bool) : Array(Int32) | Nil #

Get input code points

FIXME Fails to handle escape '\e' all by itself


[View source]
def history : History #

[View source]
def history_next : String | Nil #

[View source]
def history_next? : Bool #

[View source]
def history_previous : String | Nil #

[View source]
def history_previous? : Bool #

[View source]
def input : IO::FileDescriptor #

[View source]
def inspect(io : IO) : Nil #

Inspect class name and public attributes


[View source]
def interrupt : Symbol #

[View source]
def keyctrl_d : Nil #

[View source]
def keyctrl_z : Nil #

[View source]
def on_key(keys : Enumerable(String | Symbol) = [] of Symbol, &block : HandlerFunc) : Nil #

Listen for specific keys (or all keys if keys is empty)


[View source]
def on_key(*keys : String | Symbol, &block : HandlerFunc) : Nil #

Listen for specific keys (or all keys if keys is empty)


[View source]
def output : IO::FileDescriptor #

[View source]
def read_keypress(echo : Bool = false, raw : Bool = true, nonblock : Bool = false) : String | Nil #

Reads a keypress, including ivisible multibyte codes and return a character as a String.

Nothing is echoed to the console. This call will block for a single keypress, but will not wait for Enter to be pressed.


[View source]
def read_line(*, prompt : String = "", value : String = "", echo : Bool = true, raw : Bool = true, nonblock : Bool = false) : String #

Get a signal line from STDIN. Each key pressed is echoed back to the shell. The input terminates when enter or return key is pressed.


[View source]
def read_multiline(prompt : String = "") : Array(String) #

Read multiple lines and return them as an array. Skip empty lines in the returned lines array. The input gathering is terminated by Ctrl+d or Ctrl+z.


[View source]
def read_multiline(prompt : String = "", & : String -> ) : Array(String) #

ditto


[View source]
def track_history? : Bool #

Do we want to keep a log of things as they happen


[View source]
def unbuffered(&) #

Get input in unbuffered mode.


[View source]

Macro Detail

macro subscribe(*keys) #

[View source]