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
@@ -1,766 +0,0 @@
1
- require 'rndk'
2
-
3
- module RNDK
4
- # TODO This Widget's very buggy! Somehow improve it later!
5
- class SWINDOW < Widget
6
- def initialize(rndkscreen, xplace, yplace, height, width, title,
7
- save_lines, box, shadow)
8
- super()
9
- parent_width = Ncurses.getmaxx(rndkscreen.window)
10
- parent_height = Ncurses.getmaxy(rndkscreen.window)
11
- box_width = width
12
- box_height = height
13
- bindings = {
14
- RNDK::BACKCHAR => Ncurses::KEY_PPAGE,
15
- 'b' => Ncurses::KEY_PPAGE,
16
- 'B' => Ncurses::KEY_PPAGE,
17
- RNDK::FORCHAR => Ncurses::KEY_NPAGE,
18
- ' ' => Ncurses::KEY_NPAGE,
19
- 'f' => Ncurses::KEY_NPAGE,
20
- 'F' => Ncurses::KEY_NPAGE,
21
- '|' => Ncurses::KEY_HOME,
22
- '$' => Ncurses::KEY_END,
23
- }
24
-
25
- self.set_box(box)
26
-
27
- # If the height is a negative value, the height will be
28
- # ROWS-height, otherwise the height will be the given height.
29
- box_height = RNDK.setWidgetDimension(parent_height, height, 0)
30
-
31
- # If the width is a negative value, the width will be
32
- # COLS-width, otherwise the widget will be the given width.
33
- box_width = RNDK.setWidgetDimension(parent_width, width, 0)
34
- box_width = self.set_title(title, box_width)
35
-
36
- # Set the box height.
37
- box_height += @title_lines + 1
38
-
39
- # Make sure we didn't extend beyond the dimensions of the window.
40
- box_width = [box_width, parent_width].min
41
- box_height = [box_height, parent_height].min
42
-
43
- # Set the rest of the variables.
44
- @title_adj = @title_lines + 1
45
-
46
- # Rejustify the x and y positions if we need to.
47
- xtmp = [xplace]
48
- ytmp = [yplace]
49
- RNDK.alignxy(rndkscreen.window, xtmp, ytmp, box_width, box_height)
50
- xpos = xtmp[0]
51
- ypos = ytmp[0]
52
-
53
- # Make the scrolling window.
54
- @win = Ncurses.newwin(box_height, box_width, ypos, xpos)
55
- if @win.nil?
56
- self.destroy
57
- return nil
58
- end
59
- Ncurses.keypad(@win, true)
60
-
61
- # Make the field window
62
- @field_win = Ncurses.subwin(@win,
63
- box_height - @title_lines - 2,
64
- box_width - 2,
65
- ypos + @title_lines + 1,
66
- xpos + 1)
67
- Ncurses.keypad(@field_win, true)
68
-
69
- # Set the rest of the variables
70
- @screen = rndkscreen
71
- @parent = rndkscreen.window
72
- @shadow_win = nil
73
- @box_height = box_height
74
- @box_width = box_width
75
- @view_size = box_height - @title_lines - 2
76
- @current_top = 0
77
- @max_top_line = 0
78
- @left_char = 0
79
- @max_left_char = 0
80
- @list_size = 0
81
- @widest_line = -1
82
- @save_lines = save_lines
83
- @accepts_focus = true
84
- @input_window = @win
85
- @shadow = shadow
86
-
87
- if !self.createList(save_lines)
88
- self.destroy
89
- return nil
90
- end
91
-
92
- # Do we need to create a shadow?
93
- if shadow
94
- @shadow_win = Ncurses.newwin(box_height, box_width,
95
- ypos + 1, xpos + 1)
96
- end
97
-
98
- # Create the key bindings
99
- bindings.each do |from, to|
100
- self.bind(:swindow, from, :getc, to)
101
- end
102
-
103
- # Register this baby.
104
- rndkscreen.register(:swindow, self)
105
- end
106
-
107
- # This sets the lines and the box attribute of the scrolling window.
108
- def set(list, lines, box)
109
- self.setContents(list, lines)
110
- self.set_box(box)
111
- end
112
-
113
- def setupLine(list, x)
114
- list_len = []
115
- list_pos = []
116
- @list[x] = RNDK.char2Chtype(list, list_len, list_pos)
117
- @list_len[x] = list_len[0]
118
- @list_pos[x] = RNDK.justifyString(@box_width, list_len[0], list_pos[0])
119
- @widest_line = [@widest_line, @list_len[x]].max
120
- end
121
-
122
- # This sets all the lines inside the scrolling window.
123
- def setContents(list, list_size)
124
- # First let's clean all the lines in the window.
125
- self.clean
126
- self.createList(list_size)
127
-
128
- # Now let's set all the lines inside the window.
129
- (0...list_size).each do |x|
130
- self.setupLine(list[x], x)
131
- end
132
-
133
- # Set some more important members of the scrolling window.
134
- @list_size = list_size
135
- @max_top_line = @list_size - @view_size
136
- @max_top_line = [@max_top_line, 0].max
137
- @max_left_char = @widest_line - (@box_width - 2)
138
- @current_top = 0
139
- @left_char = 0
140
- end
141
-
142
- def getContents(size)
143
- size << @list_size
144
- return @list
145
- end
146
-
147
- def freeLine(x)
148
- # if x < @list_size
149
- # @list[x] = 0
150
- # end
151
- end
152
-
153
- # This adds a line to the scrolling window.
154
- def add(list, insert_pos)
155
- # If we are at the maximum number of save lines erase the first
156
- # position and bump everything up one spot
157
- if @list_size == @save_lines and @list_size > 0
158
- @list = @list[1..-1]
159
- @list_pos = @list_pos[1..-1]
160
- @list_len = @list_len[1..-1]
161
- @list_size -= 1
162
- end
163
-
164
- # Determine where the line is being added.
165
- if insert_pos == RNDK::TOP
166
- # We need to 'bump' everything down one line...
167
- @list = [@list[0]] + @list
168
- @list_pos = [@list_pos[0]] + @list_pos
169
- @list_len = [@list_len[0]] + @list_len
170
-
171
- # Add it into the scrolling window.
172
- self.setupLine(list, 0)
173
-
174
- # set some variables.
175
- @current_top = 0
176
- if @list_size < @save_lines
177
- @list_size += 1
178
- end
179
-
180
- # Set the maximum top line.
181
- @max_top_line = @list_size - @view_size
182
- @max_top_line = [@max_top_line, 0].max
183
-
184
- @max_left_char = @widest_line - (@box_width - 2)
185
- else
186
- # Add to the bottom.
187
- @list += ['']
188
- @list_pos += [0]
189
- @list_len += [0]
190
- self.setupLine(list, @list_size)
191
-
192
- @max_left_char = @widest_line - (@box_width - 2)
193
-
194
- # Increment the item count and zero out the next row.
195
- if @list_size < @save_lines
196
- @list_size += 1
197
- self.freeLine(@list_size)
198
- end
199
-
200
- # Set the maximum top line.
201
- if @list_size <= @view_size
202
- @max_top_line = 0
203
- @current_top = 0
204
- else
205
- @max_top_line = @list_size - @view_size
206
- @current_top = @max_top_line
207
- end
208
- end
209
-
210
- # Draw in the list.
211
- self.drawList(@box)
212
- end
213
-
214
- # This jumps to a given line.
215
- def jumpToLine(line)
216
- # Make sure the line is in bounds.
217
- if line == RNDK::BOTTOM || line >= @list_size
218
- # We are moving to the last page.
219
- @current_top = @list_size - @view_size
220
- elsif line == TOP || line <= 0
221
- # We are moving to the top of the page.
222
- @current_top = 0
223
- else
224
- # We are moving in the middle somewhere.
225
- if @view_size + line < @list_size
226
- @current_top = line
227
- else
228
- @current_top = @list_size - @view_size
229
- end
230
- end
231
-
232
- # A little sanity check to make sure we don't do something silly
233
- if @current_top < 0
234
- @current_top = 0
235
- end
236
-
237
- # Redraw the window.
238
- self.draw(@box)
239
- end
240
-
241
- # This removes all the lines inside the scrolling window.
242
- def clean
243
- # Clean up the memory used...
244
- (0...@list_size).each do |x|
245
- self.freeLine(x)
246
- end
247
-
248
- # Reset some variables.
249
- @list_size = 0
250
- @max_left_char = 0
251
- @widest_line = 0
252
- @current_top = 0
253
- @max_top_line = 0
254
-
255
- # Redraw the window.
256
- self.draw(@box)
257
- end
258
-
259
- # This trims lines from the scrolling window.
260
- def trim(begin_line, end_line)
261
- # Check the value of begin_line
262
- if begin_line < 0
263
- start = 0
264
- elsif begin_line >= @list_size
265
- start = @list_size - 1
266
- else
267
- start = begin_line
268
- end
269
-
270
- # Check the value of end_line
271
- if end_line < 0
272
- finish = 0
273
- elsif end_line >= @list_size
274
- finish = @list_size - 1
275
- else
276
- finish = end_line
277
- end
278
-
279
- # Make sure the start is lower than the end.
280
- if start > finish
281
- return
282
- end
283
-
284
- # Start nuking elements from the window
285
- (start..finish).each do |x|
286
- self.freeLine(x)
287
-
288
- if x < list_size - 1
289
- @list[x] = @list[x + 1]
290
- @list_pos[x] = @list_pos[x + 1]
291
- @list_len[x] = @list_len[x + 1]
292
- end
293
- end
294
-
295
- # Adjust the item count correctly.
296
- @list_size = @list_size - (end_line - begin_line) - 1
297
-
298
- # Redraw the window.
299
- self.draw(@box)
300
- end
301
-
302
- # This allows the user to play inside the scrolling window.
303
- def activate(actions)
304
- # Draw the scrolling list.
305
- self.draw(@box)
306
-
307
- if actions.nil? || actions.size == 0
308
- while true
309
- input = self.getch([])
310
-
311
- # inject the character into the widget.
312
- self.inject(input)
313
- if @exit_type != :EARLY_EXIT
314
- return
315
- end
316
- end
317
- else
318
- #Inject each character one at a time
319
- actions.each do |action|
320
- self.inject(action)
321
- if @exit_type != :EARLY_EXIT
322
- return
323
- end
324
- end
325
- end
326
-
327
- # Set the exit type and return.
328
- self.set_exit_type(0)
329
- end
330
-
331
- # This injects a single character into the widget.
332
- def inject(input)
333
- pp_return = 1
334
- ret = -1
335
- complete = false
336
-
337
- # Set the exit type.
338
- self.set_exit_type(0)
339
-
340
- # Draw the window....
341
- self.draw(@box)
342
-
343
- # Check if there is a pre-process function to be called.
344
- unless @pre_process_func.nil?
345
- # Call the pre-process function.
346
- pp_return = @pre_process_func.call(:swindow, self,
347
- @pre_process_data, input)
348
- end
349
-
350
- # Should we continue?
351
- if pp_return != 0
352
- # Check for a key binding.
353
- if self.checkBind(:swindow, input)
354
- complete = true
355
- else
356
- case input
357
- when Ncurses::KEY_UP
358
- if @current_top > 0
359
- @current_top -= 1
360
- else
361
- RNDK.beep
362
- end
363
- when Ncurses::KEY_DOWN
364
- if @current_top >= 0 && @current_top < @max_top_line
365
- @current_top += 1
366
- else
367
- RNDK.beep
368
- end
369
- when Ncurses::KEY_RIGHT
370
- if @left_char < @max_left_char
371
- @left_char += 1
372
- else
373
- RNDK.beep
374
- end
375
- when Ncurses::KEY_LEFT
376
- if @left_char > 0
377
- @left_char -= 1
378
- else
379
- RNDK.beep
380
- end
381
- when Ncurses::KEY_PPAGE
382
- if @current_top != 0
383
- if @current_top >= @view_size
384
- @current_top = @current_top - (@view_size - 1)
385
- else
386
- @current_top = 0
387
- end
388
- else
389
- RNDK.beep
390
- end
391
- when Ncurses::KEY_NPAGE
392
- if @current_top != @max_top_line
393
- if @current_top + @view_size < @max_top_line
394
- @current_top = @current_top + (@view_size - 1)
395
- else
396
- @current_top = @max_top_line
397
- end
398
- else
399
- RNDK.beep
400
- end
401
- when Ncurses::KEY_HOME
402
- @left_char = 0
403
- when Ncurses::KEY_END
404
- @left_char = @max_left_char + 1
405
- when 'g'.ord, '1'.ord, '<'.ord
406
- @current_top = 0
407
- when 'G'.ord, '>'.ord
408
- @current_top = @max_top_line
409
- when 'l'.ord, 'L'.ord
410
- self.loadInformation
411
- when 's'.ord, 'S'.ord
412
- self.saveInformation
413
- when RNDK::KEY_TAB, RNDK::KEY_RETURN, Ncurses::KEY_ENTER
414
- self.set_exit_type(input)
415
- ret = 1
416
- complete = true
417
- when RNDK::KEY_ESC
418
- self.set_exit_type(input)
419
- complete = true
420
- when Ncurses::ERR
421
- self.set_exit_type(input)
422
- complete = true
423
- when RNDK::REFRESH
424
- @screen.erase
425
- @screen.refresh
426
- end
427
- end
428
-
429
- # Should we call a post-process?
430
- if !complete && !(@post_process_func.nil?)
431
- @post_process_func.call(:swindow, self, @post_process_data, input)
432
- end
433
- end
434
-
435
- if !complete
436
- self.drawList(@box)
437
- self.set_exit_type(0)
438
- end
439
-
440
- @return_data = ret
441
- return ret
442
- end
443
-
444
- # This moves the window field to the given location.
445
- # Inherited
446
- # def move(xplace, yplace, relative, refresh_flag)
447
- # end
448
-
449
- # This function draws the swindow window widget.
450
- def draw(box)
451
- # Do we need to draw in the shadow.
452
- unless @shadow_win.nil?
453
- Draw.drawShadow(@shadow_win)
454
- end
455
-
456
- # Box the widget if needed
457
- if box
458
- Draw.drawObjBox(@win, self)
459
- end
460
-
461
- self.drawTitle(@win)
462
-
463
- Ncurses.wrefresh @win
464
-
465
- # Draw in the list.
466
- self.drawList(box)
467
- end
468
-
469
- # This draws in the contents of the scrolling window
470
- def drawList(box)
471
- # Determine the last line to draw.
472
- if @list_size < @view_size
473
- last_line = @list_size
474
- else
475
- last_line = @view_size
476
- end
477
-
478
- # Erase the scrolling window.
479
- Ncurses.werase @field_win
480
-
481
- # Start drawing in each line.
482
- (0...last_line).each do |x|
483
- screen_pos = @list_pos[x + @current_top] - @left_char
484
-
485
- # Write in the correct line.
486
- if screen_pos >= 0
487
- Draw.writeChtype(@field_win, screen_pos, x,
488
- @list[x + @current_top], RNDK::HORIZONTAL, 0,
489
- @list_len[x + @current_top])
490
- else
491
- Draw.writeChtype(@field_win, 0, x, @list[x + @current_top],
492
- RNDK::HORIZONTAL, @left_char - @list_pos[x + @current_top],
493
- @list_len[x + @current_top])
494
- end
495
- end
496
-
497
- Ncurses.wrefresh @field_win
498
- end
499
-
500
- # This sets the background attribute of the widget.
501
- def set_bg_attrib(attrib)
502
- Ncurses.wbkgd(@win, attrib)
503
- Ncurses.wbkgd(@field_win, attrib)
504
- end
505
-
506
- # Free any storage associated with the info-list.
507
- def destroyInfo
508
- @list = []
509
- @list_pos = []
510
- @list_len = []
511
- end
512
-
513
- # This function destroys the scrolling window widget.
514
- def destroy
515
- self.destroyInfo
516
-
517
- self.cleanTitle
518
-
519
- # Delete the windows.
520
- RNDK.window_delete(@shadow_win)
521
- RNDK.window_delete(@field_win)
522
- RNDK.window_delete(@win)
523
-
524
- # Clean the key bindings.
525
- self.clean_bindings(:swindow)
526
-
527
- # Unregister this object.
528
- RNDK::Screen.unregister(:swindow, self)
529
- end
530
-
531
- # This function erases the scrolling window widget.
532
- def erase
533
- if self.valid_widget?
534
- RNDK.window_erase(@win)
535
- RNDK.window_erase(@shadow_win)
536
- end
537
- end
538
-
539
- # This execs a command and redirects the output to the scrolling window.
540
- def exec(command, insert_pos)
541
- count = -1
542
- Ncurses.endwin
543
-
544
- # Try to open the command.
545
- # XXX This especially needs exception handling given how Ruby
546
- # implements popen
547
- unless (ps = IO.popen(command.split, 'r')).nil?
548
- # Start reading.
549
- until (temp = ps.gets).nil?
550
- if temp.size != 0 && temp[-1] == '\n'
551
- temp = temp[0...-1]
552
- end
553
- # Add the line to the scrolling window.
554
- self.add(temp, insert_pos)
555
- count += 1
556
- end
557
-
558
- # Close the pipe
559
- ps.close
560
- end
561
- return count
562
- end
563
-
564
- def showMessage2(msg, msg2, filename)
565
- mesg = [
566
- msg,
567
- msg2,
568
- "<C>(%s)" % [filename],
569
- ' ',
570
- '<C> Press any key to continue.',
571
- ]
572
- @screen.popup_label(mesg, mesg.size)
573
- end
574
-
575
- # This function allows the user to dump the information from the
576
- # scrolling window to a file.
577
- def saveInformation
578
- # Create the entry field to get the filename.
579
- entry = RNDK::Entry.new(@screen, RNDK::CENTER, RNDK::CENTER,
580
- '<C></B/5>Enter the filename of the save file.',
581
- 'Filename: ', Ncurses::A_NORMAL, '_'.ord, :MIXED,
582
- 20, 1, 256, true, false)
583
-
584
- # Get the filename.
585
- filename = entry.activate([])
586
-
587
- # Did they hit escape?
588
- if entry.exit_type == :ESCAPE_HIT
589
- # Popup a message.
590
- mesg = [
591
- '<C></B/5>Save Canceled.',
592
- '<C>Escape hit. Scrolling window information not saved.',
593
- ' ',
594
- '<C>Press any key to continue.'
595
- ]
596
- @screen.popup_label(mesg, 4)
597
-
598
- # Clean up and exit.
599
- entry.destroy
600
- end
601
-
602
- # Write the contents of the scrolling window to the file.
603
- lines_saved = self.dump(filename)
604
-
605
- # Was the save successful?
606
- if lines_saved == -1
607
- # Nope, tell 'em
608
- self.showMessage2('<C></B/16>Error', '<C>Could not save to the file.',
609
- filename)
610
- else
611
- # Yep, let them know how many lines were saved.
612
- self.showMessage2('<C></B/5>Save Successful',
613
- '<C>There were %d lines saved to the file' % [lines_saved],
614
- filename)
615
- end
616
-
617
- # Clean up and exit.
618
- entry.destroy
619
- @screen.erase
620
- @screen.draw
621
- end
622
-
623
- # This function allows the user to load new information into the scrolling
624
- # window.
625
- def loadInformation
626
- # Create the file selector to choose the file.
627
- fselect = RNDK::FSELECT.new(@screen, RNDK::CENTER, RNDK::CENTER, 20, 55,
628
- '<C>Load Which File', 'FIlename', Ncurses::A_NORMAL, '.',
629
- Ncurses::A_REVERSE, '</5>', '</48>', '</N>', '</N>', true, false)
630
-
631
- # Get the filename to load.
632
- filename = fselect.activate([])
633
-
634
- # Make sure they selected a file.
635
- if fselect.exit_type == :ESCAPE_HIT
636
- # Popup a message.
637
- mesg = [
638
- '<C></B/5>Load Canceled.',
639
- ' ',
640
- '<C>Press any key to continue.',
641
- ]
642
- @screen.popup_label(mesg, 3)
643
-
644
- # Clean up and exit
645
- fselect.destroy
646
- return
647
- end
648
-
649
- # Copy the filename and destroy the file selector.
650
- filename = fselect.pathname
651
- fselect.destroy
652
-
653
- # Maybe we should check before nuking all the information in the
654
- # scrolling window...
655
- if @list_size > 0
656
- # Create the dialog message.
657
- mesg = [
658
- '<C></B/5>Save Information First',
659
- '<C>There is information in the scrolling window.',
660
- '<C>Do you want to save it to a file first?',
661
- ]
662
- button = ['(Yes)', '(No)']
663
-
664
- # Create the dialog widget.
665
- dialog = RNDK::DIALOG.new(@screen, RNDK::CENTER, RNDK::CENTER,
666
- mesg, 3, button, 2, Ncurses.COLOR_PAIR(2) | Ncurses::A_REVERSE,
667
- true, true, false)
668
-
669
- # Activate the widet.
670
- answer = dialog.activate([])
671
- dialog.destroy
672
-
673
- # Check the answer.
674
- if (answer == -1 || answer == 0)
675
- # Save the information.
676
- self.saveInformation
677
- end
678
- end
679
-
680
- # Open the file and read it in.
681
- f = File.open(filename)
682
- file_info = f.readlines.map do |line|
683
- if line.size > 0 && line[-1] == "\n"
684
- line[0...-1]
685
- else
686
- line
687
- end
688
- end.compact
689
-
690
- # TODO error handling
691
- # if (lines == -1)
692
- # {
693
- # /* The file read didn't work. */
694
- # showMessage2 (swindow,
695
- # "<C></B/16>Error",
696
- # "<C>Could not read the file",
697
- # filename);
698
- # freeChar (filename);
699
- # return;
700
- # }
701
-
702
- # Clean out the scrolling window.
703
- self.clean
704
-
705
- # Set the new information in the scrolling window.
706
- self.set(file_info, file_info.size, @box)
707
- end
708
-
709
- # This actually dumps the information from the scrolling window to a file.
710
- def dump(filename)
711
- # Try to open the file.
712
- #if ((outputFile = fopen (filename, "w")) == 0)
713
- #{
714
- # return -1;
715
- #}
716
- output_file = File.new(filename, 'w')
717
-
718
- # Start writing out the file.
719
- @list.each do |item|
720
- raw_line = RNDK.chtype2Char(item)
721
- output_file << "%s\n" % raw_line
722
- end
723
-
724
- # Close the file and return the number of lines written.
725
- output_file.close
726
- return @list_size
727
- end
728
-
729
- def focus
730
- self.draw(@box)
731
- end
732
-
733
- def unfocus
734
- self.draw(@box)
735
- end
736
-
737
- def createList(list_size)
738
- status = false
739
-
740
- if list_size >= 0
741
- new_list = []
742
- new_pos = []
743
- new_len = []
744
-
745
- status = true
746
- self.destroyInfo
747
-
748
- @list = new_list
749
- @list_pos = new_pos
750
- @list_len = new_len
751
- else
752
- self.destroyInfo
753
- status = false
754
- end
755
- return status
756
- end
757
-
758
- def position
759
- super(@win)
760
- end
761
-
762
- def object_type
763
- :swindow
764
- end
765
- end
766
- end