Class: Menu
- Inherits:
-
Object
show all
- Includes:
- Item
- Defined in:
- lib/menu.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name) ⇒ Menu
Returns a new instance of Menu.
12
13
14
15
16
17
|
# File 'lib/menu.rb', line 12
def initialize name
self.name = name
@items = Hash.new
self.style = Style.new
set_item(Editor.new self) unless self.is_a? Dynamic
end
|
Instance Attribute Details
#name ⇒ Object
50
51
52
|
# File 'lib/menu.rb', line 50
def name
"> #{super}"
end
|
#path ⇒ Object
19
20
21
|
# File 'lib/menu.rb', line 19
def path
@path ||= '$PATH'
end
|
#style ⇒ Object
Returns the value of attribute style.
8
9
10
|
# File 'lib/menu.rb', line 8
def style
@style
end
|
Instance Method Details
#encode_with(coder) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/menu.rb', line 23
def encode_with coder
coder['name'] = @name
coder['items'] = items
coder['style'] = style
coder['path'] = path
end
|
#execute ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/menu.rb', line 59
def execute
show = true
while show
selection = @items.keys.sort, @name
item = @items[selection]
if item.nil?
show = false
else
show = !item.execute unless item.nil?
end
end
!item.nil?
end
|
#filter_entries(entries) ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/menu.rb', line 72
def filter_entries entries
if @items.nil?
entries
else
entries.reject {|entry| @items[entry].is_a?(Editor)}
end
end
|
#get_font_string ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/menu.rb', line 88
def get_font_string
font = ""
unless self.style.font.nil?
font = "-fn \"#{self.style.font}\""
end
font
end
|
#init_with(coder) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/menu.rb', line 30
def init_with coder
self.name = coder['name']
@items = coder['items']
self.style = coder['style']
set_item(Editor.new self)
self.path = coder['path']
end
|
#items ⇒ Object
42
43
44
|
# File 'lib/menu.rb', line 42
def items
@items.reject { |name,item| item.is_a?(Dynamic) }
end
|
#remove_item(item) ⇒ Object
46
47
48
|
# File 'lib/menu.rb', line 46
def remove_item item
@items.delete item.name unless item.is_a? Dynamic
end
|
#set_item(item) ⇒ Object
38
39
40
|
# File 'lib/menu.rb', line 38
def set_item item
@items[item.name] = item unless @items[item.name].is_a? Dynamic
end
|
79
80
81
82
83
84
85
86
|
# File 'lib/menu.rb', line 79
def entries, name, = true
entries = filter_entries entries
unless $read_only || self.is_a?(Dynamic)
entries << "> #{Editor.name}"
end
command = "echo \"#{entries.join "\n"}\" | dmenu -i #{$location}-l #{$lines} #{get_font_string} -nf \"#{@style.color :fg}\" -nb \"#{@style.color :bg}\" -sf \"#{@style.color :fg_hi}\" -sb \"#{@style.color :bg_hi}\" -p \"#{name}\""
(`#{command}`).strip
end
|
#to_s ⇒ Object
54
55
56
57
|
# File 'lib/menu.rb', line 54
def to_s
string = "#{name}\n"
string += (@items.keys.sort.map {|name| name.prepend(" ")}).join("\n")
end
|