Class: VER::View::List::Ex

Inherits:
VER::View::List show all
Defined in:
lib/ver/view/list/ex.rb

Instance Attribute Summary

Attributes inherited from VER::View::List

#callback, #entry, #frame, #list, #parent, #tag

Instance Method Summary collapse

Methods inherited from VER::View::List

#cancel, #destroy, #line_down, #line_up, #message, #on_update, #pick, #pick_action, #pick_first, #quit, #select_index, #setup_events, #setup_keymap, #setup_widgets, #sublist

Constructor Details

#initialize(parent, filter, &callback) ⇒ Ex

Returns a new instance of Ex.



3
4
5
6
7
8
# File 'lib/ver/view/list/ex.rb', line 3

def initialize(parent, filter, &callback)
  @filter = filter
  @previous = ''
  @propose = nil
  super(parent, &callback)
end

Instance Method Details

#complete_arg(arg, possible) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ver/view/list/ex.rb', line 48

def complete_arg(arg, possible)
  case possible.size
  when 0
    return arg
  when 1
    return possible.first
  else
    require 'abbrev'
    abbrev = possible.abbrev

    if found = abbrev[arg]
      return found
    else
      return abbrev.keys.sort_by{|k| k.size }.first[0..-2]
    end
  end
end

#complete_command(command, arg) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ver/view/list/ex.rb', line 36

def complete_command(command, arg)
  name = "complete_#{command}"

  if respond_to?(name)
    possible = send(name, arg)
    list.value = possible
    completed = complete_arg(arg, possible)
    @command, @propose = command, completed
    entry.value = "#{command} #{completed}"
  end
end

#complete_e(value) ⇒ Object Also known as: complete_o



66
67
68
# File 'lib/ver/view/list/ex.rb', line 66

def complete_e(value)
  Dir["#{value}*"].map{|f| File.directory?(f) ? "#{f}/" : f }
end

#completionObject



30
31
32
33
34
# File 'lib/ver/view/list/ex.rb', line 30

def completion
  value = entry.value
  command, arg = value.split(' ', 2)
  complete_command(command, arg)
end

#pick_selectionObject



20
21
22
23
24
25
26
27
28
# File 'lib/ver/view/list/ex.rb', line 20

def pick_selection
  if @propose
    pick_action(@command, @propose)
  else
    pick_action(entry.value)
  end

  destroy
end

#updateObject



10
11
12
13
14
15
16
17
18
# File 'lib/ver/view/list/ex.rb', line 10

def update
  value = entry.value

  if value =~ /\s/
    completion
  else
    list.value = @filter.call(value)
  end
end