Class: Ruco::CommandBar

Inherits:
Object show all
Defined in:
lib/ruco/command_bar.rb

Constant Summary collapse

SHORTCUTS =
[
  '^W Exit',
  '^S Save',
  '^F Find',
  '^D Delete line',
  '^G Go to line'
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CommandBar

Returns a new instance of CommandBar.



14
15
16
17
18
# File 'lib/ruco/command_bar.rb', line 14

def initialize(options)
  @options = options
  @forms_cache = {}
  reset
end

Instance Attribute Details

#cursor_lineObject

Returns the value of attribute cursor_line.



3
4
5
# File 'lib/ruco/command_bar.rb', line 3

def cursor_line
  @cursor_line
end

#formObject

Returns the value of attribute form.



3
4
5
# File 'lib/ruco/command_bar.rb', line 3

def form
  @form
end

Instance Method Details

#ask(question, options = {}, &block) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/ruco/command_bar.rb', line 28

def ask(question, options={}, &block)
  @form = cached_form_if(options[:cache], question) do
    Form.new(question, :columns => @options[:columns]) do |result|
      @form = nil
      block.call(result)
    end
  end
end

#cursorObject



42
43
44
45
46
47
48
# File 'lib/ruco/command_bar.rb', line 42

def cursor
  if @form
    Cursor.new cursor_line, @form.cursor.column
  else
    Cursor.new cursor_line, 0
  end
end

#resetObject



37
38
39
40
# File 'lib/ruco/command_bar.rb', line 37

def reset
  @forms_cache[@forms_cache.key(@form)] = nil
  @form = nil
end

#viewObject



20
21
22
23
24
25
26
# File 'lib/ruco/command_bar.rb', line 20

def view
  if @form
    @form.view
  else
    available_shortcuts
  end
end