ppcurses 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ppcurses/Screen.rb +1 -1
- data/lib/ppcurses/actions/BaseAction.rb +18 -17
- data/lib/ppcurses/actions/GetBooleanAction.rb +14 -13
- data/lib/ppcurses/actions/GetDataAction.rb +20 -20
- data/lib/ppcurses/actions/GetEnumeratedStringAction.rb +18 -16
- data/lib/ppcurses/actions/GetIntegerAction.rb +5 -4
- data/lib/ppcurses/actions/InsertSQLDataAction.rb +30 -23
- data/lib/ppcurses/actions/NulAction.rb +2 -2
- data/lib/ppcurses/actions/PromptAction.rb +9 -8
- data/lib/ppcurses/actions/ShowMenuAction.rb +2 -2
- data/lib/ppcurses/menu/BaseMenu.rb +5 -5
- data/lib/ppcurses/menu/CompositeMenu.rb +5 -5
- data/lib/ppcurses/menu/Menu.rb +66 -66
- data/lib/ppcurses/menu/RadioMenu.rb +22 -20
- data/test/compositeMenu.rb +8 -8
- data/test/displayMenu.rb +6 -6
- data/test/getBooleanAction.rb +4 -4
- data/test/getDataAction.rb +6 -6
- data/test/getEnumStringAction.rb +4 -5
- data/test/getIntegerAction.rb +4 -4
- data/test/getStringAction.rb +4 -4
- data/test/insertSQLAction.rb +10 -8
- data/test/menuInMenu.rb +9 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e13a98dcd617b53a1631b1383fdfa318fb879cc
|
4
|
+
data.tar.gz: 5766d143ec924f6bfc4acc65ce4cf2f0b47ed489
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe412137a6a950c0d8743952a01699ce678bdf3ae85cb3876adb0df532c94b9d8835c5fda19ff24adc0d713d75376d298d87b812424e462857f3fe86e6f9f188
|
7
|
+
data.tar.gz: e52e99c64f9cb9b31910c02fdd0d35054fcbdd2830c93c6a1f642036028b19363dc79cc6e802f6181f495b4d287dc27cb8ca4a111a7ad37c045f9cf94d94ac44
|
data/lib/ppcurses/Screen.rb
CHANGED
@@ -1,39 +1,40 @@
|
|
1
|
-
require
|
1
|
+
require 'curses'
|
2
2
|
|
3
|
+
#noinspection RubyResolve
|
3
4
|
module PPCurses
|
4
5
|
class BaseAction
|
5
6
|
|
6
|
-
def
|
7
|
+
def set_window(win)
|
7
8
|
@win = win
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
-
|
11
|
+
def x_padding
|
12
|
+
self.win_padding()
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
-
|
15
|
+
def win_padding
|
16
|
+
2
|
16
17
|
end
|
17
18
|
|
18
|
-
def
|
19
|
-
Curses.cols -
|
19
|
+
def win_width
|
20
|
+
Curses.cols - win_padding()
|
20
21
|
end
|
21
22
|
|
22
|
-
def
|
23
|
-
Curses.lines -
|
23
|
+
def win_height
|
24
|
+
Curses.lines - win_padding()
|
24
25
|
end
|
25
26
|
|
26
|
-
def
|
27
|
-
@win = Window.new(
|
28
|
-
|
27
|
+
def create_window
|
28
|
+
@win = Window.new( win_height(), win_width(),
|
29
|
+
win_padding()/2, win_padding()/2)
|
29
30
|
@win.clear
|
30
|
-
@win.box(
|
31
|
-
@win.setpos(@win.cury()+1,
|
31
|
+
@win.box('|', '-')
|
32
|
+
@win.setpos(@win.cury()+1, x_padding() )
|
32
33
|
end
|
33
34
|
|
34
|
-
def show
|
35
|
+
def show
|
35
36
|
if @win.nil?
|
36
|
-
self.
|
37
|
+
self.create_window()
|
37
38
|
end
|
38
39
|
|
39
40
|
@win.refresh
|
@@ -1,29 +1,30 @@
|
|
1
1
|
require_relative 'PromptAction.rb'
|
2
2
|
|
3
|
+
#noinspection RubyResolve
|
3
4
|
module PPCurses
|
4
5
|
|
5
6
|
class GetBooleanAction < PromptAction
|
6
7
|
|
7
8
|
def initialize(prompt)
|
8
9
|
super(prompt)
|
9
|
-
@state = false
|
10
|
+
@state = false
|
10
11
|
end
|
11
12
|
|
12
|
-
def
|
13
|
+
def print_prompt
|
13
14
|
super()
|
14
|
-
@win.addstr(
|
15
|
-
if
|
16
|
-
@win.addstr(
|
17
|
-
if
|
18
|
-
@win.addstr(
|
15
|
+
@win.addstr('No [')
|
16
|
+
if @state then @win.addstr(' ') else @win.addstr('X') end
|
17
|
+
@win.addstr('] Yes [')
|
18
|
+
if @state then @win.addstr('X') else @win.addstr(' ') end
|
19
|
+
@win.addstr(']')
|
19
20
|
end
|
20
21
|
|
21
22
|
|
22
|
-
def execute
|
23
|
-
|
23
|
+
def execute
|
24
|
+
print_prompt()
|
24
25
|
# Enables reading arrow keys in getch
|
25
26
|
@win.keypad(true)
|
26
|
-
while
|
27
|
+
while 1
|
27
28
|
noecho
|
28
29
|
c = @win.getch
|
29
30
|
|
@@ -32,14 +33,14 @@ module PPCurses
|
|
32
33
|
if c == 10 then break end
|
33
34
|
|
34
35
|
echo
|
35
|
-
|
36
|
+
print_prompt()
|
36
37
|
end
|
37
38
|
echo
|
38
39
|
end
|
39
40
|
|
40
41
|
def data
|
41
|
-
if @state
|
42
|
-
|
42
|
+
if @state then return '1' end
|
43
|
+
'0'
|
43
44
|
end
|
44
45
|
|
45
46
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require_relative 'BaseAction.rb'
|
2
2
|
|
3
|
+
#noinspection RubyResolve
|
3
4
|
module PPCurses
|
4
5
|
|
5
|
-
|
6
6
|
# An action that contains an array of prompt actions.
|
7
7
|
# It can be used to group together multiple prompt actions.
|
8
8
|
#
|
@@ -12,51 +12,51 @@ class GetDataAction < BaseAction
|
|
12
12
|
@actions = actions
|
13
13
|
unless @actions.nil?
|
14
14
|
@actions.each do |action|
|
15
|
-
action.
|
15
|
+
action.set_parent_action(self)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def before_actions
|
21
21
|
# Stub for classes that extend
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def after_actions
|
25
25
|
# Stub for classes that extend
|
26
26
|
end
|
27
27
|
|
28
28
|
|
29
|
-
def data
|
29
|
+
def data
|
30
30
|
values = []
|
31
31
|
@actions.each do |action|
|
32
32
|
values.push(action.data())
|
33
33
|
end
|
34
|
-
|
34
|
+
values
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
37
|
+
def create_window
|
38
38
|
super()
|
39
39
|
# Assign window to actions
|
40
40
|
unless @actions.nil?
|
41
41
|
@actions.each do |action|
|
42
|
-
action.
|
42
|
+
action.set_window(@win)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def execute
|
48
|
-
|
47
|
+
def execute
|
48
|
+
create_window()
|
49
49
|
echo
|
50
50
|
|
51
|
-
@win.setpos(@win.cury,
|
51
|
+
@win.setpos(@win.cury,x_padding())
|
52
52
|
|
53
|
-
self.
|
53
|
+
self.before_actions()
|
54
54
|
|
55
55
|
@actions.each do |action|
|
56
56
|
action.execute
|
57
57
|
end
|
58
58
|
|
59
|
-
self.
|
59
|
+
self.after_actions()
|
60
60
|
|
61
61
|
noecho
|
62
62
|
@win.clear
|
@@ -64,23 +64,23 @@ class GetDataAction < BaseAction
|
|
64
64
|
@win.close
|
65
65
|
end
|
66
66
|
|
67
|
-
def
|
68
|
-
@win.setpos(@win.cury(),
|
67
|
+
def print_line(string)
|
68
|
+
@win.setpos(@win.cury(), win_padding())
|
69
69
|
@win.addstr(string)
|
70
|
-
@win.setpos(@win.cury() + 1,
|
70
|
+
@win.setpos(@win.cury() + 1, win_padding())
|
71
71
|
end
|
72
72
|
|
73
|
-
def
|
73
|
+
def print_success_line(string)
|
74
74
|
init_pair(1, COLOR_GREEN, COLOR_BLACK)
|
75
75
|
@win.attron(color_pair(1))
|
76
|
-
self.
|
76
|
+
self.print_line(string)
|
77
77
|
@win.attroff(color_pair(1))
|
78
78
|
end
|
79
79
|
|
80
|
-
def
|
80
|
+
def print_error_line(string)
|
81
81
|
init_pair(1, COLOR_RED, COLOR_BLACK)
|
82
82
|
@win.attron(color_pair(1))
|
83
|
-
self.
|
83
|
+
self.print_line(string)
|
84
84
|
@win.attroff(color_pair(1))
|
85
85
|
end
|
86
86
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'BaseAction.rb'
|
2
2
|
|
3
|
+
#noinspection RubyResolve
|
3
4
|
module PPCurses
|
4
5
|
|
5
6
|
class GetEnumeratedStringAction < PromptAction
|
@@ -10,52 +11,53 @@ module PPCurses
|
|
10
11
|
super(prompt)
|
11
12
|
|
12
13
|
# verify enumeration is an array
|
13
|
-
|
14
|
+
unless enumeration.respond_to?('each_with_index') then
|
14
15
|
raise
|
15
16
|
end
|
17
|
+
|
16
18
|
@options = enumeration
|
17
|
-
@
|
19
|
+
@current_option = 0
|
18
20
|
end
|
19
21
|
|
20
|
-
def
|
22
|
+
def print_prompt
|
21
23
|
super()
|
22
24
|
@options.each_with_index do |option, index|
|
23
25
|
@win.addstr(option)
|
24
|
-
if
|
25
|
-
@win.addstr(
|
26
|
+
if index == @current_option then
|
27
|
+
@win.addstr(' [X] ')
|
26
28
|
else
|
27
|
-
@win.addstr(
|
29
|
+
@win.addstr(' [ ] ')
|
28
30
|
end
|
29
31
|
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
|
-
def execute
|
34
|
-
|
35
|
+
def execute
|
36
|
+
print_prompt()
|
35
37
|
# Enables reading arrow keys in getch
|
36
38
|
@win.keypad(true)
|
37
|
-
while
|
39
|
+
while 1
|
38
40
|
noecho
|
39
41
|
c = @win.getch
|
40
42
|
|
41
|
-
if c == KEY_LEFT then @
|
42
|
-
if c == KEY_RIGHT then @
|
43
|
+
if c == KEY_LEFT then @current_option = @current_option-1 end
|
44
|
+
if c == KEY_RIGHT then @current_option= @current_option+1 end
|
43
45
|
if c == 10 then break end
|
44
46
|
|
45
|
-
if
|
46
|
-
if
|
47
|
+
if @current_option < 0 then @current_option = @options.length-1 end
|
48
|
+
if @current_option > @options.length-1 then @current_option = 0 end
|
47
49
|
|
48
50
|
echo
|
49
|
-
|
51
|
+
print_prompt()
|
50
52
|
end
|
51
53
|
echo
|
52
54
|
# Go to next line so that further actions to overwrite
|
53
55
|
# the choice
|
54
|
-
@win.setpos(@win.cury() + 1,
|
56
|
+
@win.setpos(@win.cury() + 1, x_padding())
|
55
57
|
end
|
56
58
|
|
57
59
|
def data
|
58
|
-
@options[@
|
60
|
+
@options[@current_option]
|
59
61
|
end
|
60
62
|
|
61
63
|
end
|
@@ -1,16 +1,17 @@
|
|
1
1
|
require_relative 'PromptAction.rb'
|
2
2
|
|
3
|
+
#noinspection RubyResolve
|
3
4
|
module PPCurses
|
4
5
|
|
5
6
|
class GetIntegerAction < PromptAction
|
6
7
|
|
7
|
-
def execute
|
8
|
+
def execute
|
8
9
|
y = @win.cury()
|
9
|
-
@data =
|
10
|
+
@data = ''
|
10
11
|
begin
|
11
|
-
@win.setpos(y,
|
12
|
+
@win.setpos(y,x_padding())
|
12
13
|
@win.clrtoeol()
|
13
|
-
@win.box(
|
14
|
+
@win.box('|', '-')
|
14
15
|
@win.addstr(@prompt)
|
15
16
|
echo
|
16
17
|
@data = @win.getstr()
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'BaseAction.rb'
|
2
2
|
|
3
|
+
#noinspection RubyResolve
|
3
4
|
module PPCurses
|
4
5
|
|
5
6
|
class InsertSQLDataAction < GetDataAction
|
@@ -10,51 +11,57 @@ module PPCurses
|
|
10
11
|
@db = db
|
11
12
|
end
|
12
13
|
|
13
|
-
def
|
14
|
+
def win_height
|
14
15
|
8 + @actions.length
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
18
|
+
def after_actions
|
19
|
+
prepared_sql = @sql
|
20
|
+
data_array = []
|
20
21
|
|
21
22
|
@actions.each do |action|
|
22
|
-
|
23
|
-
|
23
|
+
prepared_sql = prepared_sql.sub('?', action.data)
|
24
|
+
data_array.push(action.data)
|
24
25
|
end
|
25
26
|
|
26
|
-
self.
|
27
|
+
self.prompt_to_change_data(prepared_sql, data_array)
|
27
28
|
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
#
|
32
|
+
# returns true if data was inserted
|
33
|
+
#
|
34
|
+
def prompt_to_change_data(user_display_sql, data_array)
|
35
|
+
self.print_line(user_display_sql)
|
32
36
|
|
33
37
|
proceed = GetBooleanAction.new('Proceed? ')
|
34
|
-
proceed.
|
35
|
-
proceed.
|
38
|
+
proceed.set_parent_action(self)
|
39
|
+
proceed.set_window(@win)
|
36
40
|
proceed.execute()
|
37
41
|
|
38
|
-
|
39
|
-
|
42
|
+
did_insert = false
|
43
|
+
|
44
|
+
if proceed.data == '1'
|
45
|
+
self.print_line('')
|
40
46
|
begin
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
47
|
+
prep_statement = @db.prepare(@sql)
|
48
|
+
prep_statement.bind_params(data_array)
|
49
|
+
prep_statement.execute()
|
50
|
+
prep_statement.close()
|
51
|
+
did_insert = true
|
52
|
+
self.print_success_line('Execution successful')
|
46
53
|
rescue SQLite3::Exception => e
|
47
|
-
self.
|
48
|
-
self.
|
54
|
+
self.print_error_line('Exception occurred')
|
55
|
+
self.print_error_line(e.message)
|
49
56
|
ensure
|
50
|
-
self.
|
51
|
-
self.
|
57
|
+
self.print_line('')
|
58
|
+
self.print_line('< Press any key to continue > ')
|
52
59
|
@win.getch()
|
53
60
|
end
|
54
61
|
|
55
62
|
end
|
56
63
|
|
57
|
-
|
64
|
+
did_insert
|
58
65
|
end
|
59
66
|
|
60
67
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'BaseAction.rb'
|
2
2
|
|
3
|
+
#noinspection RubyResolve
|
3
4
|
module PPCurses
|
4
5
|
class PromptAction < BaseAction
|
5
6
|
|
@@ -7,25 +8,25 @@ module PPCurses
|
|
7
8
|
@prompt = prompt
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
+
def set_parent_action(action)
|
11
12
|
@parent = action
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
+
def x_padding
|
15
16
|
if @parent.nil?
|
16
|
-
|
17
|
+
self.win_padding()
|
17
18
|
else
|
18
|
-
|
19
|
+
@parent.win_padding()
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
|
-
def
|
23
|
-
@win.setpos(@win.cury(),
|
23
|
+
def print_prompt
|
24
|
+
@win.setpos(@win.cury(), x_padding())
|
24
25
|
@win.addstr(@prompt)
|
25
26
|
end
|
26
27
|
|
27
|
-
def execute
|
28
|
-
|
28
|
+
def execute
|
29
|
+
print_prompt()
|
29
30
|
echo
|
30
31
|
@data = @win.getstr()
|
31
32
|
noecho
|
@@ -1,18 +1,18 @@
|
|
1
1
|
class BaseMenu
|
2
2
|
|
3
|
-
def
|
4
|
-
@
|
3
|
+
def set_sub_menu(menu)
|
4
|
+
@sub_menu = menu
|
5
5
|
end
|
6
6
|
|
7
7
|
def hide()
|
8
8
|
@win.clear
|
9
9
|
@win.refresh
|
10
10
|
|
11
|
-
@
|
11
|
+
@sub_menu.hide() if @sub_menu
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def selected_menu_name()
|
15
|
+
@items[@selection]
|
16
16
|
end
|
17
17
|
|
18
18
|
end
|
@@ -7,21 +7,21 @@ module PPCurses
|
|
7
7
|
@menu1 = menu1
|
8
8
|
@menu2 = menu2
|
9
9
|
|
10
|
-
@menu1.
|
10
|
+
@menu1.set_sub_menu(menu2)
|
11
11
|
|
12
12
|
end
|
13
13
|
|
14
|
-
def show
|
14
|
+
def show
|
15
15
|
@menu1.show()
|
16
16
|
@menu2.show()
|
17
17
|
end
|
18
18
|
|
19
19
|
|
20
|
-
def
|
21
|
-
@menu1.
|
20
|
+
def menu_selection
|
21
|
+
@menu1.menu_selection()
|
22
22
|
end
|
23
23
|
|
24
|
-
def close
|
24
|
+
def close
|
25
25
|
@menu1.close()
|
26
26
|
@menu2.close()
|
27
27
|
end
|
data/lib/ppcurses/menu/Menu.rb
CHANGED
@@ -2,115 +2,115 @@
|
|
2
2
|
# http://www.ruby-doc.org/stdlib-1.9.3/libdoc/curses/rdoc/Curses.html
|
3
3
|
|
4
4
|
require_relative 'BaseMenu.rb'
|
5
|
-
require
|
5
|
+
require 'curses'
|
6
6
|
|
7
7
|
module PPCurses
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
8
|
+
#noinspection RubyResolve
|
9
|
+
class Menu < BaseMenu
|
10
|
+
|
11
|
+
def initialize( menu_items, action_items )
|
12
|
+
@items = Array.new
|
13
|
+
@actions = Array.new
|
14
|
+
@selection = 0
|
15
|
+
|
16
|
+
max_menu_width = 0
|
17
|
+
|
18
|
+
menu_items.each do |item|
|
19
|
+
@items.push item
|
20
|
+
if item.length > max_menu_width then max_menu_width = item.length end
|
21
|
+
end
|
22
|
+
|
23
|
+
unless action_items.nil?
|
24
|
+
action_items.each do |item|
|
25
|
+
@actions.push item
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
w_height = @items.length + 4
|
30
|
+
w_width = max_menu_width + 4
|
31
|
+
@win = Window.new(w_height,w_width,(lines-w_height) / 2, (cols-w_width)/2)
|
32
|
+
|
33
|
+
@win.timeout=-1
|
34
|
+
# Enables reading arrow keys in getch
|
35
|
+
@win.keypad(true)
|
36
36
|
end
|
37
37
|
|
38
|
-
def show
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
50
|
|
51
|
-
|
51
|
+
@win.refresh
|
52
52
|
|
53
|
-
|
53
|
+
@sub_menu.show() if @sub_menu
|
54
54
|
end
|
55
55
|
|
56
|
-
def
|
57
|
-
|
56
|
+
def set_global_action(action)
|
57
|
+
@global_action = action
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
60
|
+
def menu_selection
|
61
61
|
|
62
|
-
|
63
|
-
|
62
|
+
while 1
|
63
|
+
c = @win.getch
|
64
64
|
|
65
|
-
|
65
|
+
not_processed = !self.handle_menu_selection(c)
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
if c == 27 # ESCAPE
|
68
|
+
self.hide()
|
69
|
+
break
|
70
|
+
end
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
if not_processed then
|
73
|
+
@sub_menu.handle_menu_selection(c) if @sub_menu
|
74
|
+
end
|
75
75
|
|
76
|
-
|
76
|
+
end
|
77
77
|
|
78
78
|
end
|
79
79
|
|
80
|
-
def
|
80
|
+
def handle_menu_selection(c)
|
81
81
|
n_choices = @items.length
|
82
82
|
|
83
|
-
if c == KEY_UP
|
83
|
+
if c == KEY_UP
|
84
84
|
if @selection == 0 then @selection = n_choices-1 else @selection -= 1 end
|
85
85
|
self.show()
|
86
86
|
return true
|
87
87
|
end
|
88
88
|
|
89
|
-
if c == KEY_DOWN
|
89
|
+
if c == KEY_DOWN
|
90
90
|
if @selection == n_choices-1 then @selection = 0 else @selection += 1 end
|
91
91
|
self.show()
|
92
92
|
return true
|
93
93
|
end
|
94
94
|
|
95
|
-
if c == 10
|
95
|
+
if c == 10 # ENTER
|
96
96
|
|
97
|
-
unless @
|
98
|
-
|
97
|
+
unless @global_action.nil?
|
98
|
+
@global_action.execute()
|
99
99
|
end
|
100
100
|
|
101
101
|
unless @actions.nil? or @actions[@selection].nil?
|
102
|
-
|
102
|
+
@actions[@selection].execute()
|
103
103
|
end
|
104
104
|
|
105
105
|
self.show()
|
106
106
|
return true
|
107
107
|
end
|
108
108
|
|
109
|
-
|
109
|
+
false
|
110
110
|
end
|
111
111
|
|
112
112
|
|
113
|
-
def close
|
113
|
+
def close
|
114
114
|
@win.close()
|
115
115
|
end
|
116
116
|
|
@@ -2,38 +2,40 @@
|
|
2
2
|
require_relative 'BaseMenu.rb'
|
3
3
|
|
4
4
|
module PPCurses
|
5
|
+
#noinspection RubyResolve
|
5
6
|
class RadioMenu < BaseMenu
|
6
7
|
|
7
|
-
def initialize(
|
8
|
+
def initialize( menu_items, action_items )
|
8
9
|
@items = Array.new
|
10
|
+
@actions = Array.new
|
9
11
|
|
10
|
-
@
|
12
|
+
@menu_length = 0
|
11
13
|
|
12
|
-
|
14
|
+
menu_items.each do |item|
|
13
15
|
@items.push item
|
14
|
-
@
|
16
|
+
@menu_length += item.length + 5
|
15
17
|
end
|
16
18
|
|
17
19
|
@selection = 0
|
18
20
|
|
19
|
-
unless
|
20
|
-
|
21
|
-
|
21
|
+
unless action_items.nil?
|
22
|
+
|
23
|
+
action_items.each do |item|
|
22
24
|
@actions.push item
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
|
28
|
+
w_width = @menu_length + 4
|
27
29
|
|
28
|
-
@win = Window.new(3,
|
30
|
+
@win = Window.new(3, w_width ,0, (cols - w_width) / 2)
|
29
31
|
|
30
32
|
@win.timeout=-1
|
31
33
|
# Enables reading arrow keys in getch
|
32
34
|
@win.keypad(true)
|
33
35
|
end
|
34
36
|
|
35
|
-
def show
|
36
|
-
@win.box(
|
37
|
+
def show
|
38
|
+
@win.box('|', '-')
|
37
39
|
y = 1
|
38
40
|
x = 2
|
39
41
|
|
@@ -41,7 +43,7 @@ module PPCurses
|
|
41
43
|
|
42
44
|
for i in 0...@items.length
|
43
45
|
@win.addstr( @items[i] )
|
44
|
-
if @selection == i then @win.addstr(
|
46
|
+
if @selection == i then @win.addstr(' [*] ') else @win.addstr(' [ ] ') end
|
45
47
|
end
|
46
48
|
|
47
49
|
@win.refresh
|
@@ -49,14 +51,14 @@ module PPCurses
|
|
49
51
|
end
|
50
52
|
|
51
53
|
|
52
|
-
def
|
54
|
+
def menu_selection
|
53
55
|
|
54
|
-
while
|
56
|
+
while 1
|
55
57
|
c = @win.getch
|
56
58
|
|
57
|
-
|
59
|
+
self.handle_menu_selection(c)
|
58
60
|
|
59
|
-
if c == 27
|
61
|
+
if c == 27 # ESCAPE
|
60
62
|
@win.clear
|
61
63
|
@win.refresh
|
62
64
|
break
|
@@ -67,15 +69,15 @@ module PPCurses
|
|
67
69
|
end
|
68
70
|
|
69
71
|
|
70
|
-
def
|
72
|
+
def handle_menu_selection(c)
|
71
73
|
n_choices = @items.length
|
72
74
|
|
73
|
-
if c == KEY_RIGHT
|
75
|
+
if c == KEY_RIGHT
|
74
76
|
if @selection < n_choices - 1 then @selection += 1 else @selection = 0 end
|
75
77
|
self.show()
|
76
78
|
end
|
77
79
|
|
78
|
-
if c == KEY_LEFT
|
80
|
+
if c == KEY_LEFT
|
79
81
|
if @selection > 0 then @selection -= 1 else @selection = n_choices-1 end
|
80
82
|
self.show()
|
81
83
|
end
|
@@ -90,7 +92,7 @@ module PPCurses
|
|
90
92
|
|
91
93
|
|
92
94
|
|
93
|
-
def close
|
95
|
+
def close
|
94
96
|
@win.close()
|
95
97
|
end
|
96
98
|
|
data/test/compositeMenu.rb
CHANGED
@@ -3,18 +3,18 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require_relative '../lib/ppcurses.rb'
|
5
5
|
|
6
|
-
def
|
7
|
-
|
8
|
-
|
6
|
+
def display_menu
|
7
|
+
center_menu = PPCurses::Menu.new( [ 'Press', '<ESCAPE>', 'to Quit'], nil )
|
8
|
+
radio_menu = PPCurses::RadioMenu.new( %w(Wow two menus!), nil )
|
9
9
|
|
10
|
-
|
10
|
+
main_menu = PPCurses::CompositeMenu.new(center_menu, radio_menu)
|
11
11
|
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
main_menu.show()
|
14
|
+
main_menu.menu_selection()
|
15
|
+
main_menu.close()
|
16
16
|
end
|
17
17
|
|
18
18
|
screen = PPCurses::Screen.new()
|
19
|
-
screen.run {
|
19
|
+
screen.run { display_menu() }
|
20
20
|
|
data/test/displayMenu.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require_relative '../lib/ppcurses.rb'
|
5
5
|
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
def display_menu
|
7
|
+
main_menu = PPCurses::Menu.new( [ 'Press', '<ESCAPE>', 'to Quit'], nil )
|
8
|
+
main_menu.show()
|
9
|
+
main_menu.menu_selection()
|
10
|
+
main_menu.close()
|
11
11
|
end
|
12
12
|
|
13
13
|
screen = PPCurses::Screen.new()
|
14
|
-
screen.run {
|
14
|
+
screen.run { display_menu() }
|
15
15
|
|
data/test/getBooleanAction.rb
CHANGED
@@ -3,14 +3,14 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require_relative '../lib/ppcurses.rb'
|
5
5
|
|
6
|
-
action = PPCurses::GetBooleanAction.new(
|
6
|
+
action = PPCurses::GetBooleanAction.new('Is the sky blue? ')
|
7
7
|
|
8
|
-
def
|
8
|
+
def do_boolean_action(action)
|
9
9
|
action.show()
|
10
10
|
action.execute()
|
11
11
|
end
|
12
12
|
|
13
13
|
screen = PPCurses::Screen.new()
|
14
|
-
screen.run {
|
14
|
+
screen.run { do_boolean_action(action) }
|
15
15
|
|
16
|
-
puts
|
16
|
+
puts 'Value input was: ' + action.data()
|
data/test/getDataAction.rb
CHANGED
@@ -3,17 +3,17 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require_relative '../lib/ppcurses.rb'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
integer_action = PPCurses::GetIntegerAction.new("Input Integer : ")
|
7
|
+
string_action = PPCurses::GetStringAction.new("Input your name: ")
|
8
8
|
|
9
|
-
action = PPCurses::GetDataAction.new( [
|
9
|
+
action = PPCurses::GetDataAction.new( [integer_action, string_action] )
|
10
10
|
|
11
|
-
def
|
11
|
+
def do_integer_action(action)
|
12
12
|
action.show()
|
13
13
|
action.execute()
|
14
14
|
end
|
15
15
|
|
16
16
|
screen = PPCurses::Screen.new()
|
17
|
-
screen.run {
|
17
|
+
screen.run { do_integer_action(action) }
|
18
18
|
|
19
|
-
puts
|
19
|
+
puts 'Value input was: ' + action.data().to_s()
|
data/test/getEnumStringAction.rb
CHANGED
@@ -3,15 +3,14 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require_relative '../lib/ppcurses.rb'
|
5
5
|
|
6
|
-
action = PPCurses::GetEnumeratedStringAction.new(
|
7
|
-
["CD", "Vinyl", "MP3"] );
|
6
|
+
action = PPCurses::GetEnumeratedStringAction.new('Media Type? ', %w(CD Vinyl MP3))
|
8
7
|
|
9
|
-
def
|
8
|
+
def do_action(action)
|
10
9
|
action.show()
|
11
10
|
action.execute()
|
12
11
|
end
|
13
12
|
|
14
13
|
screen = PPCurses::Screen.new()
|
15
|
-
screen.run {
|
14
|
+
screen.run { do_action(action) }
|
16
15
|
|
17
|
-
puts
|
16
|
+
puts 'Value input was: ' + action.data()
|
data/test/getIntegerAction.rb
CHANGED
@@ -3,14 +3,14 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require_relative '../lib/ppcurses.rb'
|
5
5
|
|
6
|
-
action = PPCurses::GetIntegerAction.new(
|
6
|
+
action = PPCurses::GetIntegerAction.new('Input Integer : ')
|
7
7
|
|
8
|
-
def
|
8
|
+
def do_integer_action(action)
|
9
9
|
action.show()
|
10
10
|
action.execute()
|
11
11
|
end
|
12
12
|
|
13
13
|
screen = PPCurses::Screen.new()
|
14
|
-
screen.run {
|
14
|
+
screen.run { do_integer_action(action) }
|
15
15
|
|
16
|
-
puts
|
16
|
+
puts 'Value input was: ' + action.data()
|
data/test/getStringAction.rb
CHANGED
@@ -3,14 +3,14 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require_relative '../lib/ppcurses.rb'
|
5
5
|
|
6
|
-
action = PPCurses::GetStringAction.new(
|
6
|
+
action = PPCurses::GetStringAction.new('Input your name: ')
|
7
7
|
|
8
|
-
def
|
8
|
+
def get_string_action(action)
|
9
9
|
action.show()
|
10
10
|
action.execute()
|
11
11
|
end
|
12
12
|
|
13
13
|
screen = PPCurses::Screen.new()
|
14
|
-
screen.run {
|
14
|
+
screen.run { get_string_action(action) }
|
15
15
|
|
16
|
-
puts
|
16
|
+
puts 'Value input was: ' + action.data()
|
data/test/insertSQLAction.rb
CHANGED
@@ -4,34 +4,36 @@ require 'rubygems'
|
|
4
4
|
require_relative '../lib/ppcurses.rb'
|
5
5
|
|
6
6
|
begin
|
7
|
+
#noinspection RubyResolve
|
7
8
|
require 'sqlite3'
|
8
9
|
rescue LoadError => e
|
9
10
|
abort 'Missing dependency! Run: gem install sqlite3'
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
string_action = PPCurses::GetStringAction.new('What is your name? ')
|
14
|
+
integer_action = PPCurses::GetIntegerAction.new('Input an integer? ')
|
14
15
|
|
15
|
-
def
|
16
|
+
def do_action(action)
|
16
17
|
action.show()
|
17
18
|
action.execute()
|
18
19
|
end
|
19
20
|
|
20
21
|
|
21
|
-
|
22
|
+
#noinspection RubyResolve
|
23
|
+
db = SQLite3::Database.open 'test.db'
|
22
24
|
db.execute <<-SQL
|
23
25
|
create table testTable (name varchar(30), val int);
|
24
26
|
SQL
|
25
27
|
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
+
sql_action = PPCurses::InsertSQLDataAction.new( [string_action, integer_action],
|
30
|
+
'Insert into testTable(name, val) values (?, ?)', db)
|
29
31
|
|
30
32
|
screen = PPCurses::Screen.new()
|
31
|
-
screen.run { doAction(
|
33
|
+
screen.run { doAction(sql_action) }
|
32
34
|
|
33
35
|
|
34
36
|
db.close
|
35
|
-
File.delete(
|
37
|
+
File.delete('test.db')
|
36
38
|
|
37
39
|
|
data/test/menuInMenu.rb
CHANGED
@@ -3,18 +3,18 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require_relative '../lib/ppcurses.rb'
|
5
5
|
|
6
|
-
def
|
7
|
-
|
8
|
-
|
6
|
+
def display_menu
|
7
|
+
main_menu = PPCurses::Menu.new( [ 'Press', '<ESCAPE>', 'to Quit'], nil )
|
8
|
+
inner_menu = PPCurses::Menu.new( %w(Wow another menu), nil )
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
menu_action = PPCurses::ShowMenuAction.new(inner_menu)
|
11
|
+
main_menu.set_global_action(menu_action)
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
main_menu.show()
|
14
|
+
main_menu.menu_selection()
|
15
|
+
main_menu.close()
|
16
16
|
end
|
17
17
|
|
18
18
|
screen = PPCurses::Screen.new()
|
19
|
-
screen.run {
|
19
|
+
screen.run { display_menu() }
|
20
20
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ppcurses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu Cormier
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-08 00:00:00 Z
|
13
13
|
dependencies: []
|
14
14
|
|
15
15
|
description: Curses abstraction
|