ppcurses 0.0.12 → 0.0.13
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/lib/ppcurses/actions/GetEnumeratedStringAction.rb +47 -44
- data/lib/ppcurses.rb +1 -0
- metadata +3 -3
@@ -1,60 +1,63 @@
|
|
1
|
-
require
|
1
|
+
require 'ppcurses/actions/BaseAction.rb'
|
2
2
|
|
3
|
-
|
3
|
+
module PPCurses
|
4
4
|
|
5
|
-
|
6
|
-
# i.e. CD, Vinyl, MP3
|
7
|
-
def initialize(prompt, enumeration)
|
8
|
-
super(prompt)
|
5
|
+
class GetEnumeratedStringAction < PromptAction
|
9
6
|
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@options = enumeration
|
15
|
-
@currOption = 0
|
16
|
-
end
|
7
|
+
# enumeration is a list of possible values
|
8
|
+
# i.e. CD, Vinyl, MP3
|
9
|
+
def initialize(prompt, enumeration)
|
10
|
+
super(prompt)
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@win.addstr(option)
|
22
|
-
if ( index == @currOption ) then
|
23
|
-
@win.addstr(" [X] ")
|
24
|
-
else
|
25
|
-
@win.addstr(" [ ] ")
|
12
|
+
# verify enumeration is an array
|
13
|
+
if ( enumeration.respond_to?('each_with_index') == false ) then
|
14
|
+
raise
|
26
15
|
end
|
16
|
+
@options = enumeration
|
17
|
+
@currOption = 0
|
18
|
+
end
|
19
|
+
|
20
|
+
def printPrompt()
|
21
|
+
super()
|
22
|
+
@options.each_with_index do |option, index|
|
23
|
+
@win.addstr(option)
|
24
|
+
if ( index == @currOption ) then
|
25
|
+
@win.addstr(" [X] ")
|
26
|
+
else
|
27
|
+
@win.addstr(" [ ] ")
|
28
|
+
end
|
27
29
|
|
30
|
+
end
|
28
31
|
end
|
29
|
-
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
def execute()
|
34
|
+
printPrompt()
|
35
|
+
# Enables reading arrow keys in getch
|
36
|
+
@win.keypad(true)
|
37
|
+
while(1)
|
38
|
+
noecho
|
39
|
+
c = @win.getch
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
if c == KEY_LEFT then @currOption = @currOption-1 end
|
42
|
+
if c == KEY_RIGHT then @currOption= @currOption+1 end
|
43
|
+
if c == 10 then break end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
+
if (@currOption < 0 ) then @currOption = @options.length-1 end
|
46
|
+
if (@currOption > @options.length-1 ) then @currOption = 0 end
|
45
47
|
|
48
|
+
echo
|
49
|
+
printPrompt()
|
50
|
+
end
|
46
51
|
echo
|
47
|
-
|
52
|
+
# Go to next line so that further actions to overwrite
|
53
|
+
# the choice
|
54
|
+
@win.setpos(@win.cury() + 1, xPadding())
|
48
55
|
end
|
49
|
-
echo
|
50
|
-
# Go to next line so that further actions to overwrite
|
51
|
-
# the choice
|
52
|
-
@win.setpos(@win.cury() + 1, @parent.winPadding())
|
53
|
-
end
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
57
|
+
def data
|
58
|
+
@options[@currOption]
|
59
|
+
end
|
58
60
|
|
59
|
-
end
|
61
|
+
end
|
60
62
|
|
63
|
+
end
|
data/lib/ppcurses.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ppcurses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 13
|
10
|
+
version: 0.0.13
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matthieu Cormier
|