rndk 0.0.1 → 0.1.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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/demos/appointment.rb +40 -25
  3. data/demos/clock.rb +22 -11
  4. data/demos/fileview.rb +141 -0
  5. data/examples/01-hello-world.rb +1 -2
  6. data/examples/02-colors.rb +58 -0
  7. data/examples/03-markup.rb +70 -0
  8. data/examples/04-quick-widgets.rb +72 -0
  9. data/examples/05-position-widget.rb +3 -6
  10. data/examples/calendar.rb +104 -0
  11. data/examples/scroll.rb +106 -0
  12. data/lib/rndk/alphalist.rb +14 -14
  13. data/lib/rndk/button.rb +21 -21
  14. data/lib/rndk/buttonbox.rb +18 -18
  15. data/lib/rndk/calendar.rb +333 -240
  16. data/lib/rndk/core/color.rb +136 -0
  17. data/lib/rndk/core/display.rb +23 -12
  18. data/lib/rndk/core/draw.rb +32 -26
  19. data/lib/rndk/core/markup.rb +561 -0
  20. data/lib/rndk/core/quick_widgets.rb +232 -12
  21. data/lib/rndk/core/screen.rb +16 -17
  22. data/lib/rndk/core/utils.rb +143 -0
  23. data/lib/rndk/core/widget.rb +133 -92
  24. data/lib/rndk/dialog.rb +17 -17
  25. data/lib/rndk/entry.rb +21 -21
  26. data/lib/rndk/fselect.rb +16 -16
  27. data/lib/rndk/graph.rb +10 -10
  28. data/lib/rndk/histogram.rb +10 -10
  29. data/lib/rndk/itemlist.rb +20 -20
  30. data/lib/rndk/label.rb +66 -45
  31. data/lib/rndk/marquee.rb +10 -10
  32. data/lib/rndk/matrix.rb +27 -27
  33. data/lib/rndk/mentry.rb +22 -22
  34. data/lib/rndk/menu.rb +14 -14
  35. data/lib/rndk/radio.rb +19 -19
  36. data/lib/rndk/scale.rb +21 -21
  37. data/lib/rndk/scroll.rb +19 -19
  38. data/lib/rndk/scroller.rb +2 -0
  39. data/lib/rndk/selection.rb +20 -20
  40. data/lib/rndk/slider.rb +21 -21
  41. data/lib/rndk/swindow.rb +20 -20
  42. data/lib/rndk/template.rb +21 -21
  43. data/lib/rndk/version.rb +1 -1
  44. data/lib/rndk/viewer.rb +18 -18
  45. data/lib/rndk.rb +99 -777
  46. data/rndk.gemspec +1 -1
  47. metadata +12 -3
@@ -0,0 +1,136 @@
1
+
2
+ module RNDK
3
+
4
+ # The colors that we can print text with.
5
+ #
6
+ # Internally we call Colors attributes - or attribs.
7
+ #
8
+ # ## Usage
9
+ #
10
+ # First of all, you should call Color#init. If your terminal
11
+ # doesn't support colors (come on, at 2010s?) Colors#has_colors?
12
+ # will tell.
13
+ #
14
+ # All Widgets that have an `attrib` argument can use a Color.
15
+ # You call them like this:
16
+ #
17
+ # color = RNDK::Color[:foreground_background]
18
+ #
19
+ # If you want to use your terminal's current default
20
+ # background/foreground, use:
21
+ #
22
+ # color = RNDK::Color[:default_background]
23
+ # color = RNDK::Color[:foreground]
24
+ #
25
+ # ## Examples
26
+ #
27
+ # wb = Color[:white_black]
28
+ # gm = Color[:green_magenta]
29
+ # red = Color[:red]
30
+ # bl = Color[:default_black]
31
+ #
32
+ # ## Developer Notes
33
+ #
34
+ # Color#init creates 80 color pairs.
35
+ #
36
+ module Color
37
+
38
+ # All possible colors on format `:foreground_background`.
39
+ #
40
+ # When `background` is not specified, it's the current
41
+ # terminal's default.
42
+ #
43
+ # They're defined on Color#init.
44
+ @@colors = {}
45
+
46
+ # Start support for colors, initializing all color pairs.
47
+ def self.init
48
+ return unless self.has_colors?
49
+
50
+ Ncurses.start_color
51
+
52
+ # Will be able to use current terminal's
53
+ # background color (value -1)
54
+ Ncurses.use_default_colors
55
+
56
+ # We will initialize 80 color pairs with all
57
+ # combinations from the current Array.
58
+ #
59
+ # They'll have symbols with their names.
60
+ # For example:
61
+ # Color[:white_black]
62
+ # Color[:green_magenta]
63
+ color = [[Ncurses::COLOR_WHITE, :white],
64
+ [Ncurses::COLOR_RED, :red],
65
+ [Ncurses::COLOR_GREEN, :green],
66
+ [Ncurses::COLOR_YELLOW, :yellow],
67
+ [Ncurses::COLOR_BLUE, :blue],
68
+ [Ncurses::COLOR_MAGENTA, :magenta],
69
+ [Ncurses::COLOR_CYAN, :cyan],
70
+ [Ncurses::COLOR_BLACK, :black]]
71
+
72
+ limit = if Ncurses.COLORS < 8
73
+ then Ncurses.COLORS
74
+ else 8
75
+ end
76
+
77
+ pair = 1
78
+ # Create the color pairs
79
+ (0...limit).each do |fg|
80
+ (0...limit).each do |bg|
81
+ Ncurses.init_pair(pair, color[fg][0], color[bg][0])
82
+
83
+ label = "#{color[fg][1]}_#{color[bg][1]}".to_sym
84
+ @@colors[label] = pair
85
+ pair += 1
86
+ end
87
+ end
88
+
89
+ # The color pairs with default background and foreground.
90
+ #
91
+ # They'll have symbols with their names and 'default'
92
+ # where the default color is.
93
+ # For example:
94
+ # Color[:default_black]
95
+ # Color[:magenta]
96
+ color.each do |bg|
97
+ Ncurses.init_pair(pair, -1, bg[0])
98
+
99
+ label = "default_#{bg[1]}".to_sym
100
+ @@colors[label] = pair
101
+ pair += 1
102
+ end
103
+ color.each do |fg|
104
+ Ncurses.init_pair(pair, fg[0], -1)
105
+
106
+ label = "#{fg[1]}".to_sym
107
+ @@colors[label] = pair
108
+ pair += 1
109
+ end
110
+ end
111
+
112
+ # Tells if the current terminal supports colors.
113
+ #
114
+ # Unless you've been living under a rock, this
115
+ # shouldn't be of any concern.
116
+ def self.has_colors?
117
+ Ncurses.has_colors
118
+ end
119
+
120
+ # Access individual color pairs.
121
+ #
122
+ # If colors were not initialized, returns white foreground
123
+ # over default background.
124
+ #
125
+ # @return Ncurses `COLOR_PAIR` over `label` color.
126
+ def self.[] label
127
+ unless @@colors.include? label
128
+ return Ncurses.COLOR_PAIR(0)
129
+ end
130
+
131
+ Ncurses.COLOR_PAIR @@colors[label]
132
+ end
133
+
134
+ end
135
+ end
136
+
@@ -1,7 +1,12 @@
1
+
1
2
  module RNDK
3
+
4
+ # ...I still don't know what this module does...
5
+ #
2
6
  module Display
7
+
3
8
  # Given a string, returns the equivalent display type
4
- def Display.char2DisplayType(string)
9
+ def Display.char_to_display_type string
5
10
  table = {
6
11
  "CHAR" => :CHAR,
7
12
  "HCHAR" => :HCHAR,
@@ -29,7 +34,7 @@ module RNDK
29
34
  end
30
35
 
31
36
  # Tell if a display type is "hidden"
32
- def Display.isHiddenDisplayType(type)
37
+ def Display.is_hidden_display_type type
33
38
  case type
34
39
  when :HCHAR, :HINT, :HMIXED, :LHCHAR, :LHMIXED, :UHCHAR, :UHMIXED
35
40
  true
@@ -39,25 +44,31 @@ module RNDK
39
44
  end
40
45
  end
41
46
 
42
- # Given a character input, check if it is allowed by the display type
43
- # and return the character to apply to the display, or ERR if not
44
- def Display.filterByDisplayType(type, input)
47
+ # Given a character input, check if it is allowed by the
48
+ # display type and return the character to apply to the display,
49
+ # or ERR if not.
50
+ def Display.filter_by_display_type(type, input)
45
51
  result = input
46
- if !RNDK.isChar(input)
52
+ if not RNDK.is_char? input
47
53
  result = Ncurses::ERR
48
- elsif [:INT, :HINT].include?(type) && !RNDK.digit?(result.chr)
54
+
55
+ elsif ([:INT, :HINT].include? type) and (not RNDK.digit? result.chr)
49
56
  result = Ncurses::ERR
50
- elsif [:CHAR, :UCHAR, :LCHAR, :UHCHAR, :LHCHAR].include?(type) && RNDK.digit?(result.chr)
57
+
58
+ elsif ([:CHAR, :UCHAR, :LCHAR, :UHCHAR, :LHCHAR].include? type) and (RNDK.digit? result.chr)
51
59
  result = Ncurses::ERR
60
+
52
61
  elsif type == :VIEWONLY
53
62
  result = ERR
54
- elsif [:UCHAR, :UHCHAR, :UMIXED, :UHMIXED].include?(type) && RNDK.alpha?(result.chr)
63
+
64
+ elsif ([:UCHAR, :UHCHAR, :UMIXED, :UHMIXED].include? type) and (RNDK.is_alpha? result.chr)
55
65
  result = result.chr.upcase.ord
56
- elsif [:LCHAR, :LHCHAR, :LMIXED, :LHMIXED].include?(type) && RNDK.alpha?(result.chr)
66
+
67
+ elsif ([:LCHAR, :LHCHAR, :LMIXED, :LHMIXED].include? type) and (RNDK.is_alpha? result.chr)
57
68
  result = result.chr.downcase.ord
58
69
  end
59
-
60
- return result
70
+ result
61
71
  end
72
+
62
73
  end
63
74
  end
@@ -1,31 +1,37 @@
1
+
1
2
  module RNDK
3
+
2
4
  module Draw
3
- # This sets up a basic set of color pairs. These can be redefined if wanted
4
- def Draw.initRNDKColor
5
- color = [Ncurses::COLOR_WHITE,
6
- Ncurses::COLOR_RED,
7
- Ncurses::COLOR_GREEN,
8
- Ncurses::COLOR_YELLOW,
9
- Ncurses::COLOR_BLUE,
10
- Ncurses::COLOR_MAGENTA,
11
- Ncurses::COLOR_CYAN,
12
- Ncurses::COLOR_BLACK]
13
- pair = 1
14
-
15
- if Ncurses.has_colors
16
- # XXX: Only checks if terminal has colours not if colours are started
17
- Ncurses.start_color
18
- limit = if Ncurses.COLORS < 8 then Ncurses.COLORS else 8 end
19
-
20
- # Create the color pairs
21
- (0...limit).each do |fg|
22
- (0...limit).each do |bg|
23
- Ncurses.init_pair(pair, color[fg], color[bg])
24
- pair += 1
25
- end
26
- end
27
- end
28
- end
5
+ # # This sets up a basic set of color pairs.
6
+ # # These can be redefined if wanted
7
+ # def Draw.initRNDKColor
8
+ # color = [Ncurses::COLOR_WHITE,
9
+ # Ncurses::COLOR_RED,
10
+ # Ncurses::COLOR_GREEN,
11
+ # Ncurses::COLOR_YELLOW,
12
+ # Ncurses::COLOR_BLUE,
13
+ # Ncurses::COLOR_MAGENTA,
14
+ # Ncurses::COLOR_CYAN,
15
+ # Ncurses::COLOR_BLACK]
16
+ # pair = 1
17
+
18
+ # if Ncurses.has_colors
19
+ # # XXX: Only checks if terminal has colours not if colours are started
20
+ # Ncurses.start_color
21
+ # limit = if Ncurses.COLORS < 8
22
+ # then Ncurses.COLORS
23
+ # else 8
24
+ # end
25
+
26
+ # # Create the color pairs
27
+ # (0...limit).each do |fg|
28
+ # (0...limit).each do |bg|
29
+ # Ncurses.init_pair(pair, color[fg], color[bg])
30
+ # pair += 1
31
+ # end
32
+ # end
33
+ # end
34
+ # end
29
35
 
30
36
  # This prints out a box around a window with attributes
31
37
  def Draw.boxWindow(window, attr)