rndk 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -4
  3. data/TODO +21 -1
  4. data/demos/appointment.rb +279 -299
  5. data/demos/clock.rb +13 -8
  6. data/demos/rss-reader.rb +84 -0
  7. data/examples/01-hello-world.rb +13 -11
  8. data/examples/02-colors.rb +14 -21
  9. data/examples/03-markup.rb +7 -7
  10. data/examples/04-quick-widgets.rb +2 -2
  11. data/examples/05-position-widget.rb +50 -31
  12. data/examples/06-callbacks.rb +77 -0
  13. data/examples/07-traverse.rb +90 -0
  14. data/examples/10-all-widgets.rb +165 -0
  15. data/examples/calendar.rb +20 -32
  16. data/examples/entry.rb +15 -20
  17. data/examples/label.rb +11 -11
  18. data/examples/scroll.rb +16 -60
  19. data/examples/slider.rb +18 -19
  20. data/examples/viewer.rb +65 -0
  21. data/lib/rndk.rb +28 -7
  22. data/lib/rndk/alphalist.rb +309 -313
  23. data/lib/rndk/button.rb +239 -157
  24. data/lib/rndk/buttonbox.rb +136 -103
  25. data/lib/rndk/calendar.rb +246 -203
  26. data/lib/rndk/core/color.rb +63 -13
  27. data/lib/rndk/core/display.rb +1 -1
  28. data/lib/rndk/core/draw.rb +11 -11
  29. data/lib/rndk/core/markup.rb +21 -21
  30. data/lib/rndk/core/quick_widgets.rb +75 -96
  31. data/lib/rndk/core/screen.rb +145 -102
  32. data/lib/rndk/core/traverse.rb +150 -136
  33. data/lib/rndk/core/utils.rb +5 -6
  34. data/lib/rndk/core/widget.rb +207 -191
  35. data/lib/rndk/core/widget_bind.rb +108 -0
  36. data/lib/rndk/dialog.rb +88 -56
  37. data/lib/rndk/entry.rb +79 -64
  38. data/lib/rndk/fscale.rb +38 -20
  39. data/lib/rndk/fslider.rb +38 -23
  40. data/lib/rndk/graph.rb +92 -53
  41. data/lib/rndk/itemlist.rb +80 -62
  42. data/lib/rndk/label.rb +111 -77
  43. data/lib/rndk/radio.rb +138 -128
  44. data/lib/rndk/scale.rb +123 -122
  45. data/lib/rndk/scroll.rb +444 -391
  46. data/lib/rndk/scroller.rb +21 -21
  47. data/lib/rndk/slider.rb +149 -140
  48. data/lib/rndk/template.rb +74 -61
  49. data/lib/rndk/version.rb +1 -1
  50. data/lib/rndk/viewer.rb +499 -298
  51. metadata +8 -14
  52. data/demos/fileview.rb +0 -141
  53. data/lib/rndk/dscale.rb +0 -13
  54. data/lib/rndk/fselect.rb +0 -938
  55. data/lib/rndk/histogram.rb +0 -412
  56. data/lib/rndk/marquee.rb +0 -244
  57. data/lib/rndk/matrix.rb +0 -1189
  58. data/lib/rndk/mentry.rb +0 -619
  59. data/lib/rndk/menu.rb +0 -478
  60. data/lib/rndk/selection.rb +0 -630
  61. data/lib/rndk/swindow.rb +0 -766
  62. data/lib/rndk/uscale.rb +0 -14
  63. data/lib/rndk/uslider.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 658d93a038f41e69767bd1f8a24f0ed69ab21d61
4
- data.tar.gz: 085b8d4cf88241e7ed481736a8356be356341628
3
+ metadata.gz: 5fbd239767ebd76e2ead3ac2be92d8324061ddef
4
+ data.tar.gz: 4c0bd5d00c3968a50922c5765522e61d9cc58539
5
5
  SHA512:
6
- metadata.gz: f632241c52b6accf9e017d3e2d8e26e7836d46fcbcbfcd14a3dfa8b092da98fd69500be4921a8744f87d8ecaef19bb1aacfb6cfd0e599deb227b1612242e35e1
7
- data.tar.gz: 4b18178e17b1ab81820caaf5a79fc0ab0bf66f31dfb2bf92f47c1b517fe2ced0a8c594dfb50573a391117b2b0197ace571d152257bdd05a0024c0e1710cb88c7
6
+ metadata.gz: c8047b49f43a88ce3aee7bcb65b513b6e67429879655f657658f19ddcb6f04f5c059b7c9e0de15f56c613c120b23a0cb651b9e3aeb0dcc77b0a2042c1d9bdee8
7
+ data.tar.gz: 8e455a72a17868aedca98d472252e3b92ff7531f7be2d0f39270ce66cadd316965d188b7b00fc8c5efc269b16dabb756d5692ab9f1dc516e14f6990ed8f69f32
data/README.md CHANGED
@@ -7,6 +7,7 @@ details, it provides some widgets for rapid console app development.
7
7
 
8
8
  It means that you'll be able to master the dark arts of text-based
9
9
  applications, easily creating nice apps for the console.
10
+ Not convinced? [Here's some screenshots][screens]!
10
11
 
11
12
  `RNDK` is a fork from `tawny-cdk`, a [Chris Sauro Ruby port][tawny]
12
13
  of [Thomas Dickey's Curses Development Kit][cdk] (in C).
@@ -53,8 +54,6 @@ now, I recommend you to **not** use `rndk` for production programs!
53
54
 
54
55
  ## Installation
55
56
 
56
- `rndk` requires the gem `ffi-ncurses`.
57
-
58
57
  Add this line to your application's Gemfile:
59
58
 
60
59
  gem 'rndk'
@@ -67,14 +66,22 @@ Or install it yourself as:
67
66
 
68
67
  $ gem install rndk
69
68
 
69
+ ## Requirements
70
+
71
+ `rndk` requires the following gems:
72
+
73
+ * [ffi-ncurses][ffi]
74
+
75
+ They'll get installed automatically if you're using `bundle` or `gem install`.
76
+
70
77
  ## Usage
71
78
 
72
79
  [Take a look at the Wiki][wiki]! There's some tutorials and
73
80
  resources there.
74
81
 
75
82
  The `examples` directory contains lots of sample usages for every
76
- widget available. To execute them, go to the `rndk` root folder
77
- and run:
83
+ widget available. If you've not installed `rndk` yet, go to the
84
+ root folder and run:
78
85
 
79
86
  ruby -Ilib examples/YOUR_EXAMPLE_HERE
80
87
 
@@ -107,6 +114,8 @@ Step-by-step guide to contribute:
107
114
  [rbcurse]:https://github.com/rkumar/rbcurse
108
115
  [wiki]:https://github.com/alexdantas/rndk/wiki
109
116
  [widgets]:https://github.com/alexdantas/rndk/wiki/widgets
117
+ [ffi]:http://rubygems.org/gems/ffi-ncurses
118
+ [screens]:https://github.com/alexdantas/rndk/wiki/screenshots
110
119
 
111
120
  ## Contact
112
121
 
data/TODO CHANGED
@@ -1,5 +1,25 @@
1
1
  RNDK TODO List
2
- (forked from Tawny-Cdk's TODO List)
2
+
3
+ The main things we must do are:
4
+
5
+ * Turn general api less C-like and more Ruby-ish.
6
+ - easy: Convert all methods from 'CamelCase' to 'under_scores'.
7
+ - hard: Reflect over the general API
8
+ - hard: Create a nice config system for widgets.
9
+ Mine is so messed up...
10
+
11
+ * Document stuff.
12
+ - easy: Copy relevant parts from CDK's documentation into
13
+ class headers, method docs and such.
14
+ - medium: Explain stuff on modules and classes.
15
+ Argument lists, config, signals, stuff.
16
+
17
+
18
+
19
+
20
+ Now those items were forked from Tawny-Cdk's TODO List.
21
+ Don't take them too seriously.
22
+
3
23
  ------------------------------------------------------------------------------
4
24
 
5
25
  Now that Tawny CDK is basically a complete copy of Thomas Dickey version of
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Note: This is not for beginners! Check out the examples/
4
- # before adventuring into the demos/ realm!
3
+ # Warning: This is not for beginners! Check out the examples/
4
+ # before adventuring into the demos/ realm!
5
+ #
6
+ # Warning2: This is not well-written! Handle with care.
5
7
  #
6
8
  # Shows a book where you can create appointments of different
7
9
  # kinds, save and restore them on a file.
@@ -15,344 +17,322 @@
15
17
  #
16
18
  # It automatically creates file `/tmp/appointments.dat` on the
17
19
  # current directory
20
+ #
18
21
  require 'ostruct'
19
22
  require 'rndk/calendar'
20
23
  require 'rndk/itemlist'
21
24
  require 'rndk/entry'
22
25
 
23
- class Appointment
24
- MAX_MARKERS = 2000
25
- GPAppointmentAttributes = [
26
- Ncurses::A_BLINK,
27
- Ncurses::A_BOLD,
28
- Ncurses::A_REVERSE,
29
- Ncurses::A_UNDERLINE,
30
- ]
31
-
32
- AppointmentType = [
33
- :BIRTHDAY,
34
- :ANNIVERSARY,
35
- :APPOINTMENT,
36
- :OTHER,
37
- ]
38
-
39
- # This reads a given appointment file.
40
- def Appointment.readAppointmentFile(filename, app_info)
41
- appointments = 0
42
- segments = 0
43
- lines = []
44
-
45
- # Read the appointment file.
46
- lines_read = RNDK.read_file(filename, lines)
47
- if lines_read == nil
48
- app_info.count = 0
49
- return
50
- end
26
+ # I really doubt you're gonna put
27
+ # that many markers
28
+ MAX_MARKERS = 2000
29
+
30
+ AppointmentAttributes = [
31
+ RNDK::Color[:blink],
32
+ RNDK::Color[:bold],
33
+ RNDK::Color[:reverse],
34
+ RNDK::Color[:underline],
35
+ ]
36
+
37
+ AppointmentType = [
38
+ :BIRTHDAY,
39
+ :ANNIVERSARY,
40
+ :APPOINTMENT,
41
+ :OTHER,
42
+ ]
43
+
44
+ # This reads a given appointment file into `app_info`.
45
+ def readAppointmentFile(filename, app_info)
46
+ appointments = 0
47
+ segments = 0
48
+
49
+ # Read the appointment file.
50
+ lines = RNDK.read_file filename
51
+
52
+ if lines.nil?
53
+ app_info.count = 0
54
+ return
55
+ end
51
56
 
52
- # Split each line up and create an appointment.
53
- (0...lines_read).each do |x|
54
- temp = lines[x].split(RNDK.CTRL('V').chr)
55
- segments = temp.size
56
-
57
- # A valid line has 5 elements:
58
- # Day, Month, Year, Type, Description.
59
- if segments == 5
60
- app_info.appointment << OpenStruct.new
61
- e_type = Appointment::AppointmentType[temp[3].to_i]
62
-
63
- app_info.appointment[appointments].day = temp[0].to_i
64
- app_info.appointment[appointments].month = temp[1].to_i
65
- app_info.appointment[appointments].year = temp[2].to_i
66
- app_info.appointment[appointments].type = e_type
67
- app_info.appointment[appointments].description = temp[4]
68
- appointments += 1
69
- end
57
+ # Split each line up and create an appointment.
58
+ (0...lines.size).each do |x|
59
+ temp = lines[x].split(RNDK.CTRL('V').chr)
60
+ segments = temp.size
61
+
62
+ # A valid line has 5 elements:
63
+ # Day, Month, Year, Type, Description.
64
+ if segments == 5
65
+ app_info.appointment << OpenStruct.new
66
+ e_type = AppointmentType[temp[3].to_i]
67
+
68
+ app_info.appointment[appointments].day = temp[0].to_i
69
+ app_info.appointment[appointments].month = temp[1].to_i
70
+ app_info.appointment[appointments].year = temp[2].to_i
71
+ app_info.appointment[appointments].type = e_type
72
+ app_info.appointment[appointments].description = temp[4]
73
+ appointments += 1
70
74
  end
71
-
72
- # Keep the amount of appointments read.
73
- app_info.count = appointments
74
75
  end
75
76
 
76
- # This saves a given appointment file.
77
- def Appointment.saveAppointmentFile(filename, app_info)
78
- # TODO: error handling
79
- fd = File.new(filename, 'w')
80
-
81
- # Start writing.
82
- app_info.appointment.each do |appointment|
83
- if appointment.description != ''
84
- fd.puts '%d%c%d%c%d%c%d%c%s' % [
85
- appointment.day, RNDK.CTRL('V').chr,
86
- appointment.month, RNDK.CTRL('V').chr,
87
- appointment.year, RNDK.CTRL('V').chr,
88
- Appointment::AppointmentType.index(appointment.type),
89
- RNDK.CTRL('V').chr, appointment.description]
90
- end
77
+ # Keep the amount of appointments read.
78
+ app_info.count = appointments
79
+ end
80
+
81
+ # This saves a given appointment file.
82
+ def saveAppointmentFile(filename, app_info)
83
+ # TODO: error handling
84
+ fd = File.new(filename, 'w')
85
+
86
+ # Start writing.
87
+ app_info.appointment.each do |appointment|
88
+ if appointment.description != ''
89
+ fd.puts '%d%c%d%c%d%c%d%c%s' % [
90
+ appointment.day, RNDK.CTRL('V').chr,
91
+ appointment.month, RNDK.CTRL('V').chr,
92
+ appointment.year, RNDK.CTRL('V').chr,
93
+ AppointmentType.index(appointment.type),
94
+ RNDK.CTRL('V').chr, appointment.description]
91
95
  end
92
- fd.close
93
96
  end
97
+ fd.close
98
+ end
94
99
 
95
- # This program demonstrates the Rndk calendar widget.
96
- def Appointment.main
100
+ # This adds a marker to the calendar.
101
+ def create_calendar_mark(calendar, info)
102
+
103
+ items = [
104
+ 'Birthday',
105
+ 'Anniversary',
106
+ 'Appointment',
107
+ 'Other',
108
+ ]
109
+
110
+ # Create the itemlist widget.
111
+ itemlist = RNDK::Itemlist.new(calendar.screen, {
112
+ :x => RNDK::CENTER,
113
+ :y => RNDK::CENTER,
114
+ :title => '',
115
+ :label => 'Select Appointment Type: ',
116
+ :items => items
117
+ })
118
+
119
+ # Get the appointment type from the user.
120
+ selection = itemlist.activate
121
+
122
+ # They hit escape, kill the itemlist widget and leave.
123
+ if selection == -1
124
+ itemlist.destroy
125
+ calendar.draw
126
+ return false
127
+ end
97
128
 
98
- # Get the current dates and set the default values for
99
- # the day/month/year values for the calendar.
100
- date_info = Time.now.gmtime
101
- day = date_info.day
102
- month = date_info.mon
103
- year = date_info.year
129
+ # Destroy the itemlist and set the marker.
130
+ itemlist.destroy
131
+ calendar.draw
132
+ marker = AppointmentAttributes[selection]
133
+
134
+ # Create the entry field for the description.
135
+ entry = RNDK::Entry.new(calendar.screen, {
136
+ :x => RNDK::CENTER,
137
+ :y => RNDK::CENTER,
138
+ :title => '<C>Enter a description of the appointment.',
139
+ :label => 'Description: ',
140
+ :field_width => 40,
141
+ })
142
+ # Get the description.
143
+ description = entry.activate
144
+ if description == 0
145
+ entry.destroy
146
+ calendar.draw
147
+ return false
148
+ end
104
149
 
105
- title = "<C></U>RNDK Appointment Book\nPress 'h' for help\n<C><#HL(30)>\n"
150
+ # Destroy the entry and set the marker.
151
+ description = entry.info
152
+ entry.destroy
153
+ calendar.draw
106
154
 
107
- filename = ''
155
+ # Set the marker.
156
+ calendar.set_marker(calendar.day, calendar.month, calendar.year, marker)
108
157
 
109
- # Create the appointment book filename.
110
- filename = "/tmp/appointments.dat"
158
+ # Keep the marker.
159
+ info.appointment << OpenStruct.new
160
+ current = info.count
111
161
 
112
- appointment_info = OpenStruct.new
113
- appointment_info.count = 0
114
- appointment_info.appointment = []
162
+ info.appointment[current].day = calendar.day
163
+ info.appointment[current].month = calendar.month
164
+ info.appointment[current].year = calendar.year
165
+ info.appointment[current].type = AppointmentType[selection]
166
+ info.appointment[current].description = description
167
+ info.count += 1
115
168
 
116
- # Read the appointment book information.
117
- readAppointmentFile(filename, appointment_info)
169
+ # Redraw the calendar.
170
+ calendar.draw
171
+ return false
172
+ end
118
173
 
119
- # Set up RNDK
120
- rndkscreen = RNDK::Screen.new
174
+ # This removes a marker from the calendar.
175
+ def remove_calendar_mark(calendar, info)
121
176
 
122
- # Set up RNDK colors
123
- RNDK::Color.init
177
+ info.appointment.each do |appointment|
178
+ if appointment.day == calendar.day &&
179
+ appointment.month == calendar.month &&
180
+ appointment.year == calendar.year
181
+ appointment.description = ''
182
+ break
183
+ end
184
+ end
124
185
 
125
- # Create the calendar widget.
126
- calendar = RNDK::Calendar.new(rndkscreen,
127
- RNDK::CENTER,
128
- RNDK::CENTER,
129
- title, day, month, year,
130
- Ncurses::A_NORMAL, Ncurses::A_NORMAL, Ncurses::A_NORMAL, Ncurses::A_REVERSE,
131
- true, false)
186
+ # Remove the marker from the calendar.
187
+ calendar.removeMarker(calendar.day, calendar.month, calendar.year)
132
188
 
133
- # Is the widget nil?
134
- if calendar.nil?
135
- RNDK::Screen.end_rndk
189
+ # Redraw the calendar.
190
+ calendar.draw
191
+ return false
192
+ end
136
193
 
137
- puts "Cannot create the calendar. Is the window too small?"
138
- exit 1
194
+ # This displays the marker(s) on the given day.
195
+ def display_calendar_mark(calendar, info)
196
+ found = 0
197
+ type = ''
198
+ mesg = []
199
+
200
+ # Look for the marker in the list.
201
+ info.appointment.each do |appointment|
202
+ # Get the day month year.
203
+ day = appointment.day
204
+ month = appointment.month
205
+ year = appointment.year
206
+
207
+ # Determine the appointment type.
208
+ if appointment.type == :BIRTHDAY
209
+ type = 'Birthday'
210
+ elsif appointment.type == :ANNIVERSARY
211
+ type = 'Anniversary'
212
+ elsif appointment.type == :APPOINTMENT
213
+ type = 'Appointment'
214
+ else
215
+ type = 'Other'
139
216
  end
140
217
 
141
- # This adds a marker to the calendar.
142
- create_calendar_mark_cb = lambda do |object_type, calendar, info, key|
143
- items = [
144
- 'Birthday',
145
- 'Anniversary',
146
- 'Appointment',
147
- 'Other',
148
- ]
149
-
150
- # Create the itemlist widget.
151
- itemlist = RNDK::ITEMLIST.new(calendar.screen,
152
- RNDK::CENTER,
153
- RNDK::CENTER,
154
- '',
155
- 'Select Appointment Type: ',
156
- items,
157
- items.size,
158
- 0,
159
- true,
160
- false)
161
-
162
- # Get the appointment type from the user.
163
- selection = itemlist.activate([])
164
-
165
- # They hit escape, kill the itemlist widget and leave.
166
- if selection == -1
167
- itemlist.destroy
168
- calendar.draw(calendar.box)
169
- return false
170
- end
171
-
172
- # Destroy the itemlist and set the marker.
173
- itemlist.destroy
174
- calendar.draw(calendar.box)
175
- marker = Appointment::GPAppointmentAttributes[selection]
176
-
177
- # Create the entry field for the description.
178
- entry = RNDK::Entry.new(calendar.screen,
179
- RNDK::CENTER,
180
- RNDK::CENTER,
181
- '<C>Enter a description of the appointment.',
182
- 'Description: ',
183
- Ncurses::A_NORMAL,
184
- '.'.ord,
185
- :MIXED,
186
- 40,
187
- 1,
188
- 512,
189
- true,
190
- false)
191
-
192
- # Get the description.
193
- description = entry.activate([])
194
- if description == 0
195
- entry.destroy
196
- calendar.draw(calendar.box)
197
- return false
198
- end
199
-
200
- # Destroy the entry and set the marker.
201
- description = entry.info
202
- entry.destroy
203
- calendar.draw(calendar.box)
204
-
205
- # Set the marker.
206
- calendar.setMarker(calendar.day, calendar.month, calendar.year, marker)
207
-
208
- # Keep the marker.
209
- info.appointment << OpenStruct.new
210
- current = info.count
211
-
212
- info.appointment[current].day = calendar.day
213
- info.appointment[current].month = calendar.month
214
- info.appointment[current].year = calendar.year
215
- info.appointment[current].type = Appointment::AppointmentType[selection]
216
- info.appointment[current].description = description
217
- info.count += 1
218
-
219
- # Redraw the calendar.
220
- calendar.draw(calendar.box)
221
- return false
218
+ # Find the marker by the day/month/year.
219
+ if day == calendar.day && month == calendar.month &&
220
+ year == calendar.year && appointment.description != ''
221
+ # Create the message for the label widget.
222
+ mesg << '<C>Appointment Date: %02d/%02d/%d' % [
223
+ day, month, year]
224
+ mesg << ' '
225
+ mesg << '<C><#HL(35)>'
226
+ mesg << ' Appointment Type: %s' % [type]
227
+ mesg << ' Description :'
228
+ mesg << ' %s' % [appointment.description]
229
+ mesg << '<C><#HL(35)>'
230
+ mesg << ' '
231
+ mesg << '<C>Press space to continue.'
232
+
233
+ found = 1
234
+ break
222
235
  end
236
+ end
223
237
 
224
- # This removes a marker from the calendar.
225
- remove_calendar_mark_cb = lambda do |object_type, calendar, info, key|
226
- info.appointment.each do |appointment|
227
- if appointment.day == calendar.day &&
228
- appointment.month == calendar.month &&
229
- appointment.year == calendar.year
230
- appointment.description = ''
231
- break
232
- end
233
- end
234
-
235
- # Remove the marker from the calendar.
236
- calendar.removeMarker(calendar.day, calendar.month, calendar.year)
237
-
238
- # Redraw the calendar.
239
- calendar.draw(calendar.box)
240
- return false
241
- end
238
+ # If we didn't find the marker, create a different message.
239
+ if found == 0
240
+ mesg << '<C>There is no appointment for %02d/%02d/%d' % [calendar.day, calendar.month, calendar.year]
241
+ mesg << '<C><#HL(30)>'
242
+ mesg << '<C>Press space to continue.'
243
+ end
242
244
 
243
- # This displays the marker(s) on the given day.
244
- display_calendar_mark_cb = lambda do |object_type, calendar, info, key|
245
- found = 0
246
- type = ''
247
- mesg = []
248
-
249
- # Look for the marker in the list.
250
- info.appointment.each do |appointment|
251
- # Get the day month year.
252
- day = appointment.day
253
- month = appointment.month
254
- year = appointment.year
255
-
256
- # Determine the appointment type.
257
- if appointment.type == :BIRTHDAY
258
- type = 'Birthday'
259
- elsif appointment.type == :ANNIVERSARY
260
- type = 'Anniversary'
261
- elsif appointment.type == :APPOINTMENT
262
- type = 'Appointment'
263
- else
264
- type = 'Other'
265
- end
266
-
267
- # Find the marker by the day/month/year.
268
- if day == calendar.day && month == calendar.month &&
269
- year == calendar.year && appointment.description != ''
270
- # Create the message for the label widget.
271
- mesg << '<C>Appointment Date: %02d/%02d/%d' % [
272
- day, month, year]
273
- mesg << ' '
274
- mesg << '<C><#HL(35)>'
275
- mesg << ' Appointment Type: %s' % [type]
276
- mesg << ' Description :'
277
- mesg << ' %s' % [appointment.description]
278
- mesg << '<C><#HL(35)>'
279
- mesg << ' '
280
- mesg << '<C>Press space to continue.'
281
-
282
- found = 1
283
- break
284
- end
285
- end
286
-
287
- # If we didn't find the marker, create a different message.
288
- if found == 0
289
- mesg << '<C>There is no appointment for %02d/%02d/%d' % [calendar.day, calendar.month, calendar.year]
290
- mesg << '<C><#HL(30)>'
291
- mesg << '<C>Press space to continue.'
292
- end
293
-
294
- # Create the label widget
295
- label = RNDK::Label.new(calendar.screen, RNDK::CENTER, RNDK::CENTER, mesg, true, false)
296
- label.draw(label.box)
297
- label.wait(' ')
298
- label.destroy
299
-
300
- # Redraw the calendar
301
- calendar.draw(calendar.box)
302
- return false
303
- end
245
+ # Create the label widget
246
+ label = RNDK::Label.new(calendar.screen, {
247
+ :x => RNDK::CENTER,
248
+ :y => RNDK::CENTER,
249
+ :text => mesg
250
+ })
251
+ label.draw
252
+ label.wait(' ')
253
+ label.destroy
254
+
255
+ # Redraw the calendar
256
+ calendar.draw
257
+ return false
258
+ end
304
259
 
305
- # Shows a help popup with keybindings.
306
- show_help = lambda do |object_type, calendar, info, key|
307
- msg = ["Keybindings:",
308
- " 'm' create appointment at selected day",
309
- " 'r' remove appointment at selected day",
310
- " '?' displays appointment for selected day",
311
- " 'enter' or 'tab' quits"]
260
+ # Shows a help popup with keybindings.
261
+ def show_help(screen)
262
+ msg = ["Keybindings:",
263
+ " 'm' create appointment at selected day",
264
+ " 'r' remove appointment at selected day",
265
+ " '?' displays appointment for selected day",
266
+ " 'enter' or 'tab' quits"]
312
267
 
313
- rndkscreen.popup_label msg
314
- end
268
+ screen.popup_label msg
269
+ end
315
270
 
316
- # Now we bind actions to the calendar.
317
- # Create a key binding to mark days on the calendar.
318
- calendar.bind(:calendar, 'm', create_calendar_mark_cb, appointment_info)
319
- calendar.bind(:calendar, 'M', create_calendar_mark_cb, appointment_info)
320
- calendar.bind(:calendar, 'r', remove_calendar_mark_cb, appointment_info)
321
- calendar.bind(:calendar, 'R', remove_calendar_mark_cb, appointment_info)
322
- calendar.bind(:calendar, '?', display_calendar_mark_cb, appointment_info)
323
- calendar.bind(:calendar, 'h', show_help, nil)
324
-
325
- # Set all the appointments read from the file.
326
- appointment_info.appointment.each do |appointment|
327
- marker = Appointment::GPAppointmentAttributes[Appointment::AppointmentType.index(appointment.type)]
328
-
329
- calendar.setMarker(appointment.day,
330
- appointment.month,
331
- appointment.year,
332
- marker)
333
- end
271
+ begin
272
+ # Set up RNDK and colors
273
+ screen = RNDK::Screen.new
274
+ RNDK::Color.init
275
+
276
+ title = "<C></U>RNDK Appointment Book\nPress 'h' for help\n<C><#HL(30)>\n"
277
+ filename = "/tmp/appointments.dat"
334
278
 
335
- # Draw the calendar widget.
336
- calendar.draw calendar.box
279
+ appointment_info = OpenStruct.new
280
+ appointment_info.count = 0
281
+ appointment_info.appointment = []
337
282
 
338
- # Let the user play with the widget.
339
- calendar.activate
283
+ readAppointmentFile(filename, appointment_info)
340
284
 
341
- # Save the appointment information.
342
- Appointment.saveAppointmentFile(filename, appointment_info)
285
+ # Create the calendar widget.
286
+ calendar = RNDK::Calendar.new(screen, {
287
+ :x => RNDK::CENTER,
288
+ :y => RNDK::CENTER,
289
+ :title => title
290
+ })
343
291
 
344
- # Clean up.
345
- RNDK::Screen.end_rndk
292
+ if calendar.nil?
293
+ RNDK::Screen.finish
294
+
295
+ puts "Cannot create the calendar. Is the window too small?"
296
+ exit 1
346
297
  end
347
- end
348
298
 
299
+ # Now we bind actions to the calendar.
300
+ # Create a key binding to mark days on the calendar.
301
+ calendar.bind_key('m') do
302
+ create_calendar_mark(calendar, appointment_info)
303
+ end
349
304
 
350
- begin
351
- Appointment.main
305
+ calendar.bind_key('r') do
306
+ remove_calendar_mark(calendar, appointment_info)
307
+ end
308
+
309
+ calendar.bind_key('?') do
310
+ display_calendar_mark(calendar, appointment_info)
311
+ end
312
+
313
+ calendar.bind_key('h') { show_help screen }
314
+
315
+ # Set all the appointments read from the file.
316
+ appointment_info.appointment.each do |appointment|
317
+ marker = AppointmentAttributes[AppointmentType.index(appointment.type)]
318
+
319
+ calendar.set_marker(appointment.day,
320
+ appointment.month,
321
+ appointment.year,
322
+ marker)
323
+ end
324
+
325
+ calendar.draw
326
+ calendar.activate
327
+
328
+ # Save the appointment information.
329
+ Appointment.saveAppointmentFile(filename, appointment_info)
330
+
331
+ RNDK::Screen.finish
352
332
 
353
333
  # In case something goes wrong
354
334
  rescue Exception => e
355
- RNDK::Screen.end_rndk
335
+ RNDK::Screen.finish
356
336
 
357
337
  puts e
358
338
  puts e.inspect