easy_dialog 0.0.1 → 0.0.2
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/README.md +1 -0
- data/lib/easy_dialog/version.rb +1 -1
- data/lib/easy_dialog.rb +55 -0
- metadata +2 -2
data/README.md
CHANGED
data/lib/easy_dialog/version.rb
CHANGED
data/lib/easy_dialog.rb
CHANGED
@@ -54,4 +54,59 @@ module EasyDialog
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
+
|
58
|
+
class Checkbox < Choises
|
59
|
+
def ask
|
60
|
+
@result = Array.new
|
61
|
+
width = @choises.max_by {|s| s.length}.length + 1
|
62
|
+
num = 80 / width
|
63
|
+
highlight = 0
|
64
|
+
Curses.noecho
|
65
|
+
Curses.init_screen
|
66
|
+
Curses.start_color
|
67
|
+
Curses.stdscr.keypad(true)
|
68
|
+
Curses.init_pair 1, Curses::COLOR_BLACK, Curses::COLOR_RED
|
69
|
+
Curses.init_pair 2, Curses::COLOR_BLACK, Curses::COLOR_YELLOW
|
70
|
+
loop do
|
71
|
+
Curses.setpos 0, 0
|
72
|
+
Curses.attroff(Curses::A_COLOR)
|
73
|
+
Curses.addstr(@question)
|
74
|
+
@choises.each_with_index do |c,i|
|
75
|
+
Curses.setpos i/num + 1, i%num*width
|
76
|
+
if i == highlight
|
77
|
+
Curses.attrset(Curses.color_pair(1))
|
78
|
+
elsif @result.any? {|r| r.equal? c}
|
79
|
+
Curses.attrset(Curses.color_pair(2))
|
80
|
+
else
|
81
|
+
Curses.attroff(Curses::A_COLOR)
|
82
|
+
end
|
83
|
+
Curses.addstr(c)
|
84
|
+
end
|
85
|
+
Curses.refresh
|
86
|
+
case hoge = Curses.getch
|
87
|
+
when Curses::Key::RIGHT
|
88
|
+
highlight = highlight + 1
|
89
|
+
when Curses::Key::LEFT
|
90
|
+
highlight = highlight - 1
|
91
|
+
when Curses::Key::UP
|
92
|
+
highlight = highlight - num
|
93
|
+
when Curses::Key::DOWN
|
94
|
+
highlight = highlight + num
|
95
|
+
when 27
|
96
|
+
Curses.close_screen
|
97
|
+
return @result
|
98
|
+
when 10
|
99
|
+
if @result.any? {|r| r.equal? @choises[highlight]}
|
100
|
+
@result.delete_if {|r| r.equal? @choises[highlight]}
|
101
|
+
else
|
102
|
+
@result<<@choises[highlight]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
if highlight >= @choises.length
|
106
|
+
highlight = @choises.length - 1
|
107
|
+
end
|
108
|
+
highlight = 0 if highlight < 0
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
57
112
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_dialog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-12-
|
12
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Easy CLI dialog
|
15
15
|
email:
|