Module: PI::Cli::InteractHelper
- Included in:
- Command::Apps, Command::Dns, Command::Projects, Command::Services
- Defined in:
- lib/cli/interact_helper.rb
Defined Under Namespace
Classes: InputState
Constant Summary collapse
- EVENTS =
{ "\b" => :backspace, "\t" => :tab, "\x01" => :home, "\x03" => :interrupt, "\x04" => :eof, "\x05" => :end, "\x17" => :kill_word, "\x7f" => :backspace, "\r" => :enter, "\n" => :enter }
- ESCAPES =
{ "[A" => :up, "H" => :up, "[B" => :down, "P" => :down, "[C" => :right, "M" => :right, "[D" => :left, "K" => :left, "[3~" => :delete, "S" => :delete, "[H" => :home, "G" => :home, "[F" => :end, "O" => :end, "[Z" => :shift_tab }
Instance Method Summary collapse
- #asks(question, options = {}) ⇒ Object
- #read_char(options = {}) ⇒ Object
- #read_event(options = {}) ⇒ Object
- #read_line(options = {}) ⇒ Object
Instance Method Details
#asks(question, options = {}) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/cli/interact_helper.rb', line 126 def asks(question, = {}) choices = [:choices] && [:choices].to_a list_choices(choices, ) if choices while true prompt(question, ) ok, res = multi_answered(read_line(), ) return res if ok end end |
#read_char(options = {}) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/cli/interact_helper.rb', line 97 def read_char( = {}) input = [:input] || $stdin with_char_io(input) do get_character(input) end end |
#read_event(options = {}) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/cli/interact_helper.rb', line 105 def read_event( = {}) input = [:input] || $stdin with_char_io(input) do get_event(input) end end |
#read_line(options = {}) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/cli/interact_helper.rb', line 113 def read_line( = {}) input = [:input] || $stdin state = input_state() with_char_io(input) do until state.done? handler(get_event(input), state) end end state.answer end |