Class: Ruco::CommandBar

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

Constant Summary collapse

SHORTCUTS =
[
  '^W Exit',
  '^S Save',
  '^F Find',
  '^R Replace',
  '^D Delete line',
  '^G Go to line',
  '^B Select mode'
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CommandBar

Returns a new instance of CommandBar.



16
17
18
19
20
# File 'lib/ruco/command_bar.rb', line 16

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



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

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

#cursorObject



55
56
57
58
59
60
61
# File 'lib/ruco/command_bar.rb', line 55

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

#resetObject



50
51
52
53
# File 'lib/ruco/command_bar.rb', line 50

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

#style_mapObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/ruco/command_bar.rb', line 30

def style_map
  if @form
    map = @form.style_map
    map.invert!
    map.prepend(:reverse, 0, 0..@options[:columns])
    map
  else
    Dispel::StyleMap.single_line_reversed(@options[:columns])
  end
end

#viewObject



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

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