dmenu 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +29 -0
- data/README +2 -0
- data/lib/dmenu.rb +97 -0
- data/lib/dmenu/item.rb +13 -0
- metadata +69 -0
data/LICENSE
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Copyright (c) <YEAR>, Dominik Honnef <dominikho@gmx.net>
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are
|
6
|
+
met:
|
7
|
+
|
8
|
+
- Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
- Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
13
|
+
documentation and/or other materials provided with the distribution.
|
14
|
+
|
15
|
+
- Neither the name of the author nor the names of the
|
16
|
+
contributors may be used to endorse or promote products derived from
|
17
|
+
this software without specific prior written permission.
|
18
|
+
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
20
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
21
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
22
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
25
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
26
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
27
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README
ADDED
data/lib/dmenu.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require "shellwords"
|
2
|
+
require "dmenu/item"
|
3
|
+
|
4
|
+
# @example A simple menu
|
5
|
+
# menu = Dmenu.new
|
6
|
+
# menu.items = ["foo", "bar", Dmenu::Item.new("baz", 123)]
|
7
|
+
#
|
8
|
+
# menu.run # this will return a Dmenu::Item, according to what the user selected.
|
9
|
+
class Dmenu
|
10
|
+
# @return [Array<#to_s, Item>] Items to display in the menu. Items
|
11
|
+
# that are not an instance of the {Item} class will transparently
|
12
|
+
# be converted into one.
|
13
|
+
attr_accessor :items
|
14
|
+
# @return [Symbol<:top, :bottom>] Where to display the menu on screen.
|
15
|
+
attr_accessor :position
|
16
|
+
# @return [Boolean] If true, menu entries will be matched case insensitively.
|
17
|
+
attr_accessor :case_insensitive
|
18
|
+
# @return [Number] Number of lines to display. If >1, dmenu will go into vertical mode.
|
19
|
+
attr_accessor :lines
|
20
|
+
# @return [String] Which font to use.
|
21
|
+
attr_accessor :font
|
22
|
+
# @return [String] The background color of normal items.
|
23
|
+
attr_accessor :background
|
24
|
+
# @return [String] The foreground color of normal items.
|
25
|
+
attr_accessor :foreground
|
26
|
+
# @return [String] The background color of selected items.
|
27
|
+
attr_accessor :selected_background
|
28
|
+
# @return [String] The foreground color of selected items.
|
29
|
+
attr_accessor :selected_foreground
|
30
|
+
# @return [String] Defines a prompt to be displayed before the input area.
|
31
|
+
attr_accessor :prompt
|
32
|
+
def initialize
|
33
|
+
@items = []
|
34
|
+
@position = :top
|
35
|
+
@case_insensitive = false
|
36
|
+
@lines = 1
|
37
|
+
@font = nil
|
38
|
+
@background = nil
|
39
|
+
@foreground = nil
|
40
|
+
@selected_background = nil
|
41
|
+
@selected_foreground = nil
|
42
|
+
@prompt = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
# Launches dmenu, displays the generated menu and waits for the user
|
46
|
+
# to make a choice.
|
47
|
+
#
|
48
|
+
# @return [Item, nil] Returns the selected item or nil, if the user
|
49
|
+
# didn't make any selection (i.e. pressed ESC)
|
50
|
+
def run
|
51
|
+
command = "dmenu #{args}"
|
52
|
+
puts command
|
53
|
+
pipe = IO.popen(command, "w+")
|
54
|
+
|
55
|
+
items = @items.map {|item|
|
56
|
+
if item.is_a?(Item)
|
57
|
+
item
|
58
|
+
else
|
59
|
+
Item.new(item, item)
|
60
|
+
end
|
61
|
+
}
|
62
|
+
|
63
|
+
items.each do |item|
|
64
|
+
pipe.puts item.key.to_s
|
65
|
+
end
|
66
|
+
|
67
|
+
pipe.close_write
|
68
|
+
value = pipe.read
|
69
|
+
pipe.close
|
70
|
+
|
71
|
+
if $?.exitstatus > 0
|
72
|
+
return nil
|
73
|
+
end
|
74
|
+
|
75
|
+
selection = items.find {|item|
|
76
|
+
item.key == value
|
77
|
+
}
|
78
|
+
|
79
|
+
return selection
|
80
|
+
end
|
81
|
+
|
82
|
+
def args
|
83
|
+
args = []
|
84
|
+
args << "-b" if @position == :bottom
|
85
|
+
args << "-i" if @case_insensitive
|
86
|
+
args << "-l #@lines" if @lines > 1
|
87
|
+
args << "-fn " + Shellwords.escape(@font) if @font
|
88
|
+
args << "-nb " + Shellwords.escape(@background) if @background
|
89
|
+
args << "-nf " + Shellwords.escape(@foreground) if @foreground
|
90
|
+
args << "-sb " + Shellwords.escape(@selected_background) if @selected_background
|
91
|
+
args << "-sf " + Shellwords.escape(@selected_foreground) if @selected_foreground
|
92
|
+
args << "-p " + Shellwords.escape(@prompt) if @prompt
|
93
|
+
|
94
|
+
args.join(" ")
|
95
|
+
end
|
96
|
+
private :args
|
97
|
+
end
|
data/lib/dmenu/item.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class Dmenu
|
2
|
+
class Item
|
3
|
+
# @return [#to_s] The key is what will be displayed in the menu.
|
4
|
+
attr_reader :key
|
5
|
+
# @return [Object] The value can be any kind of object you wish to
|
6
|
+
# assign to the key.
|
7
|
+
attr_reader :value
|
8
|
+
def initialize(key, value)
|
9
|
+
@key = key
|
10
|
+
@value = value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dmenu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Dominik Honnef
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-10-02 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A Ruby OOP wrapper around dmenu.
|
22
|
+
email: dominikh@fork-bomb.org
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/dmenu/item.rb
|
31
|
+
- lib/dmenu.rb
|
32
|
+
- README
|
33
|
+
- LICENSE
|
34
|
+
has_rdoc: yard
|
35
|
+
homepage: http://fork-bomb.org
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
segments:
|
49
|
+
- 1
|
50
|
+
- 9
|
51
|
+
- 1
|
52
|
+
version: 1.9.1
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.7
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: A Ruby OOP wrapper around dmenu.
|
68
|
+
test_files: []
|
69
|
+
|