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.
- checksums.yaml +4 -4
- data/demos/appointment.rb +40 -25
- data/demos/clock.rb +22 -11
- data/demos/fileview.rb +141 -0
- data/examples/01-hello-world.rb +1 -2
- data/examples/02-colors.rb +58 -0
- data/examples/03-markup.rb +70 -0
- data/examples/04-quick-widgets.rb +72 -0
- data/examples/05-position-widget.rb +3 -6
- data/examples/calendar.rb +104 -0
- data/examples/scroll.rb +106 -0
- data/lib/rndk/alphalist.rb +14 -14
- data/lib/rndk/button.rb +21 -21
- data/lib/rndk/buttonbox.rb +18 -18
- data/lib/rndk/calendar.rb +333 -240
- data/lib/rndk/core/color.rb +136 -0
- data/lib/rndk/core/display.rb +23 -12
- data/lib/rndk/core/draw.rb +32 -26
- data/lib/rndk/core/markup.rb +561 -0
- data/lib/rndk/core/quick_widgets.rb +232 -12
- data/lib/rndk/core/screen.rb +16 -17
- data/lib/rndk/core/utils.rb +143 -0
- data/lib/rndk/core/widget.rb +133 -92
- data/lib/rndk/dialog.rb +17 -17
- data/lib/rndk/entry.rb +21 -21
- data/lib/rndk/fselect.rb +16 -16
- data/lib/rndk/graph.rb +10 -10
- data/lib/rndk/histogram.rb +10 -10
- data/lib/rndk/itemlist.rb +20 -20
- data/lib/rndk/label.rb +66 -45
- data/lib/rndk/marquee.rb +10 -10
- data/lib/rndk/matrix.rb +27 -27
- data/lib/rndk/mentry.rb +22 -22
- data/lib/rndk/menu.rb +14 -14
- data/lib/rndk/radio.rb +19 -19
- data/lib/rndk/scale.rb +21 -21
- data/lib/rndk/scroll.rb +19 -19
- data/lib/rndk/scroller.rb +2 -0
- data/lib/rndk/selection.rb +20 -20
- data/lib/rndk/slider.rb +21 -21
- data/lib/rndk/swindow.rb +20 -20
- data/lib/rndk/template.rb +21 -21
- data/lib/rndk/version.rb +1 -1
- data/lib/rndk/viewer.rb +18 -18
- data/lib/rndk.rb +99 -777
- data/rndk.gemspec +1 -1
- 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
|
+
|
data/lib/rndk/core/display.rb
CHANGED
@@ -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.
|
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.
|
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
|
43
|
-
# and return the character to apply to the display,
|
44
|
-
|
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
|
52
|
+
if not RNDK.is_char? input
|
47
53
|
result = Ncurses::ERR
|
48
|
-
|
54
|
+
|
55
|
+
elsif ([:INT, :HINT].include? type) and (not RNDK.digit? result.chr)
|
49
56
|
result = Ncurses::ERR
|
50
|
-
|
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
|
-
|
63
|
+
|
64
|
+
elsif ([:UCHAR, :UHCHAR, :UMIXED, :UHMIXED].include? type) and (RNDK.is_alpha? result.chr)
|
55
65
|
result = result.chr.upcase.ord
|
56
|
-
|
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
|
data/lib/rndk/core/draw.rb
CHANGED
@@ -1,31 +1,37 @@
|
|
1
|
+
|
1
2
|
module RNDK
|
3
|
+
|
2
4
|
module Draw
|
3
|
-
# This sets up a basic set of color pairs.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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)
|