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 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
@@ -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
- class CompositeMenu
2
+ module PPCurses
3
3
 
4
- def initialize(menu1, menu2)
5
- @menu1 = menu1
6
- @menu2 = menu2
4
+ class CompositeMenu
7
5
 
8
- @menu1.setSubMenu(menu2)
6
+ def initialize(menu1, menu2)
7
+ @menu1 = menu1
8
+ @menu2 = menu2
9
9
 
10
- end
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
@@ -111,8 +111,8 @@ module PPCurses
111
111
 
112
112
 
113
113
  def close()
114
- @win.close()
115
- end
114
+ @win.close()
115
+ end
116
116
 
117
117
  end
118
118
 
@@ -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 "curses"
5
- require './ppcurses/BaseMenu.rb'
6
- include Curses
2
+ require 'ppcurses/menu/BaseMenu.rb'
7
3
 
8
- class RadioMenu < BaseMenu
4
+ module PPCurses
5
+ class RadioMenu < BaseMenu
9
6
 
10
- def initialize( menuItems, actionItems )
11
- @items = Array.new
7
+ def initialize( menuItems, actionItems )
8
+ @items = Array.new
12
9
 
13
- @menuLength = 0
10
+ @menuLength = 0
14
11
 
15
- menuItems.each do |item|
16
- @items.push item
17
- @menuLength += item.length + 5
18
- end
12
+ menuItems.each do |item|
13
+ @items.push item
14
+ @menuLength += item.length + 5
15
+ end
19
16
 
20
- @selection = 0
17
+ @selection = 0
21
18
 
22
- unless actionItems.nil?
23
- @actions = Array.new
24
- actionItems.each do |item|
25
- @actions.push item
26
- end
27
- end
28
-
29
- winWidth = @menuLength + 4
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
- @win.setpos(y, x)
28
+ @win = Window.new(3, winWidth ,0, (cols - winWidth) / 2)
44
29
 
45
- for i in 0...@items.length
46
- @win.addstr( @items[i] )
47
- if @selection == i then @win.addstr(" [*] ") else @win.addstr(" [ ] " ) end
30
+ @win.timeout=-1
31
+ # Enables reading arrow keys in getch
32
+ @win.keypad(true)
48
33
  end
49
34
 
50
- @win.refresh
35
+ def show()
36
+ @win.box("|", "-")
37
+ y = 1
38
+ x = 2
51
39
 
52
- end
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
- def getMenuSelection()
47
+ @win.refresh
56
48
 
57
- while(1)
58
- c = @win.getch
49
+ end
59
50
 
60
- processed = self.handleMenuSelection(c)
61
51
 
62
- if c == 27 then # ESCAPE
63
- @win.clear
64
- @win.refresh
65
- break
66
- end
52
+ def getMenuSelection()
67
53
 
68
- end
54
+ while(1)
55
+ c = @win.getch
69
56
 
70
- end
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
- def handleMenuSelection(c)
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
- if c == 10 then # ENTER
87
- unless @actions.nil?
88
- @actions[@selection].execute()
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
- end
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
@@ -1,7 +1,11 @@
1
1
 
2
2
  module PPCurses
3
3
  require 'ppcurses/Screen.rb'
4
+ # Menus
4
5
  require 'ppcurses/menu/Menu.rb'
6
+ require 'ppcurses/menu/CompositeMenu.rb'
7
+ require 'ppcurses/menu/RadioMenu.rb'
8
+ # Actions
5
9
  require 'ppcurses/actions/ShowMenuAction.rb'
6
10
  end
7
11
 
@@ -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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
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.md
51
+ - README.rdoc
51
52
  homepage: https://github.com/mcormier/ppcurses
52
53
  licenses: []
53
54
 
data/README.md DELETED
@@ -1,6 +0,0 @@
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
- # References #
6
- http://www.ruby-doc.org/stdlib-1.9.3/libdoc/curses/rdoc/Curses.html