dynmenu 0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/dynmenu +3 -0
- data/lib/command.rb +42 -58
- data/lib/editor.rb +16 -15
- data/lib/history.rb +7 -23
- data/lib/item.rb +1 -1
- data/lib/menu.rb +13 -17
- data/lib/root_menu.rb +5 -4
- data/lib/run_menu.rb +7 -5
- data/lib/style.rb +2 -2
- metadata +5 -3
data/bin/dynmenu
CHANGED
data/lib/command.rb
CHANGED
@@ -1,57 +1,52 @@
|
|
1
1
|
require 'item'
|
2
|
+
require 'uri'
|
3
|
+
|
2
4
|
|
3
5
|
class Command
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@@RE_BROWSER = Regexp.new(/(chrom[e|ium]|iron|navigator|firefox|opera)/i)
|
10
|
-
end
|
6
|
+
@@RE_COMMAND = Regexp.new(/^[+\^\*]*.+(\s[+\^\*])*(\s[@#][A-Za-z0-9_-]+)*$/)
|
7
|
+
@@RE_MODES = Regexp.new(/^[+\^\*=]+$/)
|
8
|
+
@@RE_METHOD = Regexp.new(/^:\s*(.*)/)
|
9
|
+
@@RE_BROWSER = Regexp.new(/(chrom[e|ium]|iron|navigator|firefox|opera)/i)
|
10
|
+
@@RE_SEARCH = Regexp.new(/^[gs]\s+(.*)/)
|
11
11
|
@@RE_URI = Regexp.new(/^((w\s+((https?|ftp):\/\/)?)|(https?|ftp):\/\/)(?:[A-Z0-9-]+.)+[A-Z]{2,6}([\/?].+)?$/i)
|
12
12
|
@@RE_PROTO = Regexp.new(/^(http|https):\/\/.*/)
|
13
13
|
|
14
14
|
include Item
|
15
15
|
|
16
|
+
attr_reader :tags, :views, :app, :modes, :command
|
17
|
+
|
16
18
|
def initialize name, command = nil
|
17
19
|
@name = name
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@app = ""
|
22
|
-
@modes = ""
|
23
|
-
end
|
20
|
+
clear_subtle_vars
|
21
|
+
self.command = command
|
22
|
+
end
|
24
23
|
|
25
|
-
|
24
|
+
def clear_subtle_vars
|
25
|
+
@tags = []
|
26
|
+
@views = []
|
27
|
+
@app = ""
|
28
|
+
@modes = []
|
26
29
|
end
|
27
30
|
|
28
31
|
def encode_with coder
|
29
32
|
coder['name'] = @name
|
30
33
|
coder['command'] = @command
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
coder['modes'] = @modes
|
36
|
-
end
|
34
|
+
coder['tags'] = @tags
|
35
|
+
coder['views'] = @views
|
36
|
+
coder['app'] = @app
|
37
|
+
coder['modes'] = @modes
|
37
38
|
end
|
38
39
|
|
39
40
|
def init_with coder
|
40
41
|
@name = coder['name']
|
41
42
|
@command = coder['command']
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
@modes = coder['modes'] || ""
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def command
|
51
|
-
@command
|
43
|
+
@tags = coder['tags']
|
44
|
+
@views = coder['views']
|
45
|
+
@app = coder['app']
|
46
|
+
@modes = coder['modes']
|
52
47
|
end
|
53
48
|
|
54
|
-
def
|
49
|
+
def command= command
|
55
50
|
unless command.nil? || command.empty?
|
56
51
|
if @@RE_URI.match command
|
57
52
|
split = Regexp.last_match(0).split(/\s+/)
|
@@ -64,17 +59,22 @@ class Command
|
|
64
59
|
if @@RE_METHOD.match(command)
|
65
60
|
command = Regexp.last_match(0).to_sym
|
66
61
|
elsif @@RE_COMMAND.match command
|
67
|
-
|
68
|
-
@views = []
|
69
|
-
@app = ""
|
70
|
-
@modes = ""
|
62
|
+
clear_subtle_vars
|
71
63
|
|
72
64
|
command.split.each do |arg|
|
73
65
|
case arg[0]
|
74
66
|
when '#' then @tags << arg[1..-1]
|
75
67
|
when '@' then @views << arg[1..-1]
|
76
|
-
when '+', '^', '*'
|
77
|
-
|
68
|
+
when '+', '^', '*','='
|
69
|
+
mode_s = @@RE_MODES.match(arg).to_s
|
70
|
+
@modes += mode_s.split(//).map! do |c|
|
71
|
+
case c
|
72
|
+
when '+' then :full
|
73
|
+
when '^' then :float
|
74
|
+
when '*' then :stick
|
75
|
+
when '=' then :zaphod
|
76
|
+
end
|
77
|
+
end
|
78
78
|
else
|
79
79
|
if @app.nil? || @app.empty?
|
80
80
|
@app = arg
|
@@ -129,11 +129,10 @@ class Command
|
|
129
129
|
system "#{@command} &>/dev/null"
|
130
130
|
end
|
131
131
|
when URI
|
132
|
-
|
133
|
-
system "xdg-open '%s' &>/dev/null &" % [ @command.to_s ]
|
132
|
+
system "xdg-open '%s' &>/dev/null" % [ @command.to_s ]
|
134
133
|
if $subtle
|
135
|
-
find_browser
|
136
|
-
|
134
|
+
browser = find_browser
|
135
|
+
browser.focus unless browser.nil?
|
137
136
|
end
|
138
137
|
end
|
139
138
|
true
|
@@ -152,23 +151,8 @@ class Command
|
|
152
151
|
end
|
153
152
|
unless (client = Subtlext::Client.spawn(@app)).nil?
|
154
153
|
client.tags = tags unless tags.empty?
|
155
|
-
unless @modes.empty?
|
156
|
-
flags = []
|
157
|
-
|
158
|
-
@modes.each_char do |c|
|
159
|
-
case c
|
160
|
-
when '+' then flags << :full
|
161
|
-
when '^' then flags << :float
|
162
|
-
when '*' then flags << :stick
|
163
|
-
when '=' then flags << :zaphod
|
164
|
-
end
|
165
|
-
end
|
166
|
-
client.flags = flags
|
167
|
-
end
|
154
|
+
client.flags = @modes unless @modes.empty?
|
168
155
|
end
|
169
|
-
|
170
|
-
|
171
|
-
def to_s
|
172
|
-
"#{@name} => #{command}"
|
156
|
+
true
|
173
157
|
end
|
174
158
|
end
|
data/lib/editor.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'menu'
|
2
2
|
require 'dynamic'
|
3
3
|
|
4
|
+
|
4
5
|
class Editor < Menu
|
5
6
|
|
6
7
|
include Dynamic
|
@@ -12,12 +13,12 @@ class Editor < Menu
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def name
|
15
|
-
"> #{
|
16
|
+
"> #{Editor.name}"
|
16
17
|
end
|
17
18
|
|
18
19
|
def initialize parent
|
19
20
|
@parent = parent
|
20
|
-
|
21
|
+
self.style = parent.style
|
21
22
|
end
|
22
23
|
|
23
24
|
def to_s
|
@@ -35,13 +36,13 @@ class Editor < Menu
|
|
35
36
|
entries << "Done"
|
36
37
|
selection = show_menu entries, @@name
|
37
38
|
case entries.index selection
|
38
|
-
when 0 then @parent.
|
39
|
-
when 1 then @parent.
|
39
|
+
when 0 then @parent.name = show_menu([@parent.name], "Edit Name")
|
40
|
+
when 1 then @parent.style = show_style_menu
|
40
41
|
when 2 then show_entries_menu
|
41
42
|
when 3 then show_run_menu_menu
|
42
43
|
end
|
43
44
|
end
|
44
|
-
|
45
|
+
false
|
45
46
|
end
|
46
47
|
|
47
48
|
def show_run_menu_menu
|
@@ -57,7 +58,7 @@ class Editor < Menu
|
|
57
58
|
entries << "Done"
|
58
59
|
selection = show_menu entries, "Run menu"
|
59
60
|
case entries.index selection
|
60
|
-
when 0 then @parent.
|
61
|
+
when 0 then @parent.run_menu = !@parent.run_menu?
|
61
62
|
when 1 then show_history_menu
|
62
63
|
end
|
63
64
|
end
|
@@ -78,15 +79,15 @@ class Editor < Menu
|
|
78
79
|
entries << "Done"
|
79
80
|
|
80
81
|
selection = show_menu entries, "History"
|
81
|
-
case entries.index
|
82
|
+
case entries.index selection
|
82
83
|
when 0
|
83
84
|
selection = (show_menu [], "Enter a number")
|
84
85
|
number = selection.to_i
|
85
|
-
@parent.history.
|
86
|
+
@parent.history.length = number unless number < 1 || number.to_s != selection
|
86
87
|
when 1
|
87
88
|
selection = (show_menu [], "Enter a number")
|
88
89
|
number = (show_menu [], "Enter a number").to_i
|
89
|
-
@parent.history.
|
90
|
+
@parent.history.show_num_items = number unless number.to_s != selection
|
90
91
|
when 2 then clear = !clear
|
91
92
|
when (entries.length - 1) then @parent.history.clear if clear
|
92
93
|
end
|
@@ -112,7 +113,7 @@ class Editor < Menu
|
|
112
113
|
colors = [:bg, :fg, :bg_hi, :fg_hi]
|
113
114
|
unless (entries.index selection).nil?
|
114
115
|
if (entries.index selection) < 4
|
115
|
-
style.
|
116
|
+
style.color = colors[entries.index selection], show_menu([style.color(colors[entries.index selection])], "Enter a color")
|
116
117
|
elsif (entries.index selection) < 5
|
117
118
|
if style.font.nil?
|
118
119
|
selection = show_menu(["default"], "Set font")
|
@@ -120,7 +121,7 @@ class Editor < Menu
|
|
120
121
|
selection = show_menu([style.font], "Set font")
|
121
122
|
end
|
122
123
|
unless selection.nil? || selection == "default"
|
123
|
-
style.
|
124
|
+
style.font = selection
|
124
125
|
end
|
125
126
|
end
|
126
127
|
end
|
@@ -202,12 +203,12 @@ class Editor < Menu
|
|
202
203
|
case entries.index selection
|
203
204
|
when 0
|
204
205
|
new_name = show_menu([command.name], "Enter a name")
|
205
|
-
command.
|
206
|
+
command.name = new_name unless new_name.empty?
|
206
207
|
when 1
|
207
208
|
history = History.new 1, 1
|
208
209
|
history.update command.command unless command.command.nil? or command.command.empty?
|
209
210
|
new_command = Run_Menu.new(self, history, "Enter a command").show_menu
|
210
|
-
command.
|
211
|
+
command.command = new_command unless new_command.empty?
|
211
212
|
when 2 then delete = !delete unless new
|
212
213
|
end
|
213
214
|
end
|
@@ -219,7 +220,7 @@ class Editor < Menu
|
|
219
220
|
new = menu.nil?
|
220
221
|
if new
|
221
222
|
menu = Menu.new "New menu"
|
222
|
-
menu.
|
223
|
+
menu.style = @parent.style
|
223
224
|
end
|
224
225
|
@parent.remove_item menu
|
225
226
|
entries = []
|
@@ -241,7 +242,7 @@ class Editor < Menu
|
|
241
242
|
selection = show_menu entries, string
|
242
243
|
if (entries.index selection) == 0
|
243
244
|
new_name = show_menu [], "Enter a name"
|
244
|
-
menu.
|
245
|
+
menu.name = new_name unless new_name.empty?
|
245
246
|
end
|
246
247
|
delete = !delete if (entries.index selection) == 1 && !new
|
247
248
|
end
|
data/lib/history.rb
CHANGED
@@ -1,24 +1,11 @@
|
|
1
1
|
class History
|
2
|
-
def initialize length, show_num_items = 5
|
3
|
-
@items = {}
|
4
|
-
set_length length
|
5
|
-
set_show_num_items show_num_items
|
6
|
-
end
|
7
|
-
|
8
|
-
def length
|
9
|
-
@length
|
10
|
-
end
|
11
2
|
|
12
|
-
|
13
|
-
@show_num_items
|
14
|
-
end
|
3
|
+
attr_accessor :length, :show_num_items
|
15
4
|
|
16
|
-
def
|
17
|
-
@
|
18
|
-
|
19
|
-
|
20
|
-
def set_show_num_items num
|
21
|
-
@show_num_items = num
|
5
|
+
def initialize length, show_num_items = 5
|
6
|
+
@items = {}
|
7
|
+
self.length = length
|
8
|
+
self.show_num_items = show_num_items
|
22
9
|
end
|
23
10
|
|
24
11
|
def update item
|
@@ -30,11 +17,8 @@ class History
|
|
30
17
|
end
|
31
18
|
|
32
19
|
def items
|
33
|
-
|
34
|
-
|
35
|
-
}
|
36
|
-
ret.store :rest, (@items.reject {|item, age| ret[:first].include? item}).keys
|
37
|
-
ret
|
20
|
+
sorted_items = (@items.sort_by {|item,age| age}).map {|pair| pair.first}
|
21
|
+
sorted_items.partition {|item| sorted_items.index(item) < (@show_num_items)}
|
38
22
|
end
|
39
23
|
|
40
24
|
def clear
|
data/lib/item.rb
CHANGED
data/lib/menu.rb
CHANGED
@@ -1,27 +1,31 @@
|
|
1
1
|
require 'item'
|
2
2
|
|
3
|
+
|
3
4
|
class Menu
|
4
5
|
|
5
6
|
include Item
|
6
7
|
|
8
|
+
attr_accessor :style
|
9
|
+
attr_writer :name
|
10
|
+
|
7
11
|
def initialize name
|
8
|
-
|
12
|
+
self.name = name
|
9
13
|
@items = Hash.new
|
10
|
-
|
11
|
-
set_item
|
14
|
+
self.style = Style.new
|
15
|
+
set_item(Editor.new self) unless self.is_a? Dynamic
|
12
16
|
end
|
13
17
|
|
14
18
|
def encode_with coder
|
15
19
|
coder['name'] = @name
|
16
20
|
coder['items'] = items
|
17
|
-
coder['style'] =
|
21
|
+
coder['style'] = style
|
18
22
|
end
|
19
23
|
|
20
24
|
def init_with coder
|
21
|
-
|
25
|
+
self.name = coder['name']
|
22
26
|
@items = coder['items']
|
23
|
-
|
24
|
-
set_item
|
27
|
+
self.style = coder['style']
|
28
|
+
set_item(Editor.new self)
|
25
29
|
end
|
26
30
|
|
27
31
|
def set_item item
|
@@ -40,14 +44,6 @@ class Menu
|
|
40
44
|
"> #{super}"
|
41
45
|
end
|
42
46
|
|
43
|
-
def style
|
44
|
-
@style
|
45
|
-
end
|
46
|
-
|
47
|
-
def set_style style
|
48
|
-
@style = style
|
49
|
-
end
|
50
|
-
|
51
47
|
def to_s
|
52
48
|
string = "#{name}\n"
|
53
49
|
string += (@items.keys.sort.map {|name| name.prepend(" ")}).join("\n")
|
@@ -84,8 +80,8 @@ class Menu
|
|
84
80
|
|
85
81
|
def get_font_string
|
86
82
|
font = ""
|
87
|
-
unless
|
88
|
-
font = "-fn \"#{
|
83
|
+
unless self.style.font.nil?
|
84
|
+
font = "-fn \"#{self.style.font}\""
|
89
85
|
end
|
90
86
|
font
|
91
87
|
end
|
data/lib/root_menu.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'menu'
|
2
|
+
|
2
3
|
class Root_Menu < Menu
|
3
4
|
|
5
|
+
attr_writer :run_menu
|
6
|
+
attr_reader :history
|
7
|
+
|
4
8
|
def initialize history_length = 1000, history_items = 5
|
5
9
|
super "Dynmenu"
|
6
|
-
|
10
|
+
self.run_menu = true
|
7
11
|
@history = History.new history_length, history_items
|
8
12
|
set_item Run_Menu.new self, @history
|
9
13
|
end
|
@@ -21,9 +25,6 @@ class Root_Menu < Menu
|
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
|
-
def set_run_menu value
|
25
|
-
@run_menu = value
|
26
|
-
end
|
27
28
|
|
28
29
|
def encode_with coder
|
29
30
|
super
|
data/lib/run_menu.rb
CHANGED
@@ -4,12 +4,12 @@ class Run_Menu < Menu
|
|
4
4
|
|
5
5
|
include Dynamic
|
6
6
|
|
7
|
-
@@RE_HIDDEN = Regexp.new
|
7
|
+
@@RE_HIDDEN = Regexp.new(/(^|\/)\.[^\/]*$/i)
|
8
8
|
def initialize parent, history = History.new(1, 5), name = "Run"
|
9
|
-
|
9
|
+
self.name = name
|
10
10
|
@parent = parent
|
11
11
|
@history = history
|
12
|
-
|
12
|
+
self.style = parent.style
|
13
13
|
end
|
14
14
|
|
15
15
|
def name
|
@@ -26,8 +26,10 @@ class Run_Menu < Menu
|
|
26
26
|
def show_menu
|
27
27
|
get_files
|
28
28
|
history_items = @history.items
|
29
|
-
items = history_items
|
30
|
-
|
29
|
+
items = history_items.first
|
30
|
+
items << '---' unless items.empty?
|
31
|
+
items += @files + history_items[1]
|
32
|
+
super items, self.name
|
31
33
|
end
|
32
34
|
|
33
35
|
def get_files dirs = (`echo $PATH`).split(':')
|
data/lib/style.rb
CHANGED
@@ -9,7 +9,7 @@ class Style
|
|
9
9
|
}
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def color= color, value
|
13
13
|
unless @colors.keys.include? color
|
14
14
|
raise ArgumentError, "Invalid key!"
|
15
15
|
end
|
@@ -26,7 +26,7 @@ class Style
|
|
26
26
|
@colors[color]
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def font= font
|
30
30
|
@font = font
|
31
31
|
end
|
32
32
|
def to_s
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynmenu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A dmenu wrapper for subtle wm
|
15
15
|
email: mail@jreinert.com
|
@@ -46,10 +46,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
- - ! '>='
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
|
-
requirements:
|
49
|
+
requirements:
|
50
|
+
- dmenu
|
50
51
|
rubyforge_project:
|
51
52
|
rubygems_version: 1.8.23
|
52
53
|
signing_key:
|
53
54
|
specification_version: 3
|
54
55
|
summary: Dynmenu
|
55
56
|
test_files: []
|
57
|
+
has_rdoc:
|