Class: Cmdr
- Inherits:
-
Object
- Object
- Cmdr
- Defined in:
- lib/cmdr.rb
Instance Method Summary collapse
-
#cli_banner ⇒ Object
display the cli banner upon initialisation.
-
#initialize ⇒ Cmdr
constructor
A new instance of Cmdr.
- #input(c, enter: "\r", backspace: "\u007F", arrowup: :arrow_up) ⇒ Object
Constructor Details
#initialize ⇒ Cmdr
Returns a new instance of Cmdr.
8 9 10 11 12 13 14 |
# File 'lib/cmdr.rb', line 8 def initialize() @linebuffer = '' @history = [] @out = [] end |
Instance Method Details
#cli_banner ⇒ Object
display the cli banner upon initialisation
65 66 67 |
# File 'lib/cmdr.rb', line 65 def () print "> " end |
#input(c, enter: "\r", backspace: "\u007F", arrowup: :arrow_up) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cmdr.rb', line 16 def input(c, enter: "\r", backspace: "\u007F", arrowup: :arrow_up) key = c reveal(c) @out << case key when enter command = @linebuffer @history << command if @linebuffer.length < 1 then return clear_cli() end result = yield(@linebuffer) if result then display_output("\n" + result) else display_output "\n" + 'command not found >> ' + @linebuffer.inspect end @linebuffer = '' clear_cli() when backspace @linebuffer.chop! cli_update() when arrowup old_command = @history.last @linebuffer = old_command cli_update old_command else if key.length < 2 then @linebuffer << key key end end end |