curses-extension 1.3 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/README.md +9 -9
- data/lib/curses-extension.rb +47 -50
- data/lib/curses-template.rb +159 -60
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a1e832808f3f3ffbf4d39755719168b08fbc0c644a7a48840839844b3fca3a4
|
4
|
+
data.tar.gz: 23e73a5413638273336b211d3274a48bdeb21963b7600f0c731968e2269bb343
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34e132b85309f493f6b31efb216edd963b32c13dea3b62b3ca56df56d50c6eb89dcc8783f3a33aa9f8dea5f951c82c9d966623ccee8f75ccc0cc9197a3826338
|
7
|
+
data.tar.gz: 8237d8b29d71c83a1e13d5a4d679ea3fc55cc80cb2d2f635bba070dd29b8ca4bd06039c79b98eaa6df026bdadcb0a4ce87d3a375c125d782ba9c9531ea075e5f
|
data/lib/README.md
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
# Ruby-Curses-Class-Extension
|
2
|
-
Extending the Ruby Curses module with some obvious functionality
|
2
|
+
Extending the Ruby Curses module with some obvious needed functionality.
|
3
3
|
|
4
4
|
## Attributes
|
5
5
|
Attribute | Description
|
6
6
|
--------------------|--------------------------------------------------------
|
7
|
-
color | Set the window's color to an already initiated color pair (with `init_pair(index, forground, backround`)
|
8
7
|
fg | Foreground color for window (0-255)
|
9
8
|
bg | Background color for window (0-255)
|
10
9
|
attr | Attributes for window (such as Curses::A_BOLD) - string with "\|" (such as Curses::A_BOLD \| Curses::A_UNDERLINE)
|
10
|
+
text | Holds the text to be written with the `write`method
|
11
11
|
update | Whether to update the window on the next refresh
|
12
|
+
index | Used to track an index for each window (used to display lists such as the content of a directory, etc.)
|
12
13
|
|
13
14
|
## Functions
|
14
15
|
Function | Description
|
15
16
|
------------------------------------|--------------------------------------------------------
|
16
17
|
clr | Clears window without flicker (win.clear flickers)
|
17
|
-
|
18
|
-
|
18
|
+
clr_to_cur_line | Clears the window up to the current line
|
19
|
+
clr_from_cur_line | Clears the rest of the window after the current line
|
19
20
|
fill | Fill window with color as set by :color ( or :bg if not :color is set)
|
20
21
|
fill_to_cur_pos | Fill the window up to the current line
|
21
22
|
fill_from_cur_pos | Fill the rest of the window after the current line
|
22
|
-
|
23
|
+
write | Write what is already stored in window.text with the set values for fg, bg and attr
|
24
|
+
p(text) or puts(test) | Write text to window with fg/bg and attributes (will handle the exceptions if no colors are set)
|
23
25
|
pclr(text) | As `p(text)` but also clears the rest of the window
|
24
26
|
pa(fg, bg, attr, text) | Write text to window with specified fg, bg and attribute(s)
|
25
|
-
paclr(text)
|
26
|
-
print(text, fg=255, bg=0, attr=0) | Print text (from current position) with optional attributes
|
27
|
-
puts(text, fg=255, bg=0, attr=0) | Clears window and puts text with optional attributes
|
27
|
+
paclr(text, fg=255, bg=0, attr=0) | As `pa(text)` but also clears the rest of the window
|
28
28
|
format_text(text) | Format text so that it linebreaks neatly inside window
|
29
29
|
|
30
30
|
## Curses template
|
31
|
-
The `curses_template.rb` includes the class extension and serves as the basis for my curses applications.
|
31
|
+
The `curses_template.rb` includes the class extension and serves as the basis for my curses applications. It is a runnable curses application that does nothing.
|
data/lib/curses-extension.rb
CHANGED
@@ -1,11 +1,26 @@
|
|
1
1
|
class Curses::Window # CLASS EXTENSION
|
2
2
|
# General extensions (see https://github.com/isene/Ruby-Curses-Class-Extension)
|
3
|
-
|
4
|
-
#
|
5
|
-
#
|
6
|
-
# self.fg is set for the foreground color
|
7
|
-
# self.bg is set for the background color
|
3
|
+
# This is a class extension to Ruby Curses - a class in dire need of such.
|
4
|
+
# self.pair keeps a registry of colors as they are encountered - defined with:
|
5
|
+
# init_pair(index, foreground, background)
|
6
|
+
# self.fg is set for the foreground color
|
7
|
+
# self.bg is set for the background color
|
8
8
|
# self.attr is set for text attributes like Curses::A_BOLD
|
9
|
+
# self.update can be used to indicate if a window should be updated (true/false)
|
10
|
+
# self.index can be used to keep track of the current list item in a window
|
11
|
+
attr_accessor :fg, :bg, :attr, :text, :update, :index
|
12
|
+
def self.pair(fg, bg)
|
13
|
+
@p = [[]] if @p == nil
|
14
|
+
fg = fg.to_i; bg = bg.to_i
|
15
|
+
if @p.include?([fg,bg])
|
16
|
+
@p.index([fg,bg])
|
17
|
+
else
|
18
|
+
@p.push([fg,bg])
|
19
|
+
cp = @p.index([fg,bg])
|
20
|
+
init_pair(cp, fg, bg)
|
21
|
+
@p.index([fg,bg])
|
22
|
+
end
|
23
|
+
end
|
9
24
|
def clr # Clears the whole window
|
10
25
|
self.setpos(0, 0)
|
11
26
|
self.maxy.times {self.deleteln()}
|
@@ -32,15 +47,11 @@ class Curses::Window # CLASS EXTENSION
|
|
32
47
|
x = self.curx
|
33
48
|
y = self.cury
|
34
49
|
self.setpos(0, 0)
|
50
|
+
self.bg = 0 if self.bg == nil
|
51
|
+
self.fg = 255 if self.fg == nil
|
35
52
|
blank = " " * self.maxx
|
36
|
-
|
37
|
-
|
38
|
-
self.fg = 255 if self.fg == nil
|
39
|
-
init_pair(self.fg, self.fg, self.bg)
|
40
|
-
y.times {self.attron(color_pair(self.fg)) {self << blank}}
|
41
|
-
else
|
42
|
-
y.times {self.attron(color_pair(self.color)) {self << blank}}
|
43
|
-
end
|
53
|
+
cp = Curses::Window.pair(self.fg, self.bg)
|
54
|
+
y.times {self.attron(color_pair(cp)) {self << blank}}
|
44
55
|
self.refresh
|
45
56
|
self.setpos(y, x)
|
46
57
|
end
|
@@ -48,60 +59,46 @@ class Curses::Window # CLASS EXTENSION
|
|
48
59
|
x = self.curx
|
49
60
|
y = self.cury
|
50
61
|
self.setpos(y, 0)
|
62
|
+
self.bg = 0 if self.bg == nil
|
63
|
+
self.fg = 255 if self.fg == nil
|
51
64
|
blank = " " * self.maxx
|
52
|
-
|
53
|
-
|
54
|
-
self.fg = 255 if self.fg == nil
|
55
|
-
init_pair(self.fg, self.fg, self.bg)
|
56
|
-
self.maxy.times {self.attron(color_pair(self.fg)) {self << blank}}
|
57
|
-
else
|
58
|
-
self.maxy.times {self.attron(color_pair(self.color)) {self << blank}}
|
59
|
-
end
|
65
|
+
cp = Curses::Window.pair(self.fg, self.bg)
|
66
|
+
self.maxy.times {self.attron(color_pair(cp)) {self << blank}}
|
60
67
|
self.refresh
|
61
68
|
self.setpos(y, x)
|
62
69
|
end
|
70
|
+
def write
|
71
|
+
self.attr = 0 if self.attr == nil
|
72
|
+
self.bg = 0 if self.bg == nil
|
73
|
+
self.fg = 255 if self.fg == nil
|
74
|
+
cp = Curses::Window.pair(self.fg, self.bg)
|
75
|
+
self.attron(color_pair(cp) | self.attr) { self << self.text }
|
76
|
+
self.refresh
|
77
|
+
end
|
63
78
|
def p(text) # Puts text to window
|
64
79
|
self.attr = 0 if self.attr == nil
|
65
|
-
if self.
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
self.attron(color_pair(self.fg) | self.attr) { self << text }
|
70
|
-
else
|
71
|
-
self.attron(color_pair(self.color) | self.attr) { self << text }
|
72
|
-
end
|
80
|
+
self.bg = 0 if self.bg == nil
|
81
|
+
self.fg = 255 if self.fg == nil
|
82
|
+
cp = Curses::Window.pair(self.fg, self.bg)
|
83
|
+
self.attron(color_pair(cp) | attr) { self << text }
|
73
84
|
self.refresh
|
74
85
|
end
|
75
86
|
def pclr(text) # Puts text to window and clears the rest of the window
|
76
87
|
self.p(text)
|
77
88
|
self.clr_from_cur_line
|
78
89
|
end
|
79
|
-
def
|
80
|
-
|
81
|
-
self.
|
82
|
-
end
|
83
|
-
def pa(fg, bg, attr, text) # Puts text to window with full set of attributes
|
84
|
-
self.fg = fg
|
85
|
-
self.bg = bg
|
86
|
-
self.attr = attr
|
87
|
-
init_pair(self.fg, self.fg, self.bg)
|
88
|
-
self.attron(color_pair(self.fg) | self.attr) { self << text }
|
90
|
+
def pa(fg = self.fg, bg = self.bg, attr = self.attr, text) # Puts text to window with full set of attributes
|
91
|
+
cp = Curses::Window.pair(fg, bg)
|
92
|
+
self.attron(color_pair(cp) | attr) { self << text }
|
89
93
|
self.refresh
|
90
94
|
end
|
91
|
-
def
|
92
|
-
self.
|
93
|
-
self.
|
94
|
-
self.setpos(0, 0)
|
95
|
-
self.print(text, fg, bg, attr)
|
96
|
-
end
|
97
|
-
def print(text, fg=255, bg=0, attr=0) # Print text (from current position) with optional attributes
|
98
|
-
init_pair(fg, fg, bg)
|
99
|
-
self.attron(color_pair(fg) | attr) { self << text }
|
100
|
-
self.refresh
|
95
|
+
def paclr(fg = self.fg, bg = self.bg, attr = self.attr, text) # Puts text to window with full set of attributes and clears rest of window
|
96
|
+
self.pa(fg, bg, attr, text)
|
97
|
+
self.clr_from_cur_line
|
101
98
|
end
|
102
99
|
def format_text(text) # Format text so that it linebreaks neatly inside window
|
103
100
|
return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
|
104
101
|
end
|
102
|
+
alias :puts :p
|
105
103
|
end
|
106
104
|
|
107
|
-
# vim: set sw=2 sts=2 et fdm=syntax fdn=2 fcs=fold\:\ :
|
data/lib/curses-template.rb
CHANGED
@@ -8,10 +8,10 @@
|
|
8
8
|
# +-------------------------------+
|
9
9
|
# | @w_t |
|
10
10
|
# +---------------+---------------+
|
11
|
-
# | | |
|
12
11
|
# | @w_l | @w_r |
|
13
12
|
# | | |
|
14
13
|
# | | |
|
14
|
+
# | | |
|
15
15
|
# +---------------+---------------+
|
16
16
|
# | @w_b |
|
17
17
|
# +-------------------------------+
|
@@ -32,12 +32,27 @@ end
|
|
32
32
|
|
33
33
|
class Curses::Window # CLASS EXTENSION
|
34
34
|
# General extensions (see https://github.com/isene/Ruby-Curses-Class-Extension)
|
35
|
-
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# self.fg is set for the foreground color
|
39
|
-
# self.bg is set for the background color
|
35
|
+
# This is a class extension to Ruby Curses - a class in dire need of such.
|
36
|
+
# self.pair keeps a registry of colors as they are encountered - defined with:
|
37
|
+
# init_pair(index, foreground, background)
|
38
|
+
# self.fg is set for the foreground color
|
39
|
+
# self.bg is set for the background color
|
40
40
|
# self.attr is set for text attributes like Curses::A_BOLD
|
41
|
+
# self.update can be used to indicate if a window should be updated (true/false)
|
42
|
+
# self.index can be used to keep track of the current list item in a window
|
43
|
+
attr_accessor :fg, :bg, :attr, :text, :update, :index
|
44
|
+
def self.pair(fg, bg)
|
45
|
+
@p = [[]] if @p == nil
|
46
|
+
fg = fg.to_i; bg = bg.to_i
|
47
|
+
if @p.include?([fg,bg])
|
48
|
+
@p.index([fg,bg])
|
49
|
+
else
|
50
|
+
@p.push([fg,bg])
|
51
|
+
cp = @p.index([fg,bg])
|
52
|
+
init_pair(cp, fg, bg)
|
53
|
+
@p.index([fg,bg])
|
54
|
+
end
|
55
|
+
end
|
41
56
|
def clr # Clears the whole window
|
42
57
|
self.setpos(0, 0)
|
43
58
|
self.maxy.times {self.deleteln()}
|
@@ -64,15 +79,11 @@ class Curses::Window # CLASS EXTENSION
|
|
64
79
|
x = self.curx
|
65
80
|
y = self.cury
|
66
81
|
self.setpos(0, 0)
|
82
|
+
self.bg = 0 if self.bg == nil
|
83
|
+
self.fg = 255 if self.fg == nil
|
67
84
|
blank = " " * self.maxx
|
68
|
-
|
69
|
-
|
70
|
-
self.fg = 255 if self.fg == nil
|
71
|
-
init_pair(self.fg, self.fg, self.bg)
|
72
|
-
y.times {self.attron(color_pair(self.fg)) {self << blank}}
|
73
|
-
else
|
74
|
-
y.times {self.attron(color_pair(self.color)) {self << blank}}
|
75
|
-
end
|
85
|
+
cp = Curses::Window.pair(self.fg, self.bg)
|
86
|
+
y.times {self.attron(color_pair(cp)) {self << blank}}
|
76
87
|
self.refresh
|
77
88
|
self.setpos(y, x)
|
78
89
|
end
|
@@ -80,60 +91,47 @@ class Curses::Window # CLASS EXTENSION
|
|
80
91
|
x = self.curx
|
81
92
|
y = self.cury
|
82
93
|
self.setpos(y, 0)
|
94
|
+
self.bg = 0 if self.bg == nil
|
95
|
+
self.fg = 255 if self.fg == nil
|
83
96
|
blank = " " * self.maxx
|
84
|
-
|
85
|
-
|
86
|
-
self.fg = 255 if self.fg == nil
|
87
|
-
init_pair(self.fg, self.fg, self.bg)
|
88
|
-
self.maxy.times {self.attron(color_pair(self.fg)) {self << blank}}
|
89
|
-
else
|
90
|
-
self.maxy.times {self.attron(color_pair(self.color)) {self << blank}}
|
91
|
-
end
|
97
|
+
cp = Curses::Window.pair(self.fg, self.bg)
|
98
|
+
self.maxy.times {self.attron(color_pair(cp)) {self << blank}}
|
92
99
|
self.refresh
|
93
100
|
self.setpos(y, x)
|
94
101
|
end
|
102
|
+
def write
|
103
|
+
self.attr = 0 if self.attr == nil
|
104
|
+
self.bg = 0 if self.bg == nil
|
105
|
+
self.fg = 255 if self.fg == nil
|
106
|
+
cp = Curses::Window.pair(self.fg, self.bg)
|
107
|
+
self.attron(color_pair(cp) | self.attr) { self << self.text }
|
108
|
+
self.refresh
|
109
|
+
end
|
95
110
|
def p(text) # Puts text to window
|
96
111
|
self.attr = 0 if self.attr == nil
|
97
|
-
if self.
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
self.attron(color_pair(self.fg) | self.attr) { self << text }
|
102
|
-
else
|
103
|
-
self.attron(color_pair(self.color) | self.attr) { self << text }
|
104
|
-
end
|
112
|
+
self.bg = 0 if self.bg == nil
|
113
|
+
self.fg = 255 if self.fg == nil
|
114
|
+
cp = Curses::Window.pair(self.fg, self.bg)
|
115
|
+
self.attron(color_pair(cp) | attr) { self << text }
|
105
116
|
self.refresh
|
106
117
|
end
|
107
118
|
def pclr(text) # Puts text to window and clears the rest of the window
|
108
119
|
self.p(text)
|
109
120
|
self.clr_from_cur_line
|
110
121
|
end
|
111
|
-
def
|
112
|
-
|
113
|
-
self.
|
114
|
-
end
|
115
|
-
def pa(fg, bg, attr, text) # Puts text to window with full set of attributes
|
116
|
-
self.fg = fg
|
117
|
-
self.bg = bg
|
118
|
-
self.attr = attr
|
119
|
-
init_pair(self.fg, self.fg, self.bg)
|
120
|
-
self.attron(color_pair(self.fg) | self.attr) { self << text }
|
122
|
+
def pa(fg = self.fg, bg = self.bg, attr = self.attr, text) # Puts text to window with full set of attributes
|
123
|
+
cp = Curses::Window.pair(fg, bg)
|
124
|
+
self.attron(color_pair(cp) | attr) { self << text }
|
121
125
|
self.refresh
|
122
126
|
end
|
123
|
-
def
|
124
|
-
self.
|
125
|
-
self.
|
126
|
-
self.setpos(0, 0)
|
127
|
-
self.print(text, fg, bg, attr)
|
128
|
-
end
|
129
|
-
def print(text, fg=255, bg=0, attr=0) # Print text (from current position) with optional attributes
|
130
|
-
init_pair(fg, fg, bg)
|
131
|
-
self.attron(color_pair(fg) | attr) { self << text }
|
132
|
-
self.refresh
|
127
|
+
def paclr(fg = self.fg, bg = self.bg, attr = self.attr, text) # Puts text to window with full set of attributes and clears rest of window
|
128
|
+
self.pa(fg, bg, attr, text)
|
129
|
+
self.clr_from_cur_line
|
133
130
|
end
|
134
131
|
def format_text(text) # Format text so that it linebreaks neatly inside window
|
135
132
|
return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
|
136
133
|
end
|
134
|
+
alias :puts :p
|
137
135
|
end
|
138
136
|
|
139
137
|
def getchr # Process key presses
|
@@ -210,6 +208,29 @@ def main_getkey # GET KEY FROM USER
|
|
210
208
|
@break = true
|
211
209
|
when 'q' # Exit
|
212
210
|
exit 0
|
211
|
+
when '@' # Enter "Ruby debug"
|
212
|
+
cmd = w_b_getstr("◆ ", "")
|
213
|
+
@w_b.clr
|
214
|
+
@w_b.refresh
|
215
|
+
@w_b.update = true
|
216
|
+
@w_r.clr
|
217
|
+
info = "Command: #{cmd}\n\n"
|
218
|
+
begin
|
219
|
+
info += eval(cmd).to_s
|
220
|
+
rescue Exception => err
|
221
|
+
info += "Error: #{err.inspect}"
|
222
|
+
end
|
223
|
+
w_r_info(info)
|
224
|
+
@w_r.update = false
|
225
|
+
cmd = w_b_getstr("◆ ", "")
|
226
|
+
begin
|
227
|
+
@w_r.text = eval(cmd)
|
228
|
+
#@w_r.fill
|
229
|
+
@w_r.write
|
230
|
+
rescue StandardError => e
|
231
|
+
w_b("Error: #{e.inspect}")
|
232
|
+
end
|
233
|
+
#@w_b.update = false
|
213
234
|
end
|
214
235
|
while STDIN.ready?
|
215
236
|
chr = STDIN.getc
|
@@ -219,25 +240,102 @@ end
|
|
219
240
|
# TOP WINDOW FUNCTIONS
|
220
241
|
|
221
242
|
# BOTTOM WINDOW FUNCTIONS
|
243
|
+
def w_b(info) # SHOW INFO IN @W_B
|
244
|
+
@w_b.clr
|
245
|
+
info = "Choose window: i=IMDB list (+/- to add/remove from My list), g=Genres (+/- to add/remove), m=My list. " if info == nil
|
246
|
+
info = info[1..(@w_b.maxx - 3)] + "…" if info.length + 3 > @w_b.maxx
|
247
|
+
info += " " * (@w_b.maxx - info.length) if info.length < @w_b.maxx
|
248
|
+
@w_b.text = info
|
249
|
+
@w_b.write
|
250
|
+
@w_b.update = false
|
251
|
+
end
|
252
|
+
def w_b_getstr(pretext, text) # A SIMPLE READLINE-LIKE ROUTINE
|
253
|
+
Curses.curs_set(1)
|
254
|
+
Curses.echo
|
255
|
+
stk = 0
|
256
|
+
pos = text.length
|
257
|
+
chr = ""
|
258
|
+
while chr != "ENTER"
|
259
|
+
@w_b.setpos(0,0)
|
260
|
+
@w_b.text = pretext + text
|
261
|
+
@w_b.text += " " * (@w_b.maxx - text.length) if text.length < @w_b.maxx
|
262
|
+
@w_b.write
|
263
|
+
@w_b.setpos(0,pretext.length + pos)
|
264
|
+
@w_b.refresh
|
265
|
+
chr = getchr
|
266
|
+
case chr
|
267
|
+
when 'C-C', 'C-G'
|
268
|
+
return ""
|
269
|
+
when 'RIGHT'
|
270
|
+
pos += 1 unless pos > text.length
|
271
|
+
when 'LEFT'
|
272
|
+
pos -= 1 unless pos == 0
|
273
|
+
when 'HOME'
|
274
|
+
pos = 0
|
275
|
+
when 'END'
|
276
|
+
pos = text.length
|
277
|
+
when 'DEL'
|
278
|
+
text[pos] = ""
|
279
|
+
when 'BACK'
|
280
|
+
unless pos == 0
|
281
|
+
pos -= 1
|
282
|
+
text[pos] = ""
|
283
|
+
end
|
284
|
+
when 'LDEL'
|
285
|
+
text = ""
|
286
|
+
pos = 0
|
287
|
+
when /^.$/
|
288
|
+
text.insert(pos,chr)
|
289
|
+
pos += 1
|
290
|
+
end
|
291
|
+
end
|
292
|
+
Curses.curs_set(0)
|
293
|
+
Curses.noecho
|
294
|
+
return text
|
295
|
+
end
|
222
296
|
|
223
297
|
# LEFT WINDOW FUNCTIONS
|
224
298
|
|
225
299
|
# RIGHT WINDOW FUNCTIONS
|
226
|
-
|
300
|
+
def w_r_info(info) # SHOW INFO IN THE RIGHT WINDOW
|
301
|
+
begin
|
302
|
+
@w_r.clr
|
303
|
+
@w_r.refresh
|
304
|
+
@w_r.text = info
|
305
|
+
@w_r.write
|
306
|
+
@w_r.update = false
|
307
|
+
rescue
|
308
|
+
end
|
309
|
+
end
|
227
310
|
|
228
311
|
# MAIN PROGRAM
|
229
312
|
loop do # OUTER LOOP - (catching refreshes via 'r')
|
230
313
|
@break = false # Initialize @break variable (set if user hits 'r')
|
231
|
-
begin # Create the four windows/
|
314
|
+
begin # Create the four windows/panes
|
232
315
|
maxx = Curses.cols
|
233
|
-
exit if maxx < @w_l_width
|
234
316
|
maxy = Curses.lines
|
235
|
-
#
|
236
|
-
|
237
|
-
@
|
238
|
-
@
|
239
|
-
@
|
317
|
+
# Create windows/panes
|
318
|
+
# Curses::Window.new ( h, w, y, x)
|
319
|
+
@w_t = Curses::Window.new( 1, maxx, 0, 0)
|
320
|
+
@w_b = Curses::Window.new( 1, maxx, maxy-1, 0)
|
321
|
+
@w_l = Curses::Window.new(maxy-2, maxx/2, 1, 0)
|
322
|
+
@w_r = Curses::Window.new(maxy-2, maxx/2, 1, maxx/2)
|
323
|
+
# Set foreground and background colors and attributes
|
324
|
+
@w_t.fg, @w_t.bg, @w_t.attr = 255, 23, 0
|
325
|
+
@w_b.fg, @w_b.bg, @w_b.attr = 231, 238, 0
|
326
|
+
@w_l.fg, @w_l.bg, @w_l.attr = 46, 234, 0
|
327
|
+
@w_r.fg, @w_r.bg, @w_r.attr = 202, 235, 0
|
240
328
|
loop do # INNER, CORE LOOP
|
329
|
+
@w_t.fill; @w_b.fill; @w_l.fill; @w_r.fill
|
330
|
+
|
331
|
+
# Example code to write to the panes in various ways
|
332
|
+
@w_t.text = "Top window"
|
333
|
+
@w_t.write
|
334
|
+
@w_b.pa("Bottom window")
|
335
|
+
@w_l.pa(196,182,Curses::A_BOLD,"Left window")
|
336
|
+
@w_r.text = "Right window"
|
337
|
+
@w_r.write
|
338
|
+
|
241
339
|
# Top window (info line)
|
242
340
|
|
243
341
|
# Bottom window (command line)
|
@@ -246,9 +344,10 @@ loop do # OUTER LOOP - (catching refreshes via 'r')
|
|
246
344
|
|
247
345
|
# Right window
|
248
346
|
|
249
|
-
|
347
|
+
# Get key from user
|
348
|
+
main_getkey
|
250
349
|
|
251
|
-
break if @break # Break to outer loop, redrawing windows, if user
|
350
|
+
break if @break # Break to outer loop, redrawing windows, if user hits 'r'
|
252
351
|
break if Curses.cols != maxx or Curses.lines != maxy # break on terminal resize
|
253
352
|
end
|
254
353
|
ensure # On exit: close curses, clear terminal
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curses-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '2.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geir Isene
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|
@@ -35,8 +35,7 @@ description: 'The Ruby curses library is sorely lacking some important features.
|
|
35
35
|
terminal curses applications in Ruby. See the Github page for information on what
|
36
36
|
properties and functions are included: https://github.com/isene/Ruby-Curses-Class-Extension.
|
37
37
|
The curses_template.rb is also installed in the lib directory and serves as the
|
38
|
-
basis for my own curses applications. New in
|
39
|
-
and other improvements'
|
38
|
+
basis for my own curses applications. New in 2.0: Full rewrite/upgrade'
|
40
39
|
email: g@isene.com
|
41
40
|
executables: []
|
42
41
|
extensions: []
|