cdk 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cdk.rb +7 -866
  3. data/lib/cdk/cdk_objs.rb +46 -423
  4. data/lib/cdk/components.rb +28 -0
  5. data/lib/cdk/{alphalist.rb → components/alphalist.rb} +9 -6
  6. data/lib/cdk/components/button.rb +405 -0
  7. data/lib/cdk/{buttonbox.rb → components/buttonbox.rb} +11 -11
  8. data/lib/cdk/{calendar.rb → components/calendar.rb} +13 -13
  9. data/lib/cdk/components/dialog.rb +343 -0
  10. data/lib/cdk/{dscale.rb → components/dscale.rb} +0 -0
  11. data/lib/cdk/{entry.rb → components/entry.rb} +18 -18
  12. data/lib/cdk/{fscale.rb → components/fscale.rb} +1 -1
  13. data/lib/cdk/{fselect.rb → components/fselect.rb} +16 -13
  14. data/lib/cdk/{fslider.rb → components/fslider.rb} +1 -1
  15. data/lib/cdk/components/graph.rb +386 -0
  16. data/lib/cdk/{histogram.rb → components/histogram.rb} +3 -3
  17. data/lib/cdk/{itemlist.rb → components/itemlist.rb} +14 -14
  18. data/lib/cdk/{label.rb → components/label.rb} +7 -7
  19. data/lib/cdk/{marquee.rb → components/marquee.rb} +7 -7
  20. data/lib/cdk/{matrix.rb → components/matrix.rb} +27 -27
  21. data/lib/cdk/{mentry.rb → components/mentry.rb} +18 -18
  22. data/lib/cdk/{menu.rb → components/menu.rb} +18 -18
  23. data/lib/cdk/{radio.rb → components/radio.rb} +12 -12
  24. data/lib/cdk/{scale.rb → components/scale.rb} +13 -13
  25. data/lib/cdk/{scroll.rb → components/scroll.rb} +23 -386
  26. data/lib/cdk/{scroller.rb → components/scroller.rb} +1 -1
  27. data/lib/cdk/{selection.rb → components/selection.rb} +14 -14
  28. data/lib/cdk/{slider.rb → components/slider.rb} +15 -15
  29. data/lib/cdk/{swindow.rb → components/swindow.rb} +14 -14
  30. data/lib/cdk/{template.rb → components/template.rb} +18 -18
  31. data/lib/cdk/{uscale.rb → components/uscale.rb} +0 -0
  32. data/lib/cdk/{uslider.rb → components/uslider.rb} +0 -0
  33. data/lib/cdk/{viewer.rb → components/viewer.rb} +88 -18
  34. data/lib/cdk/constants.rb +54 -0
  35. data/lib/cdk/display.rb +30 -35
  36. data/lib/cdk/draw.rb +4 -6
  37. data/lib/cdk/helpers/file.rb +43 -0
  38. data/lib/cdk/helpers/types.rb +13 -0
  39. data/lib/cdk/helpers/window.rb +64 -0
  40. data/lib/cdk/mixins/alignments.rb +55 -0
  41. data/lib/cdk/mixins/bindings.rb +73 -0
  42. data/lib/cdk/mixins/borders.rb +62 -0
  43. data/lib/cdk/mixins/common_controls.rb +14 -0
  44. data/lib/cdk/mixins/converters.rb +358 -0
  45. data/lib/cdk/mixins/exit_conditions.rb +31 -0
  46. data/lib/cdk/mixins/focusable.rb +17 -0
  47. data/lib/cdk/mixins/formattable.rb +15 -0
  48. data/lib/cdk/mixins/has_screen.rb +23 -0
  49. data/lib/cdk/mixins/has_title.rb +64 -0
  50. data/lib/cdk/mixins/justifications.rb +26 -0
  51. data/lib/cdk/mixins/list_support.rb +31 -0
  52. data/lib/cdk/mixins/movement.rb +140 -0
  53. data/lib/cdk/mixins/window_hooks.rb +18 -0
  54. data/lib/cdk/mixins/window_input.rb +61 -0
  55. data/lib/cdk/screen.rb +27 -3
  56. metadata +51 -29
  57. data/lib/cdk/dialog.rb +0 -727
@@ -0,0 +1,64 @@
1
+ module CDK
2
+ module HasTitle
3
+ attr_accessor :title_attrib
4
+
5
+ def init_title
6
+ @title_attrib = Ncurses::A_NORMAL
7
+ end
8
+
9
+ # Set the widget's title.
10
+ def setTitle (title, box_width)
11
+ if !title.nil?
12
+ temp = title.split("\n")
13
+ @title_lines = temp.size
14
+
15
+ if box_width >= 0
16
+ max_width = 0
17
+ temp.each do |line|
18
+ len = []
19
+ align = []
20
+ holder = char2Chtype(line, len, align)
21
+ max_width = [len[0], max_width].max
22
+ end
23
+ box_width = [box_width, max_width + 2 * @border_size].max
24
+ else
25
+ box_width = -(box_width - 1)
26
+ end
27
+
28
+ # For each line in the title convert from string to chtype array
29
+ title_width = box_width - (2 * @border_size)
30
+ @title = []
31
+ @title_pos = []
32
+ @title_len = []
33
+ (0...@title_lines).each do |x|
34
+ len_x = []
35
+ pos_x = []
36
+ @title << char2Chtype(temp[x], len_x, pos_x)
37
+ @title_len.concat(len_x)
38
+ @title_pos << justify_string(title_width, len_x[0], pos_x[0])
39
+ end
40
+ end
41
+
42
+ return box_width
43
+ end
44
+
45
+ # Draw the widget's title
46
+ def drawTitle(win)
47
+ (0...@title_lines).each do |x|
48
+ Draw.writeChtypeAttrib(@win,
49
+ @title_pos[x] + @border_size,
50
+ x + @border_size,
51
+ @title[x],
52
+ title_attrib,
53
+ CDK::HORIZONTAL,
54
+ 0,
55
+ @title_len[x])
56
+ end
57
+ end
58
+
59
+ # Remove storage for the widget's title.
60
+ def cleanTitle
61
+ @title_lines = ''
62
+ end
63
+ end # module HasTitle
64
+ end # module CDK
@@ -0,0 +1,26 @@
1
+ module CDK
2
+ module Justifications
3
+ # This takes a string, a field width, and a justification type
4
+ # and returns the adjustment to make, to fill the justification
5
+ # requirement
6
+ def justify_string (box_width, mesg_length, justify)
7
+ # make sure the message isn't longer than the width
8
+ # if it is, return 0
9
+ if mesg_length >= box_width
10
+ return 0
11
+ end
12
+
13
+ # try to justify the message
14
+ case justify
15
+ when LEFT
16
+ 0
17
+ when RIGHT
18
+ box_width - mesg_length
19
+ when CENTER
20
+ (box_width - mesg_length) / 2
21
+ else
22
+ justify
23
+ end
24
+ end
25
+ end # module Justifications
26
+ end # module CDK
@@ -0,0 +1,31 @@
1
+ module CDK
2
+ module ListSupport
3
+ # This looks for a subset of a word in the given list
4
+ def search_list(list, list_size, pattern)
5
+ index = -1
6
+
7
+ if pattern.size > 0
8
+ (0...list_size).each do |x|
9
+ len = [list[x].size, pattern.size].min
10
+ ret = (list[x][0...len] <=> pattern)
11
+
12
+ # If 'ret' is less than 0 then the current word is alphabetically
13
+ # less than the provided word. At this point we will set the index
14
+ # to the current position. If 'ret' is greater than 0, then the
15
+ # current word is alphabetically greater than the given word. We
16
+ # should return with index, which might contain the last best match.
17
+ # If they are equal then we've found it.
18
+ if ret < 0
19
+ index = ret
20
+ else
21
+ if ret == 0
22
+ index = x
23
+ end
24
+ break
25
+ end
26
+ end
27
+ end
28
+ return index
29
+ end
30
+ end # module ListSupport
31
+ end # module CDK
@@ -0,0 +1,140 @@
1
+ module CDK
2
+ module Movement
3
+ def move(xplace, yplace, relative, refresh_flag)
4
+ self.move_specific(xplace, yplace, relative, refresh_flag,
5
+ [@win, @shadow_win], [])
6
+ end
7
+
8
+ def move_specific(xplace, yplace, relative, refresh_flag,
9
+ windows, subwidgets)
10
+ current_x = @win.getbegx
11
+ current_y = @win.getbegy
12
+ xpos = xplace
13
+ ypos = yplace
14
+
15
+ # If this is a relative move, then we will adjust where we want
16
+ # to move to.
17
+ if relative
18
+ xpos = @win.getbegx + xplace
19
+ ypos = @win.getbegy + yplace
20
+ end
21
+
22
+ # Adjust the window if we need to
23
+ xtmp = [xpos]
24
+ ytmp = [ypos]
25
+ alignxy(@screen.window, xtmp, ytmp, @box_width, @box_height)
26
+ xpos = xtmp[0]
27
+ ypos = ytmp[0]
28
+
29
+ # Get the difference
30
+ xdiff = current_x - xpos
31
+ ydiff = current_y - ypos
32
+
33
+ # Move the window to the new location.
34
+ windows.each do |window|
35
+ CDK.moveCursesWindow(window, -xdiff, -ydiff)
36
+ end
37
+
38
+ subwidgets.each do |subwidget|
39
+ subwidget.move(xplace, yplace, relative, false)
40
+ end
41
+
42
+ # Touch the windows so they 'move'
43
+ CDK::SCREEN.refreshCDKWindow(@screen.window)
44
+
45
+ # Redraw the window, if they asked for it
46
+ if refresh_flag
47
+ self.draw(@box)
48
+ end
49
+ end
50
+
51
+ # This allows the user to use the cursor keys to adjust the
52
+ # postion of the widget.
53
+ def position(win)
54
+ parent = @screen.window
55
+ orig_x = win.getbegx
56
+ orig_y = win.getbegy
57
+ beg_x = parent.getbegx
58
+ beg_y = parent.getbegy
59
+ end_x = beg_x + @screen.window.getmaxx
60
+ end_y = beg_y + @screen.window.getmaxy
61
+
62
+ # Let them move the widget around until they hit return.
63
+ while !([CDK::KEY_RETURN, Ncurses::KEY_ENTER].include?(
64
+ key = self.getch([])))
65
+ case key
66
+ when Ncurses::KEY_UP, '8'.ord
67
+ if win.getbegy > beg_y
68
+ self.move(0, -1, true, true)
69
+ else
70
+ CDK.Beep
71
+ end
72
+ when Ncurses::KEY_DOWN, '2'.ord
73
+ if (win.getbegy + win.getmaxy) < end_y
74
+ self.move(0, 1, true, true)
75
+ else
76
+ CDK.Beep
77
+ end
78
+ when Ncurses::KEY_LEFT, '4'.ord
79
+ if win.getbegx > beg_x
80
+ self.move(-1, 0, true, true)
81
+ else
82
+ CDK.Beep
83
+ end
84
+ when Ncurses::KEY_RIGHT, '6'.ord
85
+ if (win.getbegx + win.getmaxx) < end_x
86
+ self.move(1, 0, true, true)
87
+ else
88
+ CDK.Beep
89
+ end
90
+ when '7'.ord
91
+ if win.getbegy > beg_y && win.getbegx > beg_x
92
+ self.move(-1, -1, true, true)
93
+ else
94
+ CDK.Beep
95
+ end
96
+ when '9'.ord
97
+ if (win.getbegx + win.getmaxx) < end_x && win.getbegy > beg_y
98
+ self.move(1, -1, true, true)
99
+ else
100
+ CDK.Beep
101
+ end
102
+ when '1'.ord
103
+ if win.getbegx > beg_x && (win.getbegy + win.getmaxy) < end_y
104
+ self.move(-1, 1, true, true)
105
+ else
106
+ CDK.Beep
107
+ end
108
+ when '3'.ord
109
+ if (win.getbegx + win.getmaxx) < end_x &&
110
+ (win.getbegy + win.getmaxy) < end_y
111
+ self.move(1, 1, true, true)
112
+ else
113
+ CDK.Beep
114
+ end
115
+ when '5'.ord
116
+ self.move(CDK::CENTER, CDK::CENTER, false, true)
117
+ when 't'.ord
118
+ self.move(win.getbegx, CDK::TOP, false, true)
119
+ when 'b'.ord
120
+ self.move(win.getbegx, CDK::BOTTOM, false, true)
121
+ when 'l'.ord
122
+ self.move(CDK::LEFT, win.getbegy, false, true)
123
+ when 'r'.ord
124
+ self.move(CDK::RIGHT, win.getbegy, false, true)
125
+ when 'c'.ord
126
+ self.move(CDK::CENTER, win.getbegy, false, true)
127
+ when 'C'.ord
128
+ self.move(win.getbegx, CDK::CENTER, false, true)
129
+ when CDK::REFRESH
130
+ @screen.erase
131
+ @screen.refresh
132
+ when CDK::KEY_ESC
133
+ self.move(orig_x, orig_y, false, true)
134
+ else
135
+ CDK.Beep
136
+ end
137
+ end
138
+ end
139
+ end # module Movement
140
+ end # module CDK
@@ -0,0 +1,18 @@
1
+ module CDK
2
+ module WindowHooks
3
+ def draw(a)
4
+ end
5
+
6
+ def erase
7
+ end
8
+
9
+ def saveData
10
+ end
11
+
12
+ def refreshData
13
+ end
14
+
15
+ def destroy
16
+ end
17
+ end # module WindowHooks
18
+ end # module CDK
@@ -0,0 +1,61 @@
1
+ module CDK
2
+ module WindowInput
3
+ def inject(a)
4
+ end
5
+
6
+ # Set data for preprocessing
7
+ def setPreProcess (fn, data)
8
+ @pre_process_func = fn
9
+ @pre_process_data = data
10
+ end
11
+
12
+ # Set data for postprocessing
13
+ def setPostProcess (fn, data)
14
+ @post_process_func = fn
15
+ @post_process_data = data
16
+ end
17
+
18
+ def getc
19
+ cdktype = self.object_type
20
+ test = self.bindableObject(cdktype)
21
+ result = @input_window.wgetch
22
+
23
+ if result >= 0 && !(test.nil?) && test.binding_list.include?(result) &&
24
+ test.binding_list[result][0] == :getc
25
+ result = test.binding_list[result][1]
26
+ elsif test.nil? || !(test.binding_list.include?(result)) ||
27
+ test.binding_list[result][0].nil?
28
+ case result
29
+ when "\r".ord, "\n".ord
30
+ result = Ncurses::KEY_ENTER
31
+ when "\t".ord
32
+ result = CDK::KEY_TAB
33
+ when CDK::DELETE
34
+ result = Ncurses::KEY_DC
35
+ when "\b".ord
36
+ result = Ncurses::KEY_BACKSPACE
37
+ when CDK::BEGOFLINE
38
+ result = Ncurses::KEY_HOME
39
+ when CDK::ENDOFLINE
40
+ result = Ncurses::KEY_END
41
+ when CDK::FORCHAR
42
+ result = Ncurses::KEY_RIGHT
43
+ when CDK::BACKCHAR
44
+ result = Ncurses::KEY_LEFT
45
+ when CDK::NEXT
46
+ result = CDK::KEY_TAB
47
+ when CDK::PREV
48
+ result = Ncurses::KEY_BTAB
49
+ end
50
+ end
51
+
52
+ return result
53
+ end
54
+
55
+ def getch(function_key)
56
+ key = self.getc
57
+ function_key << (key >= Ncurses::KEY_MIN && key <= Ncurses::KEY_MAX)
58
+ return key
59
+ end
60
+ end # module WindowInput
61
+ end # module CDK
@@ -189,13 +189,31 @@ module CDK
189
189
  self.refresh
190
190
  end
191
191
 
192
+ def self.refresh_output(v=true)
193
+ @refresh_output = v
194
+ end
195
+
196
+ def self.refresh_output?
197
+ !defined?(@refresh_output) || !!@refresh_output
198
+ end
199
+
200
+ def self.wrefresh(w)
201
+ if refresh_output?
202
+ w.wrefresh
203
+
204
+ else
205
+ w.noutrefresh
206
+
207
+ end
208
+ end
209
+
192
210
  # Refresh one CDK window.
193
211
  # FIXME(original): this should be rewritten to use the panel library, so
194
212
  # it would not be necessary to touch the window to ensure that it covers
195
213
  # other windows.
196
- def SCREEN.refreshCDKWindow(win)
214
+ def self.refreshCDKWindow(win)
197
215
  win.touchwin
198
- win.wrefresh
216
+ SCREEN.wrefresh(win)
199
217
  end
200
218
 
201
219
  # This refreshes all the objects in the screen.
@@ -237,6 +255,12 @@ module CDK
237
255
  end
238
256
  end
239
257
 
258
+ def noutrefresh
259
+ SCREEN.refresh_output(false)
260
+ refresh
261
+ SCREEN.refresh_output(true)
262
+ end
263
+
240
264
  # This clears all the objects in the screen
241
265
  def erase
242
266
  # We just call the object erase function
@@ -248,7 +272,7 @@ module CDK
248
272
  end
249
273
 
250
274
  # Refresh the screen.
251
- @window.wrefresh
275
+ SCREEN.wrefresh(@window)
252
276
  end
253
277
 
254
278
  # Destroy all the objects on a screen
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mo Morsi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-14 00:00:00.000000000 Z
11
+ date: 2018-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ncursesw
@@ -32,38 +32,60 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - lib/cdk.rb
35
- - lib/cdk/alphalist.rb
36
- - lib/cdk/buttonbox.rb
37
- - lib/cdk/calendar.rb
38
35
  - lib/cdk/cdk_objs.rb
39
- - lib/cdk/dialog.rb
36
+ - lib/cdk/components.rb
37
+ - lib/cdk/components/alphalist.rb
38
+ - lib/cdk/components/button.rb
39
+ - lib/cdk/components/buttonbox.rb
40
+ - lib/cdk/components/calendar.rb
41
+ - lib/cdk/components/dialog.rb
42
+ - lib/cdk/components/dscale.rb
43
+ - lib/cdk/components/entry.rb
44
+ - lib/cdk/components/fscale.rb
45
+ - lib/cdk/components/fselect.rb
46
+ - lib/cdk/components/fslider.rb
47
+ - lib/cdk/components/graph.rb
48
+ - lib/cdk/components/histogram.rb
49
+ - lib/cdk/components/itemlist.rb
50
+ - lib/cdk/components/label.rb
51
+ - lib/cdk/components/marquee.rb
52
+ - lib/cdk/components/matrix.rb
53
+ - lib/cdk/components/mentry.rb
54
+ - lib/cdk/components/menu.rb
55
+ - lib/cdk/components/radio.rb
56
+ - lib/cdk/components/scale.rb
57
+ - lib/cdk/components/scroll.rb
58
+ - lib/cdk/components/scroller.rb
59
+ - lib/cdk/components/selection.rb
60
+ - lib/cdk/components/slider.rb
61
+ - lib/cdk/components/swindow.rb
62
+ - lib/cdk/components/template.rb
63
+ - lib/cdk/components/uscale.rb
64
+ - lib/cdk/components/uslider.rb
65
+ - lib/cdk/components/viewer.rb
66
+ - lib/cdk/constants.rb
40
67
  - lib/cdk/display.rb
41
68
  - lib/cdk/draw.rb
42
- - lib/cdk/dscale.rb
43
- - lib/cdk/entry.rb
44
- - lib/cdk/fscale.rb
45
- - lib/cdk/fselect.rb
46
- - lib/cdk/fslider.rb
47
- - lib/cdk/histogram.rb
48
- - lib/cdk/itemlist.rb
49
- - lib/cdk/label.rb
50
- - lib/cdk/marquee.rb
51
- - lib/cdk/matrix.rb
52
- - lib/cdk/mentry.rb
53
- - lib/cdk/menu.rb
54
- - lib/cdk/radio.rb
55
- - lib/cdk/scale.rb
69
+ - lib/cdk/helpers/file.rb
70
+ - lib/cdk/helpers/types.rb
71
+ - lib/cdk/helpers/window.rb
72
+ - lib/cdk/mixins/alignments.rb
73
+ - lib/cdk/mixins/bindings.rb
74
+ - lib/cdk/mixins/borders.rb
75
+ - lib/cdk/mixins/common_controls.rb
76
+ - lib/cdk/mixins/converters.rb
77
+ - lib/cdk/mixins/exit_conditions.rb
78
+ - lib/cdk/mixins/focusable.rb
79
+ - lib/cdk/mixins/formattable.rb
80
+ - lib/cdk/mixins/has_screen.rb
81
+ - lib/cdk/mixins/has_title.rb
82
+ - lib/cdk/mixins/justifications.rb
83
+ - lib/cdk/mixins/list_support.rb
84
+ - lib/cdk/mixins/movement.rb
85
+ - lib/cdk/mixins/window_hooks.rb
86
+ - lib/cdk/mixins/window_input.rb
56
87
  - lib/cdk/screen.rb
57
- - lib/cdk/scroll.rb
58
- - lib/cdk/scroller.rb
59
- - lib/cdk/selection.rb
60
- - lib/cdk/slider.rb
61
- - lib/cdk/swindow.rb
62
- - lib/cdk/template.rb
63
88
  - lib/cdk/traverse.rb
64
- - lib/cdk/uscale.rb
65
- - lib/cdk/uslider.rb
66
- - lib/cdk/viewer.rb
67
89
  homepage: http://github.com/movitto/cdk
68
90
  licenses:
69
91
  - BSD-3-Clause