Class: Conveyor::Input::Console
- Inherits:
-
Object
- Object
- Conveyor::Input::Console
- Includes:
- Singleton
- Defined in:
- lib/conveyor/input/console.rb
Instance Method Summary collapse
- #handle(line) ⇒ Object
-
#initialize ⇒ Console
constructor
A new instance of Console.
- #listen ⇒ Object
- #restore_tty_settings ⇒ Object
- #save_tty_settings ⇒ Object
Constructor Details
#initialize ⇒ Console
Returns a new instance of Console.
6 7 |
# File 'lib/conveyor/input/console.rb', line 6 def initialize end |
Instance Method Details
#handle(line) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/conveyor/input/console.rb', line 19 def handle(line) cmd = line.split(/\s+/) return if cmd.empty? if Commands.respond_to? cmd.first Commands.send(cmd.shift, cmd.join(' ')) else Commands.unknown(*cmd) end end |
#listen ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/conveyor/input/console.rb', line 9 def listen save_tty_settings while line = Readline.readline('> ', true) handle line end rescue Interrupt => e restore_tty_settings exit end |
#restore_tty_settings ⇒ Object
34 35 36 |
# File 'lib/conveyor/input/console.rb', line 34 def restore_tty_settings system('stty', @stty_save); end |
#save_tty_settings ⇒ Object
30 31 32 |
# File 'lib/conveyor/input/console.rb', line 30 def save_tty_settings @stty_save = `stty -g`.chomp end |