ppcurses 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENCE.txt +20 -0
- data/README.md +1 -0
- data/lib/ppcurses/Screen.rb +28 -0
- data/lib/ppcurses/menu/BaseMenu.rb +19 -0
- data/lib/ppcurses/menu/Menu.rb +119 -0
- data/lib/ppcurses.rb +7 -0
- data/test/test.rb +15 -0
- metadata +71 -0
data/LICENCE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Matthieu Cormier
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
blah
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "curses"
|
2
|
+
include Curses
|
3
|
+
|
4
|
+
module PPCurses
|
5
|
+
class Screen
|
6
|
+
|
7
|
+
def run( )
|
8
|
+
begin
|
9
|
+
init_screen
|
10
|
+
Curses.raw
|
11
|
+
clear
|
12
|
+
curs_set(0) # Makes cursor invisible
|
13
|
+
noecho
|
14
|
+
cbreak
|
15
|
+
start_color
|
16
|
+
|
17
|
+
yield
|
18
|
+
|
19
|
+
rescue SystemExit, Interrupt
|
20
|
+
# Empty Catch block so ruby doesn't puke out
|
21
|
+
# a stack trace when CTRL-C is used
|
22
|
+
ensure
|
23
|
+
#close_screen
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# Curses reference:
|
2
|
+
# http://www.ruby-doc.org/stdlib-1.9.3/libdoc/curses/rdoc/Curses.html
|
3
|
+
|
4
|
+
require 'ppcurses/menu/BaseMenu.rb'
|
5
|
+
require "curses"
|
6
|
+
|
7
|
+
module PPCurses
|
8
|
+
class Menu < BaseMenu
|
9
|
+
|
10
|
+
def initialize( menuItems, actionItems )
|
11
|
+
@items = Array.new
|
12
|
+
|
13
|
+
@maxMenuWidth = 0
|
14
|
+
|
15
|
+
menuItems.each do |item|
|
16
|
+
@items.push item
|
17
|
+
if item.length > @maxMenuWidth then @maxMenuWidth = item.length end
|
18
|
+
end
|
19
|
+
|
20
|
+
@selection = 0
|
21
|
+
|
22
|
+
unless actionItems.nil?
|
23
|
+
@actions = Array.new
|
24
|
+
actionItems.each do |item|
|
25
|
+
@actions.push item
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
winHeight = @items.length + 4
|
30
|
+
winWidth = @maxMenuWidth + 4
|
31
|
+
@win = Window.new(winHeight,winWidth,(lines-winHeight) / 2, (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 = 2
|
41
|
+
x = 2
|
42
|
+
|
43
|
+
for i in 0...@items.length
|
44
|
+
@win.setpos(y, x)
|
45
|
+
if @selection == i then @win.attron(A_REVERSE) end
|
46
|
+
@win.addstr(@items[i])
|
47
|
+
if @selection == i then @win.attroff(A_REVERSE) end
|
48
|
+
y += 1
|
49
|
+
end
|
50
|
+
|
51
|
+
@win.refresh
|
52
|
+
|
53
|
+
@subMenu.show() if @subMenu
|
54
|
+
end
|
55
|
+
|
56
|
+
def setGlobalAction(action)
|
57
|
+
@gAction = action
|
58
|
+
end
|
59
|
+
|
60
|
+
def getMenuSelection()
|
61
|
+
|
62
|
+
while(1)
|
63
|
+
c = @win.getch
|
64
|
+
|
65
|
+
processed = self.handleMenuSelection(c)
|
66
|
+
|
67
|
+
if c == 27 then # ESCAPE
|
68
|
+
self.hide()
|
69
|
+
break
|
70
|
+
end
|
71
|
+
|
72
|
+
if processed == false then
|
73
|
+
@subMenu.handleMenuSelection(c) if @subMenu
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
def handleMenuSelection(c)
|
81
|
+
n_choices = @items.length
|
82
|
+
|
83
|
+
if c == KEY_UP then
|
84
|
+
if @selection == 0 then @selection = n_choices-1 else @selection -= 1 end
|
85
|
+
self.show()
|
86
|
+
return true
|
87
|
+
end
|
88
|
+
|
89
|
+
if c == KEY_DOWN then
|
90
|
+
if @selection == n_choices-1 then @selection = 0 else @selection += 1 end
|
91
|
+
self.show()
|
92
|
+
return true
|
93
|
+
end
|
94
|
+
|
95
|
+
if c == 10 then # ENTER
|
96
|
+
|
97
|
+
unless @gAction.nil?
|
98
|
+
@gAction.execute()
|
99
|
+
end
|
100
|
+
|
101
|
+
unless @actions.nil? or @actions[@selection].nil?
|
102
|
+
@actions[@selection].execute()
|
103
|
+
end
|
104
|
+
|
105
|
+
self.show()
|
106
|
+
return true
|
107
|
+
end
|
108
|
+
|
109
|
+
return false
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
def close()
|
114
|
+
@win.close()
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
data/lib/ppcurses.rb
ADDED
data/test/test.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'ppcurses'
|
5
|
+
|
6
|
+
def displayMenu()
|
7
|
+
mainMenu = PPCurses::Menu.new( [ "1RM", "3RM", "5RM" ], nil )
|
8
|
+
mainMenu.show()
|
9
|
+
mainMenu.getMenuSelection()
|
10
|
+
mainMenu.close()
|
11
|
+
end
|
12
|
+
|
13
|
+
screen = PPCurses::Screen.new()
|
14
|
+
screen.run { displayMenu() }
|
15
|
+
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ppcurses
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Matthieu Cormier
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-04-27 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Curses abstraction
|
22
|
+
email: mcormier@preenandprune.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/ppcurses.rb
|
31
|
+
- lib/ppcurses/menu/BaseMenu.rb
|
32
|
+
- lib/ppcurses/menu/Menu.rb
|
33
|
+
- lib/ppcurses/Screen.rb
|
34
|
+
- test/test.rb
|
35
|
+
- LICENCE.txt
|
36
|
+
- README.md
|
37
|
+
homepage: https://github.com/mcormier/ppcurses
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.24
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Convenience classes when using curses
|
70
|
+
test_files: []
|
71
|
+
|