ppcurses 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +23 -0
- data/lib/ppcurses/Screen.rb +8 -0
- data/lib/ppcurses/menu/CompositeMenu.rb +21 -12
- data/lib/ppcurses/menu/Menu.rb +2 -2
- data/lib/ppcurses/menu/RadioMenu.rb +66 -69
- data/lib/ppcurses.rb +4 -0
- data/test/compositeMenu.rb +20 -0
- data/test/menuInMenu.rb +1 -1
- metadata +5 -4
- data/README.md +0 -6
data/README.rdoc
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
= PPCurses
|
2
|
+
|
3
|
+
Some convenience code to initialize curses and some rudimentary GUI classes. See the **test** directory for example usage programs.
|
4
|
+
|
5
|
+
== Install
|
6
|
+
[sudo] gem install 'ppcurses'
|
7
|
+
|
8
|
+
== Usage
|
9
|
+
require 'rubygems'
|
10
|
+
require 'ppcurses'
|
11
|
+
|
12
|
+
def displayMenu()
|
13
|
+
mainMenu = PPCurses::Menu.new( [ "Press", "<ESCAPE>", "to Quit" ], nil )
|
14
|
+
mainMenu.show()
|
15
|
+
mainMenu.getMenuSelection()
|
16
|
+
mainMenu.close()
|
17
|
+
end
|
18
|
+
|
19
|
+
screen = PPCurses::Screen.new()
|
20
|
+
screen.run { displayMenu() }
|
21
|
+
|
22
|
+
== References
|
23
|
+
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/curses/rdoc/Curses.html
|
data/lib/ppcurses/Screen.rb
CHANGED
@@ -2,8 +2,16 @@ require "curses"
|
|
2
2
|
include Curses
|
3
3
|
|
4
4
|
module PPCurses
|
5
|
+
|
6
|
+
# Screen initializes the Curses screen
|
7
|
+
# Pass a code block to the run method to start things
|
5
8
|
class Screen
|
6
9
|
|
10
|
+
# Creates a curses session
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
# >> myScreen.run { displayMenu() }
|
14
|
+
#
|
7
15
|
def run( )
|
8
16
|
begin
|
9
17
|
init_screen
|
@@ -1,22 +1,31 @@
|
|
1
1
|
|
2
|
-
|
2
|
+
module PPCurses
|
3
3
|
|
4
|
-
|
5
|
-
@menu1 = menu1
|
6
|
-
@menu2 = menu2
|
4
|
+
class CompositeMenu
|
7
5
|
|
8
|
-
|
6
|
+
def initialize(menu1, menu2)
|
7
|
+
@menu1 = menu1
|
8
|
+
@menu2 = menu2
|
9
9
|
|
10
|
-
|
10
|
+
@menu1.setSubMenu(menu2)
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def show()
|
15
|
+
@menu1.show()
|
16
|
+
@menu2.show()
|
17
|
+
end
|
11
18
|
|
12
|
-
def show()
|
13
|
-
@menu1.show()
|
14
|
-
@menu2.show()
|
15
|
-
end
|
16
19
|
|
20
|
+
def getMenuSelection()
|
21
|
+
@menu1.getMenuSelection()
|
22
|
+
end
|
23
|
+
|
24
|
+
def close()
|
25
|
+
@menu1.close()
|
26
|
+
@menu2.close()
|
27
|
+
end
|
17
28
|
|
18
|
-
def getMenuSelection()
|
19
|
-
@menu1.getMenuSelection()
|
20
29
|
end
|
21
30
|
|
22
31
|
end
|
data/lib/ppcurses/menu/Menu.rb
CHANGED
@@ -1,102 +1,99 @@
|
|
1
|
-
# Curses reference:
|
2
|
-
# http://www.ruby-doc.org/stdlib-1.9.3/libdoc/curses/rdoc/Curses.html
|
3
1
|
|
4
|
-
require
|
5
|
-
require './ppcurses/BaseMenu.rb'
|
6
|
-
include Curses
|
2
|
+
require 'ppcurses/menu/BaseMenu.rb'
|
7
3
|
|
8
|
-
|
4
|
+
module PPCurses
|
5
|
+
class RadioMenu < BaseMenu
|
9
6
|
|
10
|
-
|
11
|
-
|
7
|
+
def initialize( menuItems, actionItems )
|
8
|
+
@items = Array.new
|
12
9
|
|
13
|
-
|
10
|
+
@menuLength = 0
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
menuItems.each do |item|
|
13
|
+
@items.push item
|
14
|
+
@menuLength += item.length + 5
|
15
|
+
end
|
19
16
|
|
20
|
-
|
17
|
+
@selection = 0
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@win = Window.new(3, winWidth ,0, (cols - winWidth) / 2)
|
32
|
-
|
33
|
-
@win.timeout=-1
|
34
|
-
# Enables reading arrow keys in getch
|
35
|
-
@win.keypad(true)
|
36
|
-
end
|
37
|
-
|
38
|
-
def show()
|
39
|
-
@win.box("|", "-")
|
40
|
-
y = 1
|
41
|
-
x = 2
|
19
|
+
unless actionItems.nil?
|
20
|
+
@actions = Array.new
|
21
|
+
actionItems.each do |item|
|
22
|
+
@actions.push item
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
winWidth = @menuLength + 4
|
42
27
|
|
43
|
-
|
28
|
+
@win = Window.new(3, winWidth ,0, (cols - winWidth) / 2)
|
44
29
|
|
45
|
-
|
46
|
-
|
47
|
-
|
30
|
+
@win.timeout=-1
|
31
|
+
# Enables reading arrow keys in getch
|
32
|
+
@win.keypad(true)
|
48
33
|
end
|
49
34
|
|
50
|
-
|
35
|
+
def show()
|
36
|
+
@win.box("|", "-")
|
37
|
+
y = 1
|
38
|
+
x = 2
|
51
39
|
|
52
|
-
|
40
|
+
@win.setpos(y, x)
|
53
41
|
|
42
|
+
for i in 0...@items.length
|
43
|
+
@win.addstr( @items[i] )
|
44
|
+
if @selection == i then @win.addstr(" [*] ") else @win.addstr(" [ ] " ) end
|
45
|
+
end
|
54
46
|
|
55
|
-
|
47
|
+
@win.refresh
|
56
48
|
|
57
|
-
|
58
|
-
c = @win.getch
|
49
|
+
end
|
59
50
|
|
60
|
-
processed = self.handleMenuSelection(c)
|
61
51
|
|
62
|
-
|
63
|
-
@win.clear
|
64
|
-
@win.refresh
|
65
|
-
break
|
66
|
-
end
|
52
|
+
def getMenuSelection()
|
67
53
|
|
68
|
-
|
54
|
+
while(1)
|
55
|
+
c = @win.getch
|
69
56
|
|
70
|
-
|
57
|
+
processed = self.handleMenuSelection(c)
|
71
58
|
|
59
|
+
if c == 27 then # ESCAPE
|
60
|
+
@win.clear
|
61
|
+
@win.refresh
|
62
|
+
break
|
63
|
+
end
|
72
64
|
|
73
|
-
|
74
|
-
n_choices = @items.length
|
65
|
+
end
|
75
66
|
|
76
|
-
if c == KEY_RIGHT then
|
77
|
-
if @selection < n_choices - 1 then @selection += 1 else @selection = 0 end
|
78
|
-
self.show()
|
79
67
|
end
|
80
68
|
|
81
|
-
if c == KEY_LEFT then
|
82
|
-
if @selection > 0 then @selection -= 1 else @selection = n_choices-1 end
|
83
|
-
self.show()
|
84
|
-
end
|
85
69
|
|
86
|
-
|
87
|
-
|
88
|
-
|
70
|
+
def handleMenuSelection(c)
|
71
|
+
n_choices = @items.length
|
72
|
+
|
73
|
+
if c == KEY_RIGHT then
|
74
|
+
if @selection < n_choices - 1 then @selection += 1 else @selection = 0 end
|
75
|
+
self.show()
|
76
|
+
end
|
77
|
+
|
78
|
+
if c == KEY_LEFT then
|
79
|
+
if @selection > 0 then @selection -= 1 else @selection = n_choices-1 end
|
89
80
|
self.show()
|
90
81
|
end
|
82
|
+
|
83
|
+
if c == 10 then # ENTER
|
84
|
+
unless @actions.nil?
|
85
|
+
@actions[@selection].execute()
|
86
|
+
self.show()
|
87
|
+
end
|
88
|
+
end
|
91
89
|
end
|
92
|
-
|
93
|
-
|
90
|
+
|
91
|
+
|
94
92
|
|
93
|
+
def close()
|
94
|
+
@win.close()
|
95
|
+
end
|
95
96
|
|
96
|
-
def close()
|
97
|
-
@win.close()
|
98
97
|
end
|
99
98
|
|
100
99
|
end
|
101
|
-
|
102
|
-
|
data/lib/ppcurses.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'ppcurses'
|
5
|
+
|
6
|
+
def displayMenu()
|
7
|
+
centerMenu = PPCurses::Menu.new( [ "Press", "<ESCAPE>", "to Quit" ], nil )
|
8
|
+
radioMenu = PPCurses::RadioMenu.new( [ "Wow", "another", "menu" ], nil )
|
9
|
+
|
10
|
+
mainMenu = PPCurses::CompositeMenu.new(centerMenu, radioMenu)
|
11
|
+
|
12
|
+
|
13
|
+
mainMenu.show()
|
14
|
+
mainMenu.getMenuSelection()
|
15
|
+
mainMenu.close()
|
16
|
+
end
|
17
|
+
|
18
|
+
screen = PPCurses::Screen.new()
|
19
|
+
screen.run { displayMenu() }
|
20
|
+
|
data/test/menuInMenu.rb
CHANGED
@@ -7,7 +7,7 @@ def displayMenu()
|
|
7
7
|
mainMenu = PPCurses::Menu.new( [ "Press", "<ESCAPE>", "to Quit" ], nil )
|
8
8
|
innerMenu = PPCurses::Menu.new( [ "Wow", "another", "menu" ], nil )
|
9
9
|
|
10
|
-
menuAction = ShowMenuAction.new(innerMenu)
|
10
|
+
menuAction = PPCurses::ShowMenuAction.new(innerMenu)
|
11
11
|
mainMenu.setGlobalAction(menuAction)
|
12
12
|
|
13
13
|
mainMenu.show()
|
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: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 9
|
10
|
+
version: 0.0.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matthieu Cormier
|
@@ -46,8 +46,9 @@ files:
|
|
46
46
|
- lib/ppcurses/actions/GetEnumeratedStringAction.rb
|
47
47
|
- test/menuInMenu.rb
|
48
48
|
- test/displayMenu.rb
|
49
|
+
- test/compositeMenu.rb
|
49
50
|
- LICENCE.txt
|
50
|
-
- README.
|
51
|
+
- README.rdoc
|
51
52
|
homepage: https://github.com/mcormier/ppcurses
|
52
53
|
licenses: []
|
53
54
|
|