curses-extension 2.0 → 2.1
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/lib/README.md +18 -6
- data/lib/curses-extension.rb +9 -25
- data/lib/curses-template.rb +19 -41
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0a272233095a365552a978ea26953df75a91f985ca30a9765f7191338ffc5468
|
|
4
|
+
data.tar.gz: 6b807771cb90a3bc5bdbec098f01ec31414f55bfdb982cdf88cf3b0b62f33ca2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5fa593f92f9cdbb0774350fb4fa2c956f9be7435021c52559770fe2c3c35bb7753d25f35b69e7b192818f3ae795be7705374c3c02e1714f14573d75c1b079ae9
|
|
7
|
+
data.tar.gz: 445fcf7a916887d489d16835044513c8ad76664bfa9ed7163663a9edb12ca307806b671b7e76f4d847da53613f27e1563fdda69ff62e25d772ea2cde5436463f
|
data/lib/README.md
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
# Ruby-Curses-Class-Extension
|
|
2
2
|
Extending the Ruby Curses module with some obvious needed functionality.
|
|
3
3
|
|
|
4
|
+
With this extension, you don't need to initiate any color pairs or add text to
|
|
5
|
+
windows with odd syntax. Use any foreground and backround color you see fit
|
|
6
|
+
and let this extension take care of the weird need to pair colors and initiate
|
|
7
|
+
the color pairs. You also get a bunch of extra methods to manipulate curses
|
|
8
|
+
windows.
|
|
9
|
+
|
|
10
|
+
With this extension writing text to windows becomes a breeze. You can set
|
|
11
|
+
default foreground, background and attribute for a window (e.g. `win.fg =
|
|
12
|
+
124`, `win.bg = 234` and `win.attr = Curses::A_BOLD`) - and you can write text
|
|
13
|
+
to a window with `win.p("Hello World")` where the defaults will be applied.
|
|
14
|
+
You can override the defaults with e.g. `win.p(124, "Hello World")` to write
|
|
15
|
+
the text in red or `win.p(76, 240, Curses::A_BOLD, "Hello World")` to write
|
|
16
|
+
the text in bold green on a gray background.
|
|
17
|
+
|
|
18
|
+
|
|
4
19
|
## Attributes
|
|
5
20
|
Attribute | Description
|
|
6
21
|
--------------------|--------------------------------------------------------
|
|
7
22
|
fg | Foreground color for window (0-255)
|
|
8
23
|
bg | Background color for window (0-255)
|
|
9
24
|
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
25
|
update | Whether to update the window on the next refresh
|
|
12
26
|
index | Used to track an index for each window (used to display lists such as the content of a directory, etc.)
|
|
13
27
|
|
|
@@ -20,12 +34,10 @@ clr_from_cur_line | Clears the rest of the window after the current line
|
|
|
20
34
|
fill | Fill window with color as set by :color ( or :bg if not :color is set)
|
|
21
35
|
fill_to_cur_pos | Fill the window up to the current line
|
|
22
36
|
fill_from_cur_pos | Fill the rest of the window after the current line
|
|
23
|
-
|
|
24
|
-
|
|
37
|
+
p(fg, bg, attr, text) | Write text to window with fg/bg and attributes (will handle the exceptions if no colors are set).
|
|
38
|
+
You can use `puts` instead of `p` (it's an alias)
|
|
25
39
|
pclr(text) | As `p(text)` but also clears the rest of the window
|
|
26
|
-
|
|
27
|
-
paclr(text, fg=255, bg=0, attr=0) | As `pa(text)` but also clears the rest of the window
|
|
28
|
-
format_text(text) | Format text so that it linebreaks neatly inside window
|
|
40
|
+
format(text) | Format text so that it linebreaks neatly inside window
|
|
29
41
|
|
|
30
42
|
## Curses template
|
|
31
43
|
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
|
@@ -8,7 +8,7 @@ class Curses::Window # CLASS EXTENSION
|
|
|
8
8
|
# self.attr is set for text attributes like Curses::A_BOLD
|
|
9
9
|
# self.update can be used to indicate if a window should be updated (true/false)
|
|
10
10
|
# self.index can be used to keep track of the current list item in a window
|
|
11
|
-
attr_accessor :fg, :bg, :attr, :
|
|
11
|
+
attr_accessor :fg, :bg, :attr, :update, :index
|
|
12
12
|
def self.pair(fg, bg)
|
|
13
13
|
@p = [[]] if @p == nil
|
|
14
14
|
fg = fg.to_i; bg = bg.to_i
|
|
@@ -67,38 +67,22 @@ class Curses::Window # CLASS EXTENSION
|
|
|
67
67
|
self.refresh
|
|
68
68
|
self.setpos(y, x)
|
|
69
69
|
end
|
|
70
|
-
def
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
78
|
-
def p(text) # Puts text to window
|
|
79
|
-
self.attr = 0 if self.attr == nil
|
|
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 }
|
|
84
|
-
self.refresh
|
|
85
|
-
end
|
|
86
|
-
def pclr(text) # Puts text to window and clears the rest of the window
|
|
87
|
-
self.p(text)
|
|
88
|
-
self.clr_from_cur_line
|
|
89
|
-
end
|
|
90
|
-
def pa(fg = self.fg, bg = self.bg, attr = self.attr, text) # Puts text to window with full set of attributes
|
|
70
|
+
def p(fg = self.fg, bg = self.bg, attr = self.attr, text) # Puts text to window with full set of attributes
|
|
71
|
+
fg = 255 if fg == nil
|
|
72
|
+
bg = 0 if bg == nil
|
|
73
|
+
attr = 0 if attr == nil
|
|
91
74
|
cp = Curses::Window.pair(fg, bg)
|
|
92
75
|
self.attron(color_pair(cp) | attr) { self << text }
|
|
93
76
|
self.refresh
|
|
94
77
|
end
|
|
95
|
-
def
|
|
96
|
-
self.
|
|
78
|
+
def pclr(fg = self.fg, bg = self.bg, attr = self.attr, text) # Puts text to window with full set of attributes and clears rest of window
|
|
79
|
+
self.p(fg, bg, attr, text)
|
|
97
80
|
self.clr_from_cur_line
|
|
98
81
|
end
|
|
99
|
-
def
|
|
82
|
+
def format(text) # Format text so that it linebreaks neatly inside window
|
|
100
83
|
return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
|
|
101
84
|
end
|
|
102
85
|
alias :puts :p
|
|
103
86
|
end
|
|
104
87
|
|
|
88
|
+
# vim: set sw=2 sts=2 et fdm=syntax fdn=2 fcs=fold\:\ :
|
data/lib/curses-template.rb
CHANGED
|
@@ -40,7 +40,7 @@ class Curses::Window # CLASS EXTENSION
|
|
|
40
40
|
# self.attr is set for text attributes like Curses::A_BOLD
|
|
41
41
|
# self.update can be used to indicate if a window should be updated (true/false)
|
|
42
42
|
# self.index can be used to keep track of the current list item in a window
|
|
43
|
-
attr_accessor :fg, :bg, :attr, :
|
|
43
|
+
attr_accessor :fg, :bg, :attr, :update, :index
|
|
44
44
|
def self.pair(fg, bg)
|
|
45
45
|
@p = [[]] if @p == nil
|
|
46
46
|
fg = fg.to_i; bg = bg.to_i
|
|
@@ -99,36 +99,19 @@ class Curses::Window # CLASS EXTENSION
|
|
|
99
99
|
self.refresh
|
|
100
100
|
self.setpos(y, x)
|
|
101
101
|
end
|
|
102
|
-
def
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
|
110
|
-
def p(text) # Puts text to window
|
|
111
|
-
self.attr = 0 if self.attr == nil
|
|
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 }
|
|
116
|
-
self.refresh
|
|
117
|
-
end
|
|
118
|
-
def pclr(text) # Puts text to window and clears the rest of the window
|
|
119
|
-
self.p(text)
|
|
120
|
-
self.clr_from_cur_line
|
|
121
|
-
end
|
|
122
|
-
def pa(fg = self.fg, bg = self.bg, attr = self.attr, text) # Puts text to window with full set of attributes
|
|
102
|
+
def p(fg = self.fg, bg = self.bg, attr = self.attr, text) # Puts text to window with full set of attributes
|
|
103
|
+
fg = 255 if fg == nil
|
|
104
|
+
bg = 0 if bg == nil
|
|
105
|
+
attr = 0 if attr == nil
|
|
123
106
|
cp = Curses::Window.pair(fg, bg)
|
|
124
107
|
self.attron(color_pair(cp) | attr) { self << text }
|
|
125
108
|
self.refresh
|
|
126
109
|
end
|
|
127
|
-
def
|
|
128
|
-
self.
|
|
110
|
+
def pclr(fg = self.fg, bg = self.bg, attr = self.attr, text) # Puts text to window with full set of attributes and clears rest of window
|
|
111
|
+
self.p(fg, bg, attr, text)
|
|
129
112
|
self.clr_from_cur_line
|
|
130
113
|
end
|
|
131
|
-
def
|
|
114
|
+
def format(text) # Format text so that it linebreaks neatly inside window
|
|
132
115
|
return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
|
|
133
116
|
end
|
|
134
117
|
alias :puts :p
|
|
@@ -224,9 +207,8 @@ def main_getkey # GET KEY FROM USER
|
|
|
224
207
|
@w_r.update = false
|
|
225
208
|
cmd = w_b_getstr("◆ ", "")
|
|
226
209
|
begin
|
|
227
|
-
@w_r.
|
|
228
|
-
|
|
229
|
-
@w_r.write
|
|
210
|
+
@w_r.fill
|
|
211
|
+
@w_r.p(eval(cmd))
|
|
230
212
|
rescue StandardError => e
|
|
231
213
|
w_b("Error: #{e.inspect}")
|
|
232
214
|
end
|
|
@@ -245,8 +227,7 @@ def w_b(info) # SHOW INFO IN @W_B
|
|
|
245
227
|
info = "Choose window: i=IMDB list (+/- to add/remove from My list), g=Genres (+/- to add/remove), m=My list. " if info == nil
|
|
246
228
|
info = info[1..(@w_b.maxx - 3)] + "…" if info.length + 3 > @w_b.maxx
|
|
247
229
|
info += " " * (@w_b.maxx - info.length) if info.length < @w_b.maxx
|
|
248
|
-
@w_b.
|
|
249
|
-
@w_b.write
|
|
230
|
+
@w_b.p(info)
|
|
250
231
|
@w_b.update = false
|
|
251
232
|
end
|
|
252
233
|
def w_b_getstr(pretext, text) # A SIMPLE READLINE-LIKE ROUTINE
|
|
@@ -257,9 +238,9 @@ def w_b_getstr(pretext, text) # A SIMPLE READLINE-LIKE ROUTINE
|
|
|
257
238
|
chr = ""
|
|
258
239
|
while chr != "ENTER"
|
|
259
240
|
@w_b.setpos(0,0)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
@w_b.
|
|
241
|
+
text = pretext + text
|
|
242
|
+
text += " " * (@w_b.maxx - text.length) if text.length < @w_b.maxx
|
|
243
|
+
@w_b.p(text)
|
|
263
244
|
@w_b.setpos(0,pretext.length + pos)
|
|
264
245
|
@w_b.refresh
|
|
265
246
|
chr = getchr
|
|
@@ -301,8 +282,7 @@ def w_r_info(info) # SHOW INFO IN THE RIGHT WINDOW
|
|
|
301
282
|
begin
|
|
302
283
|
@w_r.clr
|
|
303
284
|
@w_r.refresh
|
|
304
|
-
@w_r.
|
|
305
|
-
@w_r.write
|
|
285
|
+
@w_r.p(info)
|
|
306
286
|
@w_r.update = false
|
|
307
287
|
rescue
|
|
308
288
|
end
|
|
@@ -329,12 +309,10 @@ loop do # OUTER LOOP - (catching refreshes via 'r')
|
|
|
329
309
|
@w_t.fill; @w_b.fill; @w_l.fill; @w_r.fill
|
|
330
310
|
|
|
331
311
|
# Example code to write to the panes in various ways
|
|
332
|
-
@w_t.
|
|
333
|
-
@
|
|
334
|
-
@
|
|
335
|
-
@
|
|
336
|
-
@w_r.text = "Right window"
|
|
337
|
-
@w_r.write
|
|
312
|
+
@w_t.p("Top window")
|
|
313
|
+
@w_b.p("Bottom window")
|
|
314
|
+
@w_l.p(196,182,Curses::A_BOLD,"Left window")
|
|
315
|
+
@w_r.p("Right window")
|
|
338
316
|
|
|
339
317
|
# Top window (info line)
|
|
340
318
|
|
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: '2.
|
|
4
|
+
version: '2.1'
|
|
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-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: curses
|
|
@@ -35,7 +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 2.
|
|
38
|
+
basis for my own curses applications. New in 2.1: Simplified'
|
|
39
39
|
email: g@isene.com
|
|
40
40
|
executables: []
|
|
41
41
|
extensions: []
|