Class: Cmdr

Inherits:
Object
  • Object
show all
Defined in:
lib/cmdr.rb

Instance Method Summary collapse

Constructor Details

#initializeCmdr

Returns a new instance of Cmdr.



8
9
10
11
12
13
# File 'lib/cmdr.rb', line 8

def initialize()

  @linebuffer = ''
  @history = []

end

Instance Method Details

#cli_bannerObject

display the cli banner upon initialisation



71
72
73
# File 'lib/cmdr.rb', line 71

def cli_banner()
  print "> "
end

#input(c, enter: "\r", backspace: "\u007F", arrowup: :arrow_up, arrowdown: :arrow_down) ⇒ Object



15
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
62
63
64
65
# File 'lib/cmdr.rb', line 15

def input(c, enter: "\r", backspace: "\u007F", arrowup: :arrow_up, arrowdown: :arrow_down)

  key = c
  #return 'var r="e";'
  reveal(c)
  
  case key
  when enter
     
    command = @linebuffer 
    
    @history << command 
    
    if @linebuffer.length < 1 then
      return clear_cli()
    end      
    
    
    result = yield(@linebuffer.sub(/^\:/,''))

    if result then
      display_output("\n" + result)
    else
      display_output "\n" + 'command not found >> '  + @linebuffer.inspect
    end
   
    result = false

    @linebuffer = ''
    clear_cli()

  when backspace
    @linebuffer.chop!
    cli_update()
  when arrowup
    old_command = @history.last
    @linebuffer = old_command
    cli_update old_command
  when arrowdown
    #puts 'arrowdown'
  else
  
    if key.length < 2  then
  
      @linebuffer << key
      key
    end

  end

end