rndk 0.1.0 → 0.2.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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.yardopts +1 -0
  4. data/README.md +61 -42
  5. data/demos/appointment.rb +2 -2
  6. data/demos/clock.rb +1 -1
  7. data/demos/fileview.rb +0 -0
  8. data/examples/01-hello-world.rb +1 -1
  9. data/examples/02-colors.rb +1 -1
  10. data/examples/03-markup.rb +6 -4
  11. data/examples/04-quick-widgets.rb +1 -0
  12. data/examples/05-position-widget.rb +1 -1
  13. data/examples/entry.rb +76 -0
  14. data/examples/label.rb +51 -0
  15. data/examples/scroll.rb +68 -42
  16. data/examples/slider.rb +70 -0
  17. data/lib/rndk/alphalist.rb +224 -116
  18. data/lib/rndk/button.rb +4 -2
  19. data/lib/rndk/buttonbox.rb +1 -1
  20. data/lib/rndk/calendar.rb +18 -23
  21. data/lib/rndk/core/draw.rb +0 -30
  22. data/lib/rndk/core/quick_widgets.rb +9 -10
  23. data/lib/rndk/core/utils.rb +6 -6
  24. data/lib/rndk/core/widget.rb +9 -1
  25. data/lib/rndk/dialog.rb +1 -6
  26. data/lib/rndk/dscale.rb +1 -1
  27. data/lib/rndk/entry.rb +266 -116
  28. data/lib/rndk/fscale.rb +1 -1
  29. data/lib/rndk/fselect.rb +13 -15
  30. data/lib/rndk/fslider.rb +1 -1
  31. data/lib/rndk/graph.rb +1 -1
  32. data/lib/rndk/histogram.rb +1 -1
  33. data/lib/rndk/itemlist.rb +1 -1
  34. data/lib/rndk/label.rb +7 -6
  35. data/lib/rndk/marquee.rb +1 -1
  36. data/lib/rndk/matrix.rb +1 -1
  37. data/lib/rndk/mentry.rb +8 -8
  38. data/lib/rndk/menu.rb +1 -1
  39. data/lib/rndk/radio.rb +1 -1
  40. data/lib/rndk/scale.rb +1 -1
  41. data/lib/rndk/scroll.rb +138 -55
  42. data/lib/rndk/scroller.rb +9 -1
  43. data/lib/rndk/selection.rb +1 -1
  44. data/lib/rndk/slider.rb +123 -42
  45. data/lib/rndk/swindow.rb +10 -10
  46. data/lib/rndk/template.rb +1 -1
  47. data/lib/rndk/uscale.rb +1 -1
  48. data/lib/rndk/uslider.rb +1 -1
  49. data/lib/rndk/version.rb +1 -1
  50. data/lib/rndk/viewer.rb +3 -3
  51. data/rndk.gemspec +1 -1
  52. metadata +7 -3
data/lib/rndk/slider.rb CHANGED
@@ -1,12 +1,90 @@
1
1
  require 'rndk'
2
2
 
3
3
  module RNDK
4
- class SLIDER < RNDK::Widget
5
- def initialize(rndkscreen, xplace, yplace, title, label, filler,
6
- field_width, start, low, high, inc, fast_inc, box, shadow)
4
+
5
+ # Visual slider box with a label.
6
+ #
7
+ # ## Keybindings
8
+ #
9
+ # Down Arrow:: Decrements the field by the normal decrement value.
10
+ # Up Arrow:: Increments the field by the normal increment value.
11
+ # u:: Increments the field by the normal increment value.
12
+ # Prev Page:: Decrements the field by the accelerated decrement value.
13
+ # U:: Decrements the field by the accelerated decrement value.
14
+ # Ctrl-B:: Decrements the field by the accelerated decrement value.
15
+ # Next Page:: Increments the field by the accelerated increment value.
16
+ # D:: Increments the field by the accelerated increment value.
17
+ # Ctrl-F:: Increments the field by the accelerated increment value.
18
+ # Home:: Sets the value to the low value.
19
+ # g:: Sets the value to the low value.
20
+ # End:: Sets the value to the high value.
21
+ # G:: Sets the value to the high value.
22
+ # $:: Sets the value to the high value.
23
+ # Return:: Exits the widget and returns the current value. This also sets the widget data `exit_type` to `:NORMAL`.
24
+ # Tab:: Exits the widget and returns the current value. This also sets the widget data `exit_type` to `:NORMAL`.
25
+ # Escape:: Exits the widget and returns `nil`. Also sets the widget data `exit_type` to `:ESCAPE_HIT`.
26
+ # Ctrl-L:: Refreshes the screen.
27
+ #
28
+ # If the cursor is not pointing to the field's value,
29
+ # the following key bindings apply.
30
+ #
31
+ # You may use the left/right arrows to move the cursor
32
+ # onto the field's value and modify it by typing characters
33
+ # to replace the digits and sign.
34
+ #
35
+ # Left Arrow:: Decrements the scale by the normal value.
36
+ # Right Arrow:: Increments the scale by the normal value.
37
+ # d:: Decrements the scale by the normal value.
38
+ # D:: Increments the scale by the accelerated value.
39
+ # -:: Decrements the scale by the normal value.
40
+ # +:: Increments the scale by the normal value.
41
+ # 0:: Sets the scale to the low value.
42
+ #
43
+ class Slider < Widget
44
+
45
+ # Creates a new Slider Widget.
46
+ #
47
+ # * `xplace` is the x position - can be an integer or
48
+ # `RNDK::LEFT`, `RNDK::RIGHT`, `RNDK::CENTER`.
49
+ # * `yplace` is the y position - can be an integer or
50
+ # `RNDK::TOP`, `RNDK::BOTTOM`, `RNDK::CENTER`.
51
+ # * `title` can be more than one line - just split them
52
+ # with `\n`s.
53
+ # * `label` is the label of the slider field.
54
+ # * `filler` is the character to draw the slider bar. You
55
+ # can combine it with colors too - use the pipe ('|')
56
+ # operator to combine Ncurses attributes with RNDK Colors.
57
+ # * `field_width` is the width of the field. It it's 0,
58
+ # will be created with full width of the screen.
59
+ # If it's a negative value, will create with full width
60
+ # minus that value.
61
+ # * `start` is the initial value of the widget.
62
+ # * `low`/`high` are the minimum and maximum values of
63
+ # the slider.
64
+ # * `inc` is the increment value.
65
+ # * `fast_inc` is the accelerated increment value.
66
+ # * `box` if the Widget is drawn with a box outside it.
67
+ # * `shadow` turns on/off the shadow around the Widget.
68
+ #
69
+ def initialize(rndkscreen,
70
+ xplace,
71
+ yplace,
72
+ title,
73
+ label,
74
+ filler,
75
+ field_width,
76
+ start,
77
+ low,
78
+ high,
79
+ inc,
80
+ fast_inc,
81
+ box,
82
+ shadow)
7
83
  super()
8
- parent_width = Ncurses.getmaxx(rndkscreen.window)
84
+
85
+ parent_width = Ncurses.getmaxx(rndkscreen.window)
9
86
  parent_height = Ncurses.getmaxy(rndkscreen.window)
87
+
10
88
  bindings = {
11
89
  'u' => Ncurses::KEY_UP,
12
90
  'U' => Ncurses::KEY_PPAGE,
@@ -132,16 +210,20 @@ module RNDK
132
210
 
133
211
  # Setup the key bindings.
134
212
  bindings.each do |from, to|
135
- self.bind(:SLIDER, from, :getc, to)
213
+ self.bind(:slider, from, :getc, to)
136
214
  end
137
215
 
138
- rndkscreen.register(:SLIDER, self)
216
+ rndkscreen.register(:slider, self)
139
217
  end
140
218
 
141
- # This allows the person to use the widget's data field.
142
- def activate(actions)
143
- # Draw the widget.
144
- self.draw(@box)
219
+ # Activates the Widget, letting the user interact with it.
220
+ #
221
+ # `actions` is an Array of characters. If it's non-null,
222
+ # will #inject each char on it into the Widget.
223
+ #
224
+ # @return The current value of the slider.
225
+ def activate(actions=[])
226
+ self.draw @box
145
227
 
146
228
  if actions.nil? || actions.size == 0
147
229
  while true
@@ -165,7 +247,7 @@ module RNDK
165
247
 
166
248
  # Set the exit type and return.
167
249
  self.set_exit_type(0)
168
- return -1
250
+ return nil
169
251
  end
170
252
 
171
253
  # Check if the value lies outside the low/high range. If so, force it in.
@@ -260,10 +342,10 @@ module RNDK
260
342
  temp[col] = input.chr
261
343
  elsif input == Ncurses::KEY_BACKSPACE
262
344
  # delete the char before the cursor
263
- modify = RNDK::SLIDER.removeChar(temp, col - 1)
345
+ modify = RNDK::Slider.removeChar(temp, col - 1)
264
346
  elsif input == Ncurses::KEY_DC
265
347
  # delete the char at the cursor
266
- modify = RNDK::SLIDER.removeChar(temp, col)
348
+ modify = RNDK::Slider.removeChar(temp, col)
267
349
  else
268
350
  modify = false
269
351
  end
@@ -292,10 +374,10 @@ module RNDK
292
374
  end
293
375
  end
294
376
 
295
- # This function injects a single character into the widget.
296
- def inject(input)
377
+ # @see Widget#inject
378
+ def inject input
297
379
  pp_return = 1
298
- ret = -1
380
+ ret = nil
299
381
  complete = false
300
382
 
301
383
  # Set the exit type.
@@ -307,14 +389,14 @@ module RNDK
307
389
  # Check if there is a pre-process function to be called.
308
390
  unless @pre_process_func.nil?
309
391
  # Call the pre-process function.
310
- pp_return = @pre_process_func.call(:SLIDER, self,
392
+ pp_return = @pre_process_func.call(:slider, self,
311
393
  @pre_process_data, input)
312
394
  end
313
395
 
314
396
  # Should we continue?
315
397
  if pp_return != 0
316
398
  # Check for a key binding.
317
- if self.checkBind(:SLIDER, input)
399
+ if self.checkBind(:slider, input)
318
400
  complete = true
319
401
  else
320
402
  case input
@@ -323,13 +405,13 @@ module RNDK
323
405
  when Ncurses::KEY_RIGHT
324
406
  self.setEditPosition(@field_edit - 1)
325
407
  when Ncurses::KEY_DOWN
326
- @current = RNDK::SLIDER.Decrement(@current, @inc)
408
+ @current = RNDK::Slider.Decrement(@current, @inc)
327
409
  when Ncurses::KEY_UP
328
- @current = RNDK::SLIDER.Increment(@current, @inc)
410
+ @current = RNDK::Slider.Increment(@current, @inc)
329
411
  when Ncurses::KEY_PPAGE
330
- @current = RNDK::SLIDER.Increment(@current, @fastinc)
412
+ @current = RNDK::Slider.Increment(@current, @fastinc)
331
413
  when Ncurses::KEY_NPAGE
332
- @current = RNDK::SLIDER.Decrement(@current, @fastinc)
414
+ @current = RNDK::Slider.Decrement(@current, @fastinc)
333
415
  when Ncurses::KEY_HOME
334
416
  @current = @low
335
417
  when Ncurses::KEY_END
@@ -374,7 +456,7 @@ module RNDK
374
456
 
375
457
  # Should we call a post-process?
376
458
  if !complete && !(@post_process_func.nil?)
377
- @post_process_func.call(:SLIDER, self, @post_process_data, input)
459
+ @post_process_func.call(:slider, self, @post_process_data, input)
378
460
  end
379
461
  end
380
462
 
@@ -387,26 +469,25 @@ module RNDK
387
469
  return ret
388
470
  end
389
471
 
390
- # This moves the widget's data field to the given location.
472
+ # @see Widget#move
391
473
  def move(xplace, yplace, relative, refresh_flag)
392
474
  windows = [@win, @label_win, @field_win, @shadow_win]
393
475
 
394
476
  self.move_specific(xplace, yplace, relative, refresh_flag, windows, [])
395
477
  end
396
478
 
397
- # This function draws the widget.
398
- def draw(box)
479
+ # Draws the Widget on the Screen.
480
+ #
481
+ # If `box` is true, it is drawn with a box.
482
+ def draw box
483
+
399
484
  # Draw the shadow.
400
- unless @shadow_win.nil?
401
- Draw.drawShadow(@shadow_win)
402
- end
485
+ Draw.drawShadow(@shadow_win) unless @shadow_win.nil?
403
486
 
404
487
  # Box the widget if asked.
405
- if box
406
- Draw.drawObjBox(@win, self)
407
- end
488
+ Draw.drawObjBox(@win, self) if box
408
489
 
409
- self.drawTitle(@win)
490
+ self.drawTitle @win
410
491
 
411
492
  # Draw the label.
412
493
  unless @label_win.nil?
@@ -450,7 +531,7 @@ module RNDK
450
531
  Ncurses.wbkgd(@label_win, attrib) unless @label_win.nil?
451
532
  end
452
533
 
453
- # This function destroys the widget.
534
+ # @see Widget#destroy
454
535
  def destroy
455
536
  self.cleanTitle
456
537
  @label = []
@@ -462,19 +543,19 @@ module RNDK
462
543
  RNDK.window_delete(@win)
463
544
 
464
545
  # Clean the key bindings.
465
- self.clean_bindings(:SLIDER)
546
+ self.clean_bindings(:slider)
466
547
 
467
548
  # Unregister this object.
468
- RNDK::Screen.unregister(:SLIDER, self)
549
+ RNDK::Screen.unregister(:slider, self)
469
550
  end
470
551
 
471
- # This function erases the widget from the screen.
552
+ # @see Widget#erase
472
553
  def erase
473
554
  if self.valid_widget?
474
- RNDK.window_erase(@label_win)
475
- RNDK.window_erase(@field_win)
476
- RNDK.window_erase(@lwin)
477
- RNDK.window_erase(@shadow_win)
555
+ RNDK.window_erase @label_win
556
+ RNDK.window_erase @field_win
557
+ RNDK.window_erase @lwin
558
+ RNDK.window_erase @shadow_win
478
559
  end
479
560
  end
480
561
 
@@ -539,7 +620,7 @@ module RNDK
539
620
  end
540
621
 
541
622
  def object_type
542
- :SLIDER
623
+ :slider
543
624
  end
544
625
  end
545
626
  end
data/lib/rndk/swindow.rb CHANGED
@@ -2,7 +2,7 @@ require 'rndk'
2
2
 
3
3
  module RNDK
4
4
  # TODO This Widget's very buggy! Somehow improve it later!
5
- class SWINDOW < RNDK::Widget
5
+ class SWINDOW < Widget
6
6
  def initialize(rndkscreen, xplace, yplace, height, width, title,
7
7
  save_lines, box, shadow)
8
8
  super()
@@ -97,11 +97,11 @@ module RNDK
97
97
 
98
98
  # Create the key bindings
99
99
  bindings.each do |from, to|
100
- self.bind(:SWINDOW, from, :getc, to)
100
+ self.bind(:swindow, from, :getc, to)
101
101
  end
102
102
 
103
103
  # Register this baby.
104
- rndkscreen.register(:SWINDOW, self)
104
+ rndkscreen.register(:swindow, self)
105
105
  end
106
106
 
107
107
  # This sets the lines and the box attribute of the scrolling window.
@@ -343,14 +343,14 @@ module RNDK
343
343
  # Check if there is a pre-process function to be called.
344
344
  unless @pre_process_func.nil?
345
345
  # Call the pre-process function.
346
- pp_return = @pre_process_func.call(:SWINDOW, self,
346
+ pp_return = @pre_process_func.call(:swindow, self,
347
347
  @pre_process_data, input)
348
348
  end
349
349
 
350
350
  # Should we continue?
351
351
  if pp_return != 0
352
352
  # Check for a key binding.
353
- if self.checkBind(:SWINDOW, input)
353
+ if self.checkBind(:swindow, input)
354
354
  complete = true
355
355
  else
356
356
  case input
@@ -428,7 +428,7 @@ module RNDK
428
428
 
429
429
  # Should we call a post-process?
430
430
  if !complete && !(@post_process_func.nil?)
431
- @post_process_func.call(:SWINDOW, self, @post_process_data, input)
431
+ @post_process_func.call(:swindow, self, @post_process_data, input)
432
432
  end
433
433
  end
434
434
 
@@ -522,10 +522,10 @@ module RNDK
522
522
  RNDK.window_delete(@win)
523
523
 
524
524
  # Clean the key bindings.
525
- self.clean_bindings(:SWINDOW)
525
+ self.clean_bindings(:swindow)
526
526
 
527
527
  # Unregister this object.
528
- RNDK::Screen.unregister(:SWINDOW, self)
528
+ RNDK::Screen.unregister(:swindow, self)
529
529
  end
530
530
 
531
531
  # This function erases the scrolling window widget.
@@ -576,7 +576,7 @@ module RNDK
576
576
  # scrolling window to a file.
577
577
  def saveInformation
578
578
  # Create the entry field to get the filename.
579
- entry = RNDK::ENTRY.new(@screen, RNDK::CENTER, RNDK::CENTER,
579
+ entry = RNDK::Entry.new(@screen, RNDK::CENTER, RNDK::CENTER,
580
580
  '<C></B/5>Enter the filename of the save file.',
581
581
  'Filename: ', Ncurses::A_NORMAL, '_'.ord, :MIXED,
582
582
  20, 1, 256, true, false)
@@ -760,7 +760,7 @@ module RNDK
760
760
  end
761
761
 
762
762
  def object_type
763
- :SWINDOW
763
+ :swindow
764
764
  end
765
765
  end
766
766
  end
data/lib/rndk/template.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rndk'
2
2
 
3
3
  module RNDK
4
- class TEMPLATE < RNDK::Widget
4
+ class TEMPLATE < Widget
5
5
  def initialize(rndkscreen, xplace, yplace, title, label, plate,
6
6
  overlay, box, shadow)
7
7
  super()
data/lib/rndk/uscale.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rndk/scale'
2
2
 
3
3
  module RNDK
4
- class USCALE < RNDK::SCALE
4
+ class USCALE < SCALE
5
5
  # The original UScale handled unsigned values.
6
6
  # Since Ruby's typing is different this is really just SCALE
7
7
  # but is nice it's nice to have this for compatibility/completeness
data/lib/rndk/uslider.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rndk/slider'
2
2
 
3
3
  module RNDK
4
- class USLIDER < RNDK::SLIDER
4
+ class USLIDER < SLIDER
5
5
  # The original USlider handled unsigned values.
6
6
  # Since Ruby's typing is different this is really just SLIDER
7
7
  # but is nice it's nice to have this for compatibility/completeness
data/lib/rndk/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module RNDK
2
- VERSION="0.1.0"
2
+ VERSION="0.2.0"
3
3
  VERSION_MAJOR = VERSION.split('.')[0]
4
4
  VERSION_MINOR = VERSION.split('.')[1]
5
5
  VERSION_PATCH = VERSION.split('.')[2]
data/lib/rndk/viewer.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rndk'
2
2
 
3
3
  module RNDK
4
- class VIEWER < RNDK::Widget
4
+ class VIEWER < Widget
5
5
  DOWN = 0
6
6
  UP = 1
7
7
 
@@ -520,7 +520,7 @@ module RNDK
520
520
  end
521
521
 
522
522
  # Pop up the entry field.
523
- get_pattern = RNDK::ENTRY.new(screen, RNDK::CENTER, RNDK::CENTER,
523
+ get_pattern = RNDK::Entry.new(screen, RNDK::CENTER, RNDK::CENTER,
524
524
  '', label, Ncurses.COLOR_PAIR(5) | Ncurses::A_BOLD,
525
525
  '.' | Ncurses.COLOR_PAIR(5) | Ncurses::A_BOLD,
526
526
  :MIXED, 10, 0, 256, true, false)
@@ -613,7 +613,7 @@ module RNDK
613
613
  # This pops a little message up on the screen.
614
614
  def popUpLabel(mesg)
615
615
  # Set up variables.
616
- label = RNDK::LABEL.new(@screen, RNDK::CENTER, RNDK::CENTER,
616
+ label = RNDK::Label.new(@screen, RNDK::CENTER, RNDK::CENTER,
617
617
  mesg, mesg.size, true, false)
618
618
 
619
619
  # Draw the label and wait.
data/rndk.gemspec CHANGED
@@ -20,7 +20,7 @@ It means that you'll be able to master the dark arts of text-based
20
20
  applications, easily creating nice apps for the console.
21
21
  END_OF_DESCRIPTION
22
22
 
23
- spec.homepage = "https://github.com/alexdantas/rndk"
23
+ spec.homepage = "http://alexdantas.net/projects/rndk"
24
24
  spec.license = "BSD"
25
25
 
26
26
  spec.files = `git ls-files`.split($/)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rndk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Dantas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-12 00:00:00.000000000 Z
11
+ date: 2013-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi-ncurses
@@ -66,6 +66,7 @@ extensions: []
66
66
  extra_rdoc_files: []
67
67
  files:
68
68
  - ".gitignore"
69
+ - ".yardopts"
69
70
  - COPYING
70
71
  - Gemfile
71
72
  - README.md
@@ -80,7 +81,10 @@ files:
80
81
  - examples/04-quick-widgets.rb
81
82
  - examples/05-position-widget.rb
82
83
  - examples/calendar.rb
84
+ - examples/entry.rb
85
+ - examples/label.rb
83
86
  - examples/scroll.rb
87
+ - examples/slider.rb
84
88
  - lib/rndk.rb
85
89
  - lib/rndk/alphalist.rb
86
90
  - lib/rndk/button.rb
@@ -122,7 +126,7 @@ files:
122
126
  - lib/rndk/version.rb
123
127
  - lib/rndk/viewer.rb
124
128
  - rndk.gemspec
125
- homepage: https://github.com/alexdantas/rndk
129
+ homepage: http://alexdantas.net/projects/rndk
126
130
  licenses:
127
131
  - BSD
128
132
  metadata: {}