ppcurses 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/lib/ppcurses.rb +1 -6
- data/lib/ppcurses/form/button.rb +9 -0
- data/lib/ppcurses/form/combo_box.rb +4 -0
- data/lib/ppcurses/form/date_picker.rb +8 -1
- data/lib/ppcurses/form/form.rb +8 -1
- data/lib/ppcurses/form/input_element.rb +87 -10
- data/lib/ppcurses/form/radio_button_group.rb +8 -3
- data/lib/ppcurses/menu/date_menu.rb +4 -0
- data/lib/ppcurses/menu_bar.rb +5 -0
- data/lib/ppcurses/table_view.rb +88 -2
- data/test/form/decimal_element.rb +21 -0
- data/test/form/simple_form.rb +1 -1
- data/test/form/time_element.rb +20 -0
- data/test/raw_screen/display_colours.rb +2 -2
- data/test/table_view/testMultiColView.rb +23 -0
- data/test/table_view/testTableView.rb +4 -0
- metadata +5 -16
- data/lib/ppcurses/actions/GetBooleanAction.rb +0 -48
- data/lib/ppcurses/actions/GetDataAction.rb +0 -92
- data/lib/ppcurses/actions/GetEnumeratedStringAction.rb +0 -65
- data/lib/ppcurses/actions/GetIntegerAction.rb +0 -24
- data/lib/ppcurses/actions/GetStringAction.rb +0 -9
- data/lib/ppcurses/actions/InsertSQLDataAction.rb +0 -69
- data/lib/ppcurses/actions/PromptAction.rb +0 -41
- data/test/form/menu_opens_form.rb +0 -15
- data/test/getBooleanAction.rb +0 -16
- data/test/getDataAction.rb +0 -19
- data/test/getEnumStringAction.rb +0 -16
- data/test/getIntegerAction.rb +0 -16
- data/test/getStringAction.rb +0 -16
- data/test/insertSQLAction.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1f34fa50d5ec820ad8ccb333d57e40a9b14ea89
|
4
|
+
data.tar.gz: 4f809ba8124e6f5bca7f9566a9a2d2f71750f4aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ce5e450738025b54e9455e0a585d0e6537e7518007d92500045acce594f1e3f9d98f3bace1c97aa69ca72a2a9630bbe9f6afb0a7bcf484e164f2ad2e246d869
|
7
|
+
data.tar.gz: a47a2528952accdd03954a9fc846fd9fa4120a5772c95b0d097a60b9e2e45e1f0992dd5cc7019ae2e920f0502fb41339cc048f20bcfc1dd7bae7df03462eaf15
|
data/lib/ppcurses.rb
CHANGED
@@ -49,13 +49,8 @@ module PPCurses
|
|
49
49
|
require_relative 'ppcurses/menu/date_menu.rb'
|
50
50
|
# Actions -------------------------------------------------------------------------------------------------------------
|
51
51
|
require_relative 'ppcurses/actions/ShowMenuAction.rb'
|
52
|
-
require_relative 'ppcurses/actions/GetStringAction.rb'
|
53
|
-
require_relative 'ppcurses/actions/GetBooleanAction.rb'
|
54
|
-
require_relative 'ppcurses/actions/GetIntegerAction.rb'
|
55
|
-
require_relative 'ppcurses/actions/GetEnumeratedStringAction.rb'
|
56
|
-
require_relative 'ppcurses/actions/GetDataAction.rb'
|
57
52
|
require_relative 'ppcurses/actions/NulAction.rb'
|
58
|
-
|
53
|
+
|
59
54
|
# Forms ---------------------------------------------------------------------------------------------------------------
|
60
55
|
require_relative 'ppcurses/form/form.rb'
|
61
56
|
require_relative 'ppcurses/form/button.rb'
|
data/lib/ppcurses/form/button.rb
CHANGED
@@ -13,7 +13,7 @@ module PPCurses
|
|
13
13
|
|
14
14
|
# Does the element have focus in the form?
|
15
15
|
attr_accessor :selected
|
16
|
-
|
16
|
+
attr_accessor :date
|
17
17
|
|
18
18
|
def initialize(label, initial_date = Date.today)
|
19
19
|
@label = label
|
@@ -73,6 +73,13 @@ module PPCurses
|
|
73
73
|
|
74
74
|
end
|
75
75
|
|
76
|
+
def clear
|
77
|
+
@date = Date.today
|
78
|
+
if @date_menu.nil? == false
|
79
|
+
@date_menu.day = @date
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
76
83
|
#------------------------------------------------
|
77
84
|
protected
|
78
85
|
def display_string
|
data/lib/ppcurses/form/form.rb
CHANGED
@@ -26,7 +26,7 @@ module PPCurses
|
|
26
26
|
# - def selected=
|
27
27
|
#
|
28
28
|
def add (element)
|
29
|
-
PPCurses.implements_protocol( element, %w(show height set_curs_pos key_down selected=))
|
29
|
+
PPCurses.implements_protocol( element, %w(show height set_curs_pos key_down selected= clear))
|
30
30
|
@elements.push(element)
|
31
31
|
|
32
32
|
if @selected_element.nil?
|
@@ -80,6 +80,13 @@ module PPCurses
|
|
80
80
|
@selected_element.set_curs_pos(screen) unless @selected_element.nil?
|
81
81
|
end
|
82
82
|
|
83
|
+
# clears or resets all values of elements in the form
|
84
|
+
def clear
|
85
|
+
for i in 0..@elements.length - 1
|
86
|
+
@elements[i].clear
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
83
90
|
# --------------------------------------------------------------------------------
|
84
91
|
protected
|
85
92
|
|
@@ -23,19 +23,35 @@ module PPCurses
|
|
23
23
|
@label = label
|
24
24
|
@size = size
|
25
25
|
@selected = false
|
26
|
-
@value = ''
|
27
|
-
@cursor_location = 0
|
28
26
|
@filter = nil
|
27
|
+
self.clear
|
29
28
|
end
|
30
29
|
|
31
30
|
# Creates an InputElement that only allows integer input
|
32
31
|
#
|
33
32
|
def InputElement.new_integer_only( label, size)
|
34
33
|
i_only = PPCurses::InputElement.new(label, size)
|
35
|
-
i_only.filter =PPCurses::
|
34
|
+
i_only.filter = PPCurses::IntegerFilter.new
|
36
35
|
i_only
|
37
36
|
end
|
38
37
|
|
38
|
+
# Creates an InputElement that only allows a number
|
39
|
+
# but allows a decimal point. I.E. 10.2
|
40
|
+
#
|
41
|
+
def InputElement.new_decimal_only( label, size)
|
42
|
+
i_only = PPCurses::InputElement.new(label, size)
|
43
|
+
i_only.filter = PPCurses::DecimalFilter.new
|
44
|
+
i_only
|
45
|
+
end
|
46
|
+
|
47
|
+
# Creates an InputElement that only allows time data
|
48
|
+
# E.G. 20:10.20 == 20 hours, 10 minutes and 20 seconds
|
49
|
+
#
|
50
|
+
def InputElement.new_time_only( label, size)
|
51
|
+
i_only = PPCurses::InputElement.new(label, size)
|
52
|
+
i_only.filter = PPCurses::TimeFilter.new
|
53
|
+
i_only
|
54
|
+
end
|
39
55
|
|
40
56
|
def show(screen)
|
41
57
|
print_label( screen )
|
@@ -77,10 +93,19 @@ module PPCurses
|
|
77
93
|
return
|
78
94
|
end
|
79
95
|
|
80
|
-
|
96
|
+
#
|
97
|
+
# Get a temporary version of the current value
|
98
|
+
# with the new character added so that we can
|
99
|
+
# test it against the filter.
|
100
|
+
temp_val = value_with(key)
|
101
|
+
|
102
|
+
unless passes_filter(temp_val)
|
81
103
|
return
|
82
104
|
end
|
83
105
|
|
106
|
+
#
|
107
|
+
# Actually add the new character if the filter passes
|
108
|
+
#
|
84
109
|
add_character(key)
|
85
110
|
|
86
111
|
end
|
@@ -107,6 +132,12 @@ module PPCurses
|
|
107
132
|
1
|
108
133
|
end
|
109
134
|
|
135
|
+
def clear
|
136
|
+
@value = ''
|
137
|
+
@cursor_location = 0
|
138
|
+
end
|
139
|
+
|
140
|
+
|
110
141
|
# --------------------------------------------------------------------------------
|
111
142
|
protected
|
112
143
|
|
@@ -160,24 +191,53 @@ module PPCurses
|
|
160
191
|
end
|
161
192
|
|
162
193
|
|
163
|
-
|
194
|
+
|
195
|
+
#
|
196
|
+
# Returns what the value of the input element would be, if
|
197
|
+
# the given character was added. Does not modify the internal
|
198
|
+
# state.
|
199
|
+
#
|
200
|
+
def value_with (char)
|
201
|
+
temp_val = @value
|
202
|
+
|
164
203
|
if @cursor_location == @value.length
|
165
|
-
@value
|
204
|
+
temp_val = @value + char
|
166
205
|
else
|
167
|
-
|
206
|
+
temp_val = @value.slice(0..@cursor_location-1) + char + @value.slice(@cursor_location..@value.length-1)
|
168
207
|
end
|
208
|
+
|
209
|
+
temp_val
|
210
|
+
end
|
211
|
+
|
169
212
|
|
213
|
+
def add_character ( char )
|
214
|
+
@value = value_with(char)
|
170
215
|
@cursor_location += 1
|
171
216
|
end
|
172
217
|
|
173
218
|
end
|
174
219
|
|
220
|
+
# ============================================================
|
221
|
+
# ------------ Filters
|
222
|
+
# ============================================================
|
175
223
|
|
224
|
+
class IntegerFilter
|
176
225
|
|
177
|
-
|
226
|
+
def passes_filter( value )
|
227
|
+
if value =~ /^\d+$/
|
228
|
+
return true
|
229
|
+
end
|
178
230
|
|
179
|
-
|
180
|
-
|
231
|
+
false
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
|
237
|
+
class DecimalFilter
|
238
|
+
|
239
|
+
def passes_filter( value )
|
240
|
+
if value =~ /^\d*\.?\d*$/
|
181
241
|
return true
|
182
242
|
end
|
183
243
|
|
@@ -185,5 +245,22 @@ module PPCurses
|
|
185
245
|
end
|
186
246
|
|
187
247
|
end
|
248
|
+
|
249
|
+
# Used for hours minute second input.
|
250
|
+
# Valid input includes:
|
251
|
+
# 3:33.20 == 3 hours 33 minutes and 20 seconds
|
252
|
+
# 33.20 == 33 minutes and 20 seconds
|
253
|
+
# 33 == 33 minutes
|
254
|
+
# 0.20 == 20 seconds
|
255
|
+
class TimeFilter
|
256
|
+
|
257
|
+
def passes_filter( value )
|
258
|
+
if value =~ /^\d*\:?\d*\.?\d*$/
|
259
|
+
return true
|
260
|
+
end
|
188
261
|
|
262
|
+
false
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|
189
266
|
end
|
@@ -8,7 +8,7 @@ module PPCurses
|
|
8
8
|
class RadioButtonGroup < View
|
9
9
|
|
10
10
|
attr_accessor :selected
|
11
|
-
|
11
|
+
attr_accessor :current_option
|
12
12
|
|
13
13
|
#
|
14
14
|
# label : a label for the radio button group
|
@@ -27,9 +27,9 @@ module PPCurses
|
|
27
27
|
screen.attroff(Curses::A_REVERSE) if @selected
|
28
28
|
@options.each_with_index do |option, index|
|
29
29
|
if index == @current_option
|
30
|
-
screen.addstr(" #{option} #{RADIO_SELECTED}")
|
30
|
+
screen.addstr(" #{option} #{RADIO_SELECTED} ")
|
31
31
|
else
|
32
|
-
screen.addstr(" #{option} #{RADIO_NOT_SELECTED}")
|
32
|
+
screen.addstr(" #{option} #{RADIO_NOT_SELECTED} ")
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -50,6 +50,11 @@ module PPCurses
|
|
50
50
|
def height
|
51
51
|
1
|
52
52
|
end
|
53
|
+
|
54
|
+
def clear
|
55
|
+
@current_option = 0
|
56
|
+
end
|
57
|
+
|
53
58
|
|
54
59
|
end
|
55
60
|
|
data/lib/ppcurses/menu_bar.rb
CHANGED
@@ -8,6 +8,8 @@ module PPCurses
|
|
8
8
|
#
|
9
9
|
class MenuBar < Responder
|
10
10
|
|
11
|
+
attr_accessor :selected
|
12
|
+
|
11
13
|
def initialize
|
12
14
|
@menu_items = []
|
13
15
|
@selected = false
|
@@ -46,6 +48,9 @@ module PPCurses
|
|
46
48
|
@menu_items.push(menu_item)
|
47
49
|
end
|
48
50
|
|
51
|
+
def remove_menu_item(menu_item)
|
52
|
+
@menu_items.delete(menu_item)
|
53
|
+
end
|
49
54
|
|
50
55
|
def key_down( key )
|
51
56
|
|
data/lib/ppcurses/table_view.rb
CHANGED
@@ -22,6 +22,8 @@ class TableView < View
|
|
22
22
|
super
|
23
23
|
origin = Point.new( 2, 2 )
|
24
24
|
setFrameOrigin(origin)
|
25
|
+
|
26
|
+
@table_columns = []
|
25
27
|
end
|
26
28
|
|
27
29
|
|
@@ -43,6 +45,10 @@ class TableView < View
|
|
43
45
|
if x > width then width = x end
|
44
46
|
end
|
45
47
|
|
48
|
+
# Add an extra line for the column header
|
49
|
+
# and ====== divider
|
50
|
+
height += 2
|
51
|
+
|
46
52
|
sz = Size.new( width, height )
|
47
53
|
setFrameSize( sz )
|
48
54
|
|
@@ -53,10 +59,37 @@ class TableView < View
|
|
53
59
|
y = @frame.origin.y
|
54
60
|
x = @frame.origin.x
|
55
61
|
|
62
|
+
|
63
|
+
# display column header
|
64
|
+
screen.setpos(y,x)
|
65
|
+
@table_columns.each_with_index do |column,i|
|
66
|
+
screen.addstr(column.identifier.center(column.width))
|
67
|
+
if i < @table_columns.length - 1 then screen.addstr(' | ') end
|
68
|
+
end
|
69
|
+
|
70
|
+
y += 1
|
71
|
+
screen.setpos(y,x)
|
72
|
+
# Display ================= divider
|
73
|
+
@table_columns.each_with_index do |column, i|
|
74
|
+
screen.addstr( ''.center(column.width, '=') )
|
75
|
+
if i < @table_columns.length - 1 then screen.addstr('===') end
|
76
|
+
end
|
77
|
+
|
78
|
+
y += 1
|
79
|
+
|
56
80
|
for i in 0..@data_source.number_of_rows_in_table(self)-1
|
57
81
|
screen.setpos(y,x)
|
58
82
|
screen.attron(Curses::A_REVERSE) if i == selected_row
|
59
|
-
|
83
|
+
|
84
|
+
|
85
|
+
@table_columns.each_with_index do |col,j|
|
86
|
+
col_str = @data_source.object_value_for(self, j, i)
|
87
|
+
display_string = col_str.ljust(col.width)
|
88
|
+
screen.addstr( display_string )
|
89
|
+
if j < @table_columns.length - 1 then screen.addstr(' | ') end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
60
93
|
screen.attroff(Curses::A_REVERSE) if i == selected_row
|
61
94
|
y += 1
|
62
95
|
end
|
@@ -92,9 +125,48 @@ class TableView < View
|
|
92
125
|
|
93
126
|
end
|
94
127
|
|
128
|
+
def number_of_columns
|
129
|
+
num_col = 0
|
130
|
+
|
131
|
+
while @data_source.object_value_for(self, num_col, 0) != nil do
|
132
|
+
num_col += 1
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
num_col
|
137
|
+
end
|
138
|
+
|
139
|
+
## Column Management
|
140
|
+
|
141
|
+
def add_table_column( col )
|
142
|
+
col.table_view = self
|
143
|
+
@table_columns.push(col)
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
# ==========================================================================================
|
149
|
+
#
|
150
|
+
# Based loosely on ...
|
151
|
+
# https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTableColumn_Class/index.html#//apple_ref/swift/cl/NSTableColumn
|
152
|
+
#
|
153
|
+
# The TableColumn class stores the display characteristics and identifier for a column
|
154
|
+
# in a TableView instance. A table column object determines the width of its column.
|
155
|
+
class TableColumn
|
156
|
+
|
157
|
+
attr_accessor :identifier
|
158
|
+
attr_accessor :width
|
159
|
+
attr_accessor :table_view
|
160
|
+
|
161
|
+
def initialize( identifier, width = 5 )
|
162
|
+
@identifier = identifier
|
163
|
+
@width = width
|
164
|
+
end
|
165
|
+
|
95
166
|
end
|
96
167
|
|
97
168
|
|
169
|
+
# ==========================================================================================
|
98
170
|
# Based on ...
|
99
171
|
#
|
100
172
|
# https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Protocols/NSTableDataSource_Protocol/index.html#//apple_ref/occ/intf/NSTableViewDataSource
|
@@ -114,11 +186,25 @@ class SingleColumnDataSource
|
|
114
186
|
# Called by the table view to return the data object associated with
|
115
187
|
# the specified row and column.
|
116
188
|
def object_value_for(aTableview, column, row_index)
|
189
|
+
if column > 0 then
|
190
|
+
return nil
|
191
|
+
end
|
192
|
+
|
117
193
|
@values[row_index]
|
118
194
|
end
|
119
195
|
end
|
120
196
|
|
121
|
-
|
197
|
+
# Values in the constructor is expected to be a two sided array
|
198
|
+
class MultipleColumnDataSource < SingleColumnDataSource
|
199
|
+
|
200
|
+
# Called by the table view to return the data object associated with
|
201
|
+
# the specified row and column.
|
202
|
+
def object_value_for(aTableview, column, row_index)
|
203
|
+
@values[row_index][column]
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
end
|
122
208
|
|
123
209
|
class TableViewDataSource
|
124
210
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require_relative '../../lib/ppcurses.rb'
|
5
|
+
|
6
|
+
|
7
|
+
@app = PPCurses::Application.new
|
8
|
+
|
9
|
+
form = PPCurses::Form.new
|
10
|
+
|
11
|
+
km = PPCurses::InputElement.new_decimal_only(' Decimal Number', 10)
|
12
|
+
age = PPCurses::InputElement.new_integer_only(' Integer', 5)
|
13
|
+
|
14
|
+
form.add(km)
|
15
|
+
form.add(age)
|
16
|
+
|
17
|
+
@app.content_view = form
|
18
|
+
@app.launch
|
19
|
+
|
20
|
+
|
21
|
+
|
data/test/form/simple_form.rb
CHANGED
@@ -20,7 +20,7 @@ form = PPCurses::Form.new
|
|
20
20
|
|
21
21
|
first_name = PPCurses::InputElement.new('First Name', 10)
|
22
22
|
last_name = PPCurses::InputElement.new(' Last Name', 10)
|
23
|
-
age = PPCurses::InputElement.new_integer_only('
|
23
|
+
age = PPCurses::InputElement.new_integer_only(' Age', 5)
|
24
24
|
|
25
25
|
gender = PPCurses::RadioButtonGroup.new(' Sex', %w(Male Female))
|
26
26
|
button_pair = PPCurses::ButtonPair.new('Submit', 'Cancel')
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require_relative '../../lib/ppcurses.rb'
|
5
|
+
|
6
|
+
|
7
|
+
@app = PPCurses::Application.new
|
8
|
+
|
9
|
+
form = PPCurses::Form.new
|
10
|
+
|
11
|
+
duration = PPCurses::InputElement.new_time_only(' Duration', 10)
|
12
|
+
|
13
|
+
|
14
|
+
form.add(duration)
|
15
|
+
|
16
|
+
@app.content_view = form
|
17
|
+
@app.launch
|
18
|
+
|
19
|
+
|
20
|
+
|
@@ -13,7 +13,7 @@ def print_value(value, text_color, bg_color)
|
|
13
13
|
pair_index = @index + 1
|
14
14
|
Curses.setpos(@y_loc, @x_loc)
|
15
15
|
Curses.init_pair(pair_index, text_color, bg_color)
|
16
|
-
color_pair = color_pair(pair_index)
|
16
|
+
color_pair = Curses.color_pair(pair_index)
|
17
17
|
Curses.attron(color_pair)
|
18
18
|
out_string = "#{value}"
|
19
19
|
@x_loc = @x_loc + 5
|
@@ -34,7 +34,7 @@ def wait_for_key
|
|
34
34
|
|
35
35
|
|
36
36
|
for i in 0..255
|
37
|
-
print_value("#{i}",
|
37
|
+
print_value("#{i}", 0, i )
|
38
38
|
end
|
39
39
|
|
40
40
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../../lib/ppcurses.rb'
|
3
|
+
|
4
|
+
@app = PPCurses::Application.new
|
5
|
+
@table_view = PPCurses::TableView.new
|
6
|
+
|
7
|
+
values = [ ["true", "crossfit"],
|
8
|
+
["false", "reading"],
|
9
|
+
["true", "music"]
|
10
|
+
]
|
11
|
+
|
12
|
+
col_a = PPCurses::TableColumn.new('bool', 6)
|
13
|
+
@table_view.add_table_column(col_a)
|
14
|
+
|
15
|
+
col_b = PPCurses::TableColumn.new('Activity', 12)
|
16
|
+
@table_view.add_table_column(col_b)
|
17
|
+
|
18
|
+
data_source = PPCurses::MultipleColumnDataSource.new(values)
|
19
|
+
@table_view.data_source=data_source
|
20
|
+
|
21
|
+
@app.content_view = @table_view
|
22
|
+
|
23
|
+
@app.launch
|
@@ -41,6 +41,10 @@ buttons.button2.action = method(:music_cancel)
|
|
41
41
|
@app = PPCurses::Application.new
|
42
42
|
@table_view = PPCurses::TableView.new
|
43
43
|
|
44
|
+
col_a = PPCurses::TableColumn.new('Activity')
|
45
|
+
col_a.width = 10
|
46
|
+
@table_view.add_table_column(col_a)
|
47
|
+
|
44
48
|
values = %w(Music Reading Lifts)
|
45
49
|
data_source = PPCurses::SingleColumnDataSource.new(values)
|
46
50
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ppcurses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu Cormier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A curses abstraction layer.
|
14
14
|
email: mcormier@preenandprune.com
|
@@ -21,14 +21,7 @@ files:
|
|
21
21
|
- lib/ppcurses.rb
|
22
22
|
- lib/ppcurses/Screen.rb
|
23
23
|
- lib/ppcurses/actions/BaseAction.rb
|
24
|
-
- lib/ppcurses/actions/GetBooleanAction.rb
|
25
|
-
- lib/ppcurses/actions/GetDataAction.rb
|
26
|
-
- lib/ppcurses/actions/GetEnumeratedStringAction.rb
|
27
|
-
- lib/ppcurses/actions/GetIntegerAction.rb
|
28
|
-
- lib/ppcurses/actions/GetStringAction.rb
|
29
|
-
- lib/ppcurses/actions/InsertSQLDataAction.rb
|
30
24
|
- lib/ppcurses/actions/NulAction.rb
|
31
|
-
- lib/ppcurses/actions/PromptAction.rb
|
32
25
|
- lib/ppcurses/actions/ShowMenuAction.rb
|
33
26
|
- lib/ppcurses/application.rb
|
34
27
|
- lib/ppcurses/date/meta_month.rb
|
@@ -54,16 +47,11 @@ files:
|
|
54
47
|
- lib/ppcurses/window/pp_window.rb
|
55
48
|
- test/application/create_application.rb
|
56
49
|
- test/date/printMetaMonth.rb
|
57
|
-
- test/form/
|
50
|
+
- test/form/decimal_element.rb
|
58
51
|
- test/form/simple_form.rb
|
59
52
|
- test/form/test_combo.rb
|
60
53
|
- test/form/test_date_picker.rb
|
61
|
-
- test/
|
62
|
-
- test/getDataAction.rb
|
63
|
-
- test/getEnumStringAction.rb
|
64
|
-
- test/getIntegerAction.rb
|
65
|
-
- test/getStringAction.rb
|
66
|
-
- test/insertSQLAction.rb
|
54
|
+
- test/form/time_element.rb
|
67
55
|
- test/menu/changeMenuBorder.rb
|
68
56
|
- test/menu/compositeMenu.rb
|
69
57
|
- test/menu/displayMenu.rb
|
@@ -72,6 +60,7 @@ files:
|
|
72
60
|
- test/menu/menuWmenuItems.rb
|
73
61
|
- test/raw_screen/display_colours.rb
|
74
62
|
- test/raw_screen/press_a_key.rb
|
63
|
+
- test/table_view/testMultiColView.rb
|
75
64
|
- test/table_view/testTableView.rb
|
76
65
|
- test/threads/block_test.rb
|
77
66
|
- test/threads/handle_resize.rb
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require_relative 'PromptAction.rb'
|
2
|
-
|
3
|
-
#noinspection RubyResolve
|
4
|
-
module PPCurses
|
5
|
-
|
6
|
-
class GetBooleanAction < PromptAction
|
7
|
-
|
8
|
-
def initialize(prompt)
|
9
|
-
super(prompt)
|
10
|
-
@state = false
|
11
|
-
end
|
12
|
-
|
13
|
-
def print_prompt
|
14
|
-
super()
|
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(']')
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
def execute
|
24
|
-
print_prompt
|
25
|
-
# Enables reading arrow keys in getch
|
26
|
-
@win.keypad(true)
|
27
|
-
while 1
|
28
|
-
Curses.noecho
|
29
|
-
c = @win.getch
|
30
|
-
|
31
|
-
if c == Curses::KEY_LEFT then @state = false end
|
32
|
-
if c == Curses::KEY_RIGHT then @state = true end
|
33
|
-
if c == ESCAPE then break end
|
34
|
-
|
35
|
-
Curses.echo
|
36
|
-
print_prompt
|
37
|
-
end
|
38
|
-
Curses.echo
|
39
|
-
end
|
40
|
-
|
41
|
-
def data
|
42
|
-
if @state then return '1' end
|
43
|
-
'0'
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
require_relative 'BaseAction.rb'
|
2
|
-
|
3
|
-
#noinspection RubyResolve
|
4
|
-
module PPCurses
|
5
|
-
|
6
|
-
# An action that contains an array of prompt actions.
|
7
|
-
# It can be used to group together multiple prompt actions.
|
8
|
-
#
|
9
|
-
class GetDataAction < BaseAction
|
10
|
-
|
11
|
-
def initialize( actions )
|
12
|
-
@actions = actions
|
13
|
-
unless @actions.nil?
|
14
|
-
@actions.each do |action|
|
15
|
-
action.set_parent_action(self)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def before_actions
|
21
|
-
# Stub for classes that extend
|
22
|
-
end
|
23
|
-
|
24
|
-
def after_actions
|
25
|
-
# Stub for classes that extend
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
def data
|
30
|
-
values = []
|
31
|
-
@actions.each do |action|
|
32
|
-
values.push( action.data )
|
33
|
-
end
|
34
|
-
values
|
35
|
-
end
|
36
|
-
|
37
|
-
def create_window
|
38
|
-
super()
|
39
|
-
# Assign window to actions
|
40
|
-
unless @actions.nil?
|
41
|
-
@actions.each do |action|
|
42
|
-
action.set_window(@win)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def execute
|
48
|
-
create_window
|
49
|
-
Curses.echo
|
50
|
-
|
51
|
-
@win.setpos(@win.cury, x_padding )
|
52
|
-
|
53
|
-
self.before_actions
|
54
|
-
|
55
|
-
@actions.each do |action|
|
56
|
-
action.execute
|
57
|
-
end
|
58
|
-
|
59
|
-
self.after_actions
|
60
|
-
|
61
|
-
Curses.noecho
|
62
|
-
@win.clear
|
63
|
-
@win.refresh
|
64
|
-
@win.close
|
65
|
-
end
|
66
|
-
|
67
|
-
def print_line(string)
|
68
|
-
@win.setpos(@win.cury, win_padding)
|
69
|
-
@win.addstr(string)
|
70
|
-
@win.setpos(@win.cury + 1, win_padding)
|
71
|
-
end
|
72
|
-
|
73
|
-
def print_success_line(string)
|
74
|
-
Curses.init_pair(1, COLOR_GREEN, COLOR_BLACK)
|
75
|
-
@win.attron(color_pair(1))
|
76
|
-
self.print_line(string)
|
77
|
-
@win.attroff(color_pair(1))
|
78
|
-
end
|
79
|
-
|
80
|
-
def print_error_line(string)
|
81
|
-
Curses.init_pair(1, COLOR_RED, COLOR_BLACK)
|
82
|
-
@win.attron(color_pair(1))
|
83
|
-
self.print_line(string)
|
84
|
-
@win.attroff(color_pair(1))
|
85
|
-
end
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require_relative 'BaseAction.rb'
|
2
|
-
|
3
|
-
#noinspection RubyResolve
|
4
|
-
module PPCurses
|
5
|
-
|
6
|
-
class GetEnumeratedStringAction < PromptAction
|
7
|
-
|
8
|
-
# enumeration is a list of possible values
|
9
|
-
# i.e. CD, Vinyl, MP3
|
10
|
-
def initialize(prompt, enumeration)
|
11
|
-
super(prompt)
|
12
|
-
|
13
|
-
# verify enumeration is an array
|
14
|
-
unless enumeration.respond_to?('each_with_index')
|
15
|
-
raise
|
16
|
-
end
|
17
|
-
|
18
|
-
@options = enumeration
|
19
|
-
@current_option = 0
|
20
|
-
end
|
21
|
-
|
22
|
-
def print_prompt
|
23
|
-
super()
|
24
|
-
@options.each_with_index do |option, index|
|
25
|
-
@win.addstr(option)
|
26
|
-
if index == @current_option
|
27
|
-
@win.addstr(' [X] ')
|
28
|
-
else
|
29
|
-
@win.addstr(' [ ] ')
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def execute
|
36
|
-
print_prompt
|
37
|
-
# Enables reading arrow keys in getch
|
38
|
-
@win.keypad(true)
|
39
|
-
while 1
|
40
|
-
Curses.noecho
|
41
|
-
c = @win.getch
|
42
|
-
|
43
|
-
if c == Curses::KEY_LEFT then @current_option = @current_option-1 end
|
44
|
-
if c == Curses::KEY_RIGHT then @current_option = @current_option+1 end
|
45
|
-
if c == ESCAPE then break end
|
46
|
-
|
47
|
-
if @current_option < 0 then @current_option = @options.length-1 end
|
48
|
-
if @current_option > @options.length-1 then @current_option = 0 end
|
49
|
-
|
50
|
-
Curses.echo
|
51
|
-
print_prompt
|
52
|
-
end
|
53
|
-
Curses.echo
|
54
|
-
# Go to next line so that further actions to overwrite
|
55
|
-
# the choice
|
56
|
-
@win.setpos(@win.cury + 1, x_padding)
|
57
|
-
end
|
58
|
-
|
59
|
-
def data
|
60
|
-
@options[@current_option]
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require_relative 'PromptAction.rb'
|
2
|
-
|
3
|
-
#noinspection RubyResolve
|
4
|
-
module PPCurses
|
5
|
-
|
6
|
-
class GetIntegerAction < PromptAction
|
7
|
-
|
8
|
-
def execute
|
9
|
-
y = @win.cury
|
10
|
-
@data = ''
|
11
|
-
begin
|
12
|
-
@win.setpos(y, x_padding)
|
13
|
-
@win.clrtoeol
|
14
|
-
@win.box('|', '-')
|
15
|
-
@win.addstr(@prompt)
|
16
|
-
Curses.echo
|
17
|
-
@data = @win.getstr
|
18
|
-
Curses.noecho
|
19
|
-
end until @data =~ /^\d+$/
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require_relative 'BaseAction.rb'
|
2
|
-
|
3
|
-
#noinspection RubyResolve
|
4
|
-
module PPCurses
|
5
|
-
|
6
|
-
class InsertSQLDataAction < GetDataAction
|
7
|
-
|
8
|
-
def initialize( actions, sql, db )
|
9
|
-
super(actions)
|
10
|
-
@sql = sql
|
11
|
-
@db = db
|
12
|
-
end
|
13
|
-
|
14
|
-
def win_height
|
15
|
-
8 + @actions.length
|
16
|
-
end
|
17
|
-
|
18
|
-
def after_actions
|
19
|
-
prepared_sql = @sql
|
20
|
-
data_array = []
|
21
|
-
|
22
|
-
@actions.each do |action|
|
23
|
-
prepared_sql = prepared_sql.sub('?', action.data)
|
24
|
-
data_array.push(action.data)
|
25
|
-
end
|
26
|
-
|
27
|
-
self.prompt_to_change_data(prepared_sql, data_array)
|
28
|
-
|
29
|
-
end
|
30
|
-
|
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)
|
36
|
-
|
37
|
-
proceed = GetBooleanAction.new('Proceed? ')
|
38
|
-
proceed.set_parent_action(self)
|
39
|
-
proceed.set_window(@win)
|
40
|
-
proceed.execute
|
41
|
-
|
42
|
-
did_insert = false
|
43
|
-
|
44
|
-
if proceed.data == '1'
|
45
|
-
self.print_line('')
|
46
|
-
begin
|
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')
|
53
|
-
rescue SQLite3::Exception => e
|
54
|
-
self.print_error_line('Exception occurred')
|
55
|
-
self.print_error_line(e.message)
|
56
|
-
ensure
|
57
|
-
self.print_line('')
|
58
|
-
self.print_line('< Press any key to continue > ')
|
59
|
-
@win.getch
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
did_insert
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require_relative 'BaseAction.rb'
|
2
|
-
|
3
|
-
#noinspection RubyResolve
|
4
|
-
module PPCurses
|
5
|
-
class PromptAction < BaseAction
|
6
|
-
|
7
|
-
def initialize(prompt)
|
8
|
-
@prompt = prompt
|
9
|
-
end
|
10
|
-
|
11
|
-
def set_parent_action(action)
|
12
|
-
@parent = action
|
13
|
-
end
|
14
|
-
|
15
|
-
def x_padding
|
16
|
-
if @parent.nil?
|
17
|
-
self.win_padding
|
18
|
-
else
|
19
|
-
@parent.win_padding
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def print_prompt
|
24
|
-
@win.setpos(@win.cury, self.x_padding )
|
25
|
-
@win.addstr(@prompt)
|
26
|
-
end
|
27
|
-
|
28
|
-
def execute
|
29
|
-
print_prompt
|
30
|
-
Curses.echo
|
31
|
-
@data = @win.getstr
|
32
|
-
Curses.noecho
|
33
|
-
end
|
34
|
-
|
35
|
-
def data
|
36
|
-
@data
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require_relative '../../lib/ppcurses.rb'
|
5
|
-
|
6
|
-
@app = PPCurses::Application.new
|
7
|
-
|
8
|
-
@win = PPCurses::Window.new(9,60,0,0)
|
9
|
-
|
10
|
-
table_view = PPCurses::TableView.new
|
11
|
-
|
12
|
-
|
13
|
-
@app.content_view = table_view
|
14
|
-
@app.launch
|
15
|
-
|
data/test/getBooleanAction.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require_relative '../lib/ppcurses.rb'
|
5
|
-
|
6
|
-
action = PPCurses::GetBooleanAction.new('Is the sky blue? ')
|
7
|
-
|
8
|
-
def do_boolean_action(action)
|
9
|
-
action.show
|
10
|
-
action.execute
|
11
|
-
end
|
12
|
-
|
13
|
-
screen = PPCurses::Screen.new
|
14
|
-
screen.run { do_boolean_action(action) }
|
15
|
-
|
16
|
-
puts "Value input was: #{action.data}"
|
data/test/getDataAction.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require_relative '../lib/ppcurses.rb'
|
5
|
-
|
6
|
-
integer_action = PPCurses::GetIntegerAction.new('Input Integer : ')
|
7
|
-
string_action = PPCurses::GetStringAction.new('Input your name: ')
|
8
|
-
|
9
|
-
action = PPCurses::GetDataAction.new( [integer_action, string_action] )
|
10
|
-
|
11
|
-
def do_integer_action(action)
|
12
|
-
action.show
|
13
|
-
action.execute
|
14
|
-
end
|
15
|
-
|
16
|
-
screen = PPCurses::Screen.new
|
17
|
-
screen.run { do_integer_action(action) }
|
18
|
-
|
19
|
-
puts 'Value input was: ' + action.data.to_s
|
data/test/getEnumStringAction.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require_relative '../lib/ppcurses.rb'
|
5
|
-
|
6
|
-
action = PPCurses::GetEnumeratedStringAction.new('Media Type? ', %w(CD Vinyl MP3))
|
7
|
-
|
8
|
-
def do_action(action)
|
9
|
-
action.show
|
10
|
-
action.execute
|
11
|
-
end
|
12
|
-
|
13
|
-
screen = PPCurses::Screen.new
|
14
|
-
screen.run { do_action(action) }
|
15
|
-
|
16
|
-
puts "Value input was: #{action.data}"
|
data/test/getIntegerAction.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require_relative '../lib/ppcurses.rb'
|
5
|
-
|
6
|
-
action = PPCurses::GetIntegerAction.new('Input Integer : ')
|
7
|
-
|
8
|
-
def do_integer_action(action)
|
9
|
-
action.show
|
10
|
-
action.execute
|
11
|
-
end
|
12
|
-
|
13
|
-
screen = PPCurses::Screen.new
|
14
|
-
screen.run { do_integer_action(action) }
|
15
|
-
|
16
|
-
puts "Value input was: #{action.data}"
|
data/test/getStringAction.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require_relative '../lib/ppcurses.rb'
|
5
|
-
|
6
|
-
action = PPCurses::GetStringAction.new('Input your name: ')
|
7
|
-
|
8
|
-
def get_string_action(action)
|
9
|
-
action.show()
|
10
|
-
action.execute()
|
11
|
-
end
|
12
|
-
|
13
|
-
screen = PPCurses::Screen.new()
|
14
|
-
screen.run { get_string_action(action) }
|
15
|
-
|
16
|
-
puts 'Value input was: ' + action.data()
|
data/test/insertSQLAction.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require_relative '../lib/ppcurses.rb'
|
5
|
-
|
6
|
-
begin
|
7
|
-
#noinspection RubyResolve
|
8
|
-
require 'sqlite3'
|
9
|
-
rescue LoadError => e
|
10
|
-
abort 'Missing dependency! Run: gem install sqlite3'
|
11
|
-
end
|
12
|
-
|
13
|
-
string_action = PPCurses::GetStringAction.new('What is your name? ')
|
14
|
-
integer_action = PPCurses::GetIntegerAction.new('Input an integer? ')
|
15
|
-
|
16
|
-
def do_action(action)
|
17
|
-
action.show
|
18
|
-
action.execute
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
#noinspection RubyResolve
|
23
|
-
db = SQLite3::Database.open 'test.db'
|
24
|
-
db.execute <<-SQL
|
25
|
-
create table testTable (name varchar(30), val int);
|
26
|
-
SQL
|
27
|
-
|
28
|
-
|
29
|
-
sql_action = PPCurses::InsertSQLDataAction.new( [string_action, integer_action],
|
30
|
-
'Insert into testTable(name, val) values (?, ?)', db)
|
31
|
-
|
32
|
-
screen = PPCurses::Screen.new
|
33
|
-
screen.run { do_action(sql_action) }
|
34
|
-
|
35
|
-
|
36
|
-
db.close
|
37
|
-
File.delete('test.db')
|
38
|
-
|
39
|
-
|