rndk 0.2.0 → 1.0.0
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/README.md +13 -4
- data/TODO +21 -1
- data/demos/appointment.rb +279 -299
- data/demos/clock.rb +13 -8
- data/demos/rss-reader.rb +84 -0
- data/examples/01-hello-world.rb +13 -11
- data/examples/02-colors.rb +14 -21
- data/examples/03-markup.rb +7 -7
- data/examples/04-quick-widgets.rb +2 -2
- data/examples/05-position-widget.rb +50 -31
- data/examples/06-callbacks.rb +77 -0
- data/examples/07-traverse.rb +90 -0
- data/examples/10-all-widgets.rb +165 -0
- data/examples/calendar.rb +20 -32
- data/examples/entry.rb +15 -20
- data/examples/label.rb +11 -11
- data/examples/scroll.rb +16 -60
- data/examples/slider.rb +18 -19
- data/examples/viewer.rb +65 -0
- data/lib/rndk.rb +28 -7
- data/lib/rndk/alphalist.rb +309 -313
- data/lib/rndk/button.rb +239 -157
- data/lib/rndk/buttonbox.rb +136 -103
- data/lib/rndk/calendar.rb +246 -203
- data/lib/rndk/core/color.rb +63 -13
- data/lib/rndk/core/display.rb +1 -1
- data/lib/rndk/core/draw.rb +11 -11
- data/lib/rndk/core/markup.rb +21 -21
- data/lib/rndk/core/quick_widgets.rb +75 -96
- data/lib/rndk/core/screen.rb +145 -102
- data/lib/rndk/core/traverse.rb +150 -136
- data/lib/rndk/core/utils.rb +5 -6
- data/lib/rndk/core/widget.rb +207 -191
- data/lib/rndk/core/widget_bind.rb +108 -0
- data/lib/rndk/dialog.rb +88 -56
- data/lib/rndk/entry.rb +79 -64
- data/lib/rndk/fscale.rb +38 -20
- data/lib/rndk/fslider.rb +38 -23
- data/lib/rndk/graph.rb +92 -53
- data/lib/rndk/itemlist.rb +80 -62
- data/lib/rndk/label.rb +111 -77
- data/lib/rndk/radio.rb +138 -128
- data/lib/rndk/scale.rb +123 -122
- data/lib/rndk/scroll.rb +444 -391
- data/lib/rndk/scroller.rb +21 -21
- data/lib/rndk/slider.rb +149 -140
- data/lib/rndk/template.rb +74 -61
- data/lib/rndk/version.rb +1 -1
- data/lib/rndk/viewer.rb +499 -298
- metadata +8 -14
- data/demos/fileview.rb +0 -141
- data/lib/rndk/dscale.rb +0 -13
- data/lib/rndk/fselect.rb +0 -938
- data/lib/rndk/histogram.rb +0 -412
- data/lib/rndk/marquee.rb +0 -244
- data/lib/rndk/matrix.rb +0 -1189
- data/lib/rndk/mentry.rb +0 -619
- data/lib/rndk/menu.rb +0 -478
- data/lib/rndk/selection.rb +0 -630
- data/lib/rndk/swindow.rb +0 -766
- data/lib/rndk/uscale.rb +0 -14
- data/lib/rndk/uslider.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fbd239767ebd76e2ead3ac2be92d8324061ddef
|
4
|
+
data.tar.gz: 4c0bd5d00c3968a50922c5765522e61d9cc58539
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
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
|
data/demos/appointment.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
-
#
|
4
|
-
#
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
#
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
96
|
-
|
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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
-
|
150
|
+
# Destroy the entry and set the marker.
|
151
|
+
description = entry.info
|
152
|
+
entry.destroy
|
153
|
+
calendar.draw
|
106
154
|
|
107
|
-
|
155
|
+
# Set the marker.
|
156
|
+
calendar.set_marker(calendar.day, calendar.month, calendar.year, marker)
|
108
157
|
|
109
|
-
|
110
|
-
|
158
|
+
# Keep the marker.
|
159
|
+
info.appointment << OpenStruct.new
|
160
|
+
current = info.count
|
111
161
|
|
112
|
-
|
113
|
-
|
114
|
-
|
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
|
-
|
117
|
-
|
169
|
+
# Redraw the calendar.
|
170
|
+
calendar.draw
|
171
|
+
return false
|
172
|
+
end
|
118
173
|
|
119
|
-
|
120
|
-
|
174
|
+
# This removes a marker from the calendar.
|
175
|
+
def remove_calendar_mark(calendar, info)
|
121
176
|
|
122
|
-
|
123
|
-
|
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
|
-
|
126
|
-
|
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
|
-
|
134
|
-
|
135
|
-
|
189
|
+
# Redraw the calendar.
|
190
|
+
calendar.draw
|
191
|
+
return false
|
192
|
+
end
|
136
193
|
|
137
|
-
|
138
|
-
|
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
|
-
#
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
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
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
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
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
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
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
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
|
-
|
314
|
-
|
268
|
+
screen.popup_label msg
|
269
|
+
end
|
315
270
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
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
|
-
|
336
|
-
|
279
|
+
appointment_info = OpenStruct.new
|
280
|
+
appointment_info.count = 0
|
281
|
+
appointment_info.appointment = []
|
337
282
|
|
338
|
-
|
339
|
-
calendar.activate
|
283
|
+
readAppointmentFile(filename, appointment_info)
|
340
284
|
|
341
|
-
|
342
|
-
|
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
|
-
|
345
|
-
RNDK::Screen.
|
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
|
-
|
351
|
-
|
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.
|
335
|
+
RNDK::Screen.finish
|
356
336
|
|
357
337
|
puts e
|
358
338
|
puts e.inspect
|