curses-extension 2.3 → 3.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 +24 -17
- data/lib/curses-extension.rb +87 -52
- data/lib/curses-template.rb +122 -81
- 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: f99e5edb8a0e53f52e18c5f5c8ad401fb50092275288cbc32fa6bf0c7c18cc07
|
4
|
+
data.tar.gz: 20842d9a7eeea019df04a4e29073322c6a351c998fe45e0424d5cd4abd8d7cff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71bd0aa9bb4fd5246454af6dcd92f38b0cccbaf1d11412a1e309892b18e99aa0f2e1269ccb52979245e970e1faf6acf5f55a753eace7bf9ef5a4d7e01744b973
|
7
|
+
data.tar.gz: 221a4711ff5cf9eb22b4eab34b0e7e174c4fa4164bae7d2a2e54d94c941240b7412729acf600f2bd4228f375b2b339b61b0f552c184336008d4cced4542d0631
|
data/lib/README.md
CHANGED
@@ -20,7 +20,7 @@ the text in bold green on a gray background.
|
|
20
20
|
There is also the handy method `nl` that fills the rest of the line with
|
21
21
|
spaces and (optional) background color, making it an effective newline.
|
22
22
|
|
23
|
-
And then there is the convenient `frame`method that
|
23
|
+
And then there is the convenient `frame`method that toggles a frame for the
|
24
24
|
window.
|
25
25
|
|
26
26
|
The `curses-template.rb` contains code that helps you understand how you can
|
@@ -33,27 +33,34 @@ Attribute | Description
|
|
33
33
|
--------------------|--------------------------------------------------------
|
34
34
|
fg | Foreground color for window (0-255)
|
35
35
|
bg | Background color for window (0-255)
|
36
|
-
attr | Attributes for window (such as Curses::A_BOLD) -
|
36
|
+
attr | Attributes for window (such as Curses::A_BOLD) - combine with "\|" (such as Curses::A_BOLD \| Curses::A_UNDERLINE)
|
37
37
|
update | Whether to update the window on the next refresh
|
38
38
|
index | Used to track an index for each window (used to display lists such as the content of a directory, etc.)
|
39
39
|
|
40
|
-
## Functions
|
40
|
+
## Functions/Methods
|
41
|
+
Each window has an additional set of methods/functions to the original Curses library.
|
42
|
+
|
43
|
+
In this extended set of methods/functions, the ones ending in a question mark
|
44
|
+
(like `x?`) is a query and will return a value, while the others will set a
|
45
|
+
value or create something.
|
46
|
+
|
41
47
|
Parameters in square are optional.
|
42
48
|
|
43
|
-
Function
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
nl([bg])
|
55
|
-
|
56
|
-
|
49
|
+
Function | Description
|
50
|
+
-----------------------------|-------------------------------------------------------
|
51
|
+
x? | Get the current x (column)
|
52
|
+
y? | Get the current y (row)
|
53
|
+
mx? | Get the maximum x (column)
|
54
|
+
my? | Get the maximum y (row)
|
55
|
+
x(x) | Set/goto x (column)
|
56
|
+
y(y) | Set/goto y (row)
|
57
|
+
xy(x,y) | Set/goto x & y (column & row)
|
58
|
+
fill([bg], [l1], [l2]) | Fill window with bg color from lines l1 to l2
|
59
|
+
p([fg], [bg], [attr], text) | Puts text to window with full set of attributes
|
60
|
+
nl([bg]) | Add newline
|
61
|
+
p0([fg], [bg], [attr], text) | Puts text at 0,0 and clears the rest of the line
|
62
|
+
frame([fg], [bg]) | Toggle framing of the window
|
63
|
+
format(text) | Format text so that it linebreaks neatly inside window
|
57
64
|
|
58
65
|
## Curses template
|
59
66
|
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,8 +8,8 @@ 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, :update, :index
|
12
|
-
def self.pair(fg, bg)
|
11
|
+
attr_accessor :fg, :bg, :attr, :framed, :update, :index
|
12
|
+
def self.pair(fg, bg) # INTERNAL FUNCTION
|
13
13
|
@p = [[]] if @p == nil
|
14
14
|
fg = fg.to_i; bg = bg.to_i
|
15
15
|
if @p.include?([fg,bg])
|
@@ -21,79 +21,114 @@ class Curses::Window # CLASS EXTENSION
|
|
21
21
|
@p.index([fg,bg])
|
22
22
|
end
|
23
23
|
end
|
24
|
-
def
|
25
|
-
self.
|
26
|
-
|
27
|
-
|
28
|
-
self.setpos(0, 0)
|
24
|
+
def x? # GET THE CURRENT X (COLUMN)
|
25
|
+
x = self.curx
|
26
|
+
x -= 1 if self.framed
|
27
|
+
x
|
29
28
|
end
|
30
|
-
def
|
31
|
-
|
32
|
-
self.
|
33
|
-
|
34
|
-
self.refresh
|
29
|
+
def y? # GET THE CURRENT Y (ROW)
|
30
|
+
y = self.cury
|
31
|
+
y -= 1 if self.framed
|
32
|
+
y
|
35
33
|
end
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
self.setpos(l, 0)
|
34
|
+
def mx? # GET THE MAXIMUM X (COLUMN)
|
35
|
+
mx = self.maxx
|
36
|
+
mx -= 2 if self.framed
|
37
|
+
mx
|
41
38
|
end
|
42
|
-
def
|
43
|
-
self.
|
44
|
-
self.
|
39
|
+
def my? # GET THE MAXIMUM Y (ROW)
|
40
|
+
my = self.maxy
|
41
|
+
my -= 2 if self.framed
|
42
|
+
my
|
45
43
|
end
|
46
|
-
def
|
47
|
-
x
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
self.
|
52
|
-
|
53
|
-
|
54
|
-
y
|
55
|
-
self.
|
56
|
-
|
44
|
+
def x(x) # SET/GOTO X (COLUMN)
|
45
|
+
x += 1 if self.framed
|
46
|
+
mx = self.mx?
|
47
|
+
x = mx if x > mx
|
48
|
+
y = self.cury
|
49
|
+
self.setpos(y,x)
|
50
|
+
end
|
51
|
+
def y(y) # SET/GOTO Y (ROW)
|
52
|
+
y += 1 if self.framed
|
53
|
+
my = self.my?
|
54
|
+
y = my if y > my
|
55
|
+
x = self.curx
|
56
|
+
self.setpos(y,x)
|
57
57
|
end
|
58
|
-
def
|
59
|
-
x
|
60
|
-
y
|
61
|
-
self.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
58
|
+
def xy(x,y) # SET/GOTO X & Y (COLUMN & ROW)
|
59
|
+
x += 1 if self.framed
|
60
|
+
y += 1 if self.framed
|
61
|
+
mx = self.mx?
|
62
|
+
x = mx if x > mx?
|
63
|
+
my = self.my?
|
64
|
+
y = my if y > my?
|
65
|
+
self.setpos(y,x)
|
66
|
+
end
|
67
|
+
def fill(bg = self.bg, l1 = 0, l2 = self.my?) # FILL WINDOW WITH BG COLOR FROM LINES L1 TO L2
|
68
|
+
self.xy(0, l1)
|
69
|
+
bg = 0 if self.bg == nil
|
70
|
+
blank = " " * self.mx?
|
71
|
+
cp = Curses::Window.pair(0, bg)
|
72
|
+
lines = l2 - l1
|
73
|
+
lines.times do
|
74
|
+
y = self.y?
|
75
|
+
self.attron(color_pair(cp)) {self << blank}
|
76
|
+
self.xy(0,y+1)
|
77
|
+
end
|
67
78
|
self.refresh
|
68
|
-
self.
|
79
|
+
self.xy(0, 0)
|
69
80
|
end
|
70
|
-
def p(fg = self.fg, bg = self.bg, attr = self.attr, text) #
|
81
|
+
def p(fg = self.fg, bg = self.bg, attr = self.attr, text) # PUTS TEXT TO WINDOW WITH FULL SET OF ATTRIBUTES
|
71
82
|
fg = 255 if fg == nil
|
72
83
|
bg = 0 if bg == nil
|
73
84
|
attr = 0 if attr == nil
|
74
|
-
cp
|
85
|
+
cp = Curses::Window.pair(fg, bg)
|
75
86
|
self.attron(color_pair(cp) | attr) { self << text }
|
76
87
|
self.refresh
|
77
88
|
end
|
78
|
-
def nl(bg = self.bg)
|
89
|
+
def nl(bg = self.bg) # ADD NEWLINE
|
90
|
+
y = self.y?
|
79
91
|
bg = 232 if bg == nil
|
80
|
-
f = " " * (self.
|
92
|
+
f = " " * (self.mx? - self.x?)
|
81
93
|
self.p(self.fg, bg, self.attr, f)
|
94
|
+
self.xy(0,y+1)
|
82
95
|
end
|
83
|
-
def
|
96
|
+
def p0(fg = self.fg, bg = self.bg, attr = self.attr, text) # PUTS TEXT AT 0,0 AND CLEARS THE REST OF THE LINE
|
97
|
+
self.xy(0, 0)
|
84
98
|
self.p(fg, bg, attr, text)
|
85
|
-
self.
|
99
|
+
self.nl(bg)
|
100
|
+
self.xy(0, 0)
|
86
101
|
end
|
87
|
-
def frame(fg = self.fg, bg = self.bg)
|
102
|
+
def frame(fg = self.fg, bg = self.bg) # TOGGLE FRAMING OF THE WINDOW
|
103
|
+
fr = self.framed
|
104
|
+
tl = self.framed ? " " : "┌"
|
105
|
+
tc = self.framed ? " " : "─"
|
106
|
+
tr = self.framed ? " " : "┐"
|
107
|
+
lr = self.framed ? " " : "│"
|
108
|
+
bl = self.framed ? " " : "└"
|
109
|
+
bc = self.framed ? " " : "─"
|
110
|
+
br = self.framed ? " " : "┘"
|
88
111
|
self.setpos(0,0)
|
89
|
-
self.p(
|
90
|
-
(self.maxy-2).times
|
91
|
-
|
112
|
+
self.p(tl + tc*(self.maxx-2) + tr)
|
113
|
+
(self.maxy-2).times do
|
114
|
+
y = self.cury
|
115
|
+
mx = self.maxx
|
116
|
+
self.setpos(y,0); self.p(lr)
|
117
|
+
self.setpos(y,maxx-1); self.p(lr)
|
118
|
+
end
|
119
|
+
self.p(bl + bc*(self.maxx-2) + br)
|
120
|
+
if self.framed == nil
|
121
|
+
self.framed = true
|
122
|
+
else
|
123
|
+
self.framed = !self.framed
|
124
|
+
end
|
125
|
+
self.xy(0,0)
|
92
126
|
end
|
93
|
-
def format(text) #
|
127
|
+
def format(text) # FORMAT TEXT SO THAT IT LINEBREAKS NEATLY INSIDE WINDOW
|
94
128
|
return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
|
95
129
|
end
|
96
130
|
alias :puts :p
|
131
|
+
alias :puts0 :p0
|
97
132
|
end
|
98
133
|
|
99
134
|
# vim: set sw=2 sts=2 et fdm=syntax fdn=2 fcs=fold\:\ :
|
data/lib/curses-template.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
-
# This is a basic template for my Curses applications. Feel free to use.
|
4
|
+
# This is a basic template for my? Curses applications. Feel free to use.
|
5
5
|
#
|
6
6
|
# It is an example of a basic curses application with 4 windows like this:
|
7
7
|
#
|
@@ -40,8 +40,8 @@ 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, :update, :index
|
44
|
-
def self.pair(fg, bg)
|
43
|
+
attr_accessor :fg, :bg, :attr, :framed, :update, :index
|
44
|
+
def self.pair(fg, bg) # INTERNAL FUNCTION
|
45
45
|
@p = [[]] if @p == nil
|
46
46
|
fg = fg.to_i; bg = bg.to_i
|
47
47
|
if @p.include?([fg,bg])
|
@@ -53,53 +53,64 @@ class Curses::Window # CLASS EXTENSION
|
|
53
53
|
@p.index([fg,bg])
|
54
54
|
end
|
55
55
|
end
|
56
|
-
def
|
57
|
-
self.
|
58
|
-
|
59
|
-
|
60
|
-
self.setpos(0, 0)
|
56
|
+
def x? # GET THE CURRENT X (COLUMN)
|
57
|
+
x = self.curx
|
58
|
+
x -= 1 if self.framed
|
59
|
+
x
|
61
60
|
end
|
62
|
-
def
|
63
|
-
|
64
|
-
self.
|
65
|
-
|
66
|
-
self.refresh
|
61
|
+
def y? # GET THE CURRENT Y (ROW)
|
62
|
+
y = self.cury
|
63
|
+
y -= 1 if self.framed
|
64
|
+
y
|
67
65
|
end
|
68
|
-
def
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
self.setpos(l, 0)
|
66
|
+
def mx? # GET THE MAXIMUM X (COLUMN)
|
67
|
+
mx = self.maxx
|
68
|
+
mx -= 2 if self.framed
|
69
|
+
mx
|
73
70
|
end
|
74
|
-
def
|
75
|
-
self.
|
76
|
-
self.
|
71
|
+
def my? # GET THE MAXIMUM Y (ROW)
|
72
|
+
my = self.maxy
|
73
|
+
my -= 2 if self.framed
|
74
|
+
my
|
77
75
|
end
|
78
|
-
def
|
79
|
-
x
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
self.
|
84
|
-
blank = " " * self.maxx
|
85
|
-
cp = Curses::Window.pair(self.fg, self.bg)
|
86
|
-
y.times {self.attron(color_pair(cp)) {self << blank}}
|
87
|
-
self.refresh
|
88
|
-
self.setpos(y, x)
|
76
|
+
def x(x) # SET/GOTO X (COLUMN)
|
77
|
+
x += 1 if self.framed
|
78
|
+
mx = self.mx?
|
79
|
+
x = mx if x > mx
|
80
|
+
y = self.cury
|
81
|
+
self.setpos(y,x)
|
89
82
|
end
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
self.
|
96
|
-
|
97
|
-
|
98
|
-
|
83
|
+
def y(y) # SET/GOTO Y (ROW)
|
84
|
+
y += 1 if self.framed
|
85
|
+
my = self.my?
|
86
|
+
y = my if y > my
|
87
|
+
x = self.curx
|
88
|
+
self.setpos(y,x)
|
89
|
+
end
|
90
|
+
def xy(x,y) # SET/GOTO X & Y (COLUMN & ROW)
|
91
|
+
x += 1 if self.framed
|
92
|
+
y += 1 if self.framed
|
93
|
+
mx = self.mx?
|
94
|
+
x = mx if x > mx?
|
95
|
+
my = self.my?
|
96
|
+
y = my if y > my?
|
97
|
+
self.setpos(y,x)
|
98
|
+
end
|
99
|
+
def fill(bg = self.bg, l1 = 0, l2 = self.my?) # FILL WINDOW WITH BG COLOR FROM LINES L1 TO L2
|
100
|
+
self.xy(0, l1)
|
101
|
+
bg = 0 if self.bg == nil
|
102
|
+
blank = " " * self.mx?
|
103
|
+
cp = Curses::Window.pair(0, bg)
|
104
|
+
lines = l2 - l1
|
105
|
+
lines.times do
|
106
|
+
y = self.y?
|
107
|
+
self.attron(color_pair(cp)) {self << blank}
|
108
|
+
self.xy(0,y+1)
|
109
|
+
end
|
99
110
|
self.refresh
|
100
|
-
self.
|
111
|
+
self.xy(0, 0)
|
101
112
|
end
|
102
|
-
def p(fg = self.fg, bg = self.bg, attr = self.attr, text) #
|
113
|
+
def p(fg = self.fg, bg = self.bg, attr = self.attr, text) # PUTS TEXT TO WINDOW WITH FULL SET OF ATTRIBUTES
|
103
114
|
fg = 255 if fg == nil
|
104
115
|
bg = 0 if bg == nil
|
105
116
|
attr = 0 if attr == nil
|
@@ -107,25 +118,49 @@ class Curses::Window # CLASS EXTENSION
|
|
107
118
|
self.attron(color_pair(cp) | attr) { self << text }
|
108
119
|
self.refresh
|
109
120
|
end
|
110
|
-
def nl(bg = self.bg)
|
121
|
+
def nl(bg = self.bg) # ADD NEWLINE
|
122
|
+
y = self.y?
|
111
123
|
bg = 232 if bg == nil
|
112
|
-
f = " " * (self.
|
124
|
+
f = " " * (self.mx? - self.x?)
|
113
125
|
self.p(self.fg, bg, self.attr, f)
|
126
|
+
self.xy(0,y+1)
|
114
127
|
end
|
115
|
-
def
|
128
|
+
def p0(fg = self.fg, bg = self.bg, attr = self.attr, text) # PUTS TEXT AT 0,0 AND CLEARS THE REST OF THE LINE
|
129
|
+
self.xy(0, 0)
|
116
130
|
self.p(fg, bg, attr, text)
|
117
|
-
self.
|
131
|
+
self.nl(bg)
|
132
|
+
self.xy(0, 0)
|
118
133
|
end
|
119
|
-
def frame(fg = self.fg, bg = self.bg)
|
134
|
+
def frame(fg = self.fg, bg = self.bg) # TOGGLE FRAMING OF THE WINDOW
|
135
|
+
fr = self.framed
|
136
|
+
tl = self.framed ? " " : "┌"
|
137
|
+
tc = self.framed ? " " : "─"
|
138
|
+
tr = self.framed ? " " : "┐"
|
139
|
+
lr = self.framed ? " " : "│"
|
140
|
+
bl = self.framed ? " " : "└"
|
141
|
+
bc = self.framed ? " " : "─"
|
142
|
+
br = self.framed ? " " : "┘"
|
120
143
|
self.setpos(0,0)
|
121
|
-
self.p(
|
122
|
-
(self.maxy-2).times
|
123
|
-
|
144
|
+
self.p(tl + tc*(self.maxx-2) + tr)
|
145
|
+
(self.maxy-2).times do
|
146
|
+
y = self.cury
|
147
|
+
mx = self.maxx
|
148
|
+
self.setpos(y,0); self.p(lr)
|
149
|
+
self.setpos(y,maxx-1); self.p(lr)
|
150
|
+
end
|
151
|
+
self.p(bl + bc*(self.maxx-2) + br)
|
152
|
+
if self.framed == nil
|
153
|
+
self.framed = true
|
154
|
+
else
|
155
|
+
self.framed = !self.framed
|
156
|
+
end
|
157
|
+
self.xy(0,0)
|
124
158
|
end
|
125
|
-
def format(text) #
|
159
|
+
def format(text) # FORMAT TEXT SO THAT IT LINEBREAKS NEATLY INSIDE WINDOW
|
126
160
|
return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
|
127
161
|
end
|
128
162
|
alias :puts :p
|
163
|
+
alias :puts0 :p0
|
129
164
|
end
|
130
165
|
|
131
166
|
# GENERAL FUNCTIONS
|
@@ -181,10 +216,8 @@ def main_getkey # GET KEY FROM USER
|
|
181
216
|
chr = getchr
|
182
217
|
case chr
|
183
218
|
when '?' # Show helptext in right window - add code to show help text here
|
184
|
-
|
185
|
-
|
186
|
-
@w_t.nl
|
187
|
-
@w_t.update = false
|
219
|
+
@w_t.p0(255,27,"Try pressing 'w'")
|
220
|
+
@w_t.update = false
|
188
221
|
# Examples of moving up and down in a window
|
189
222
|
# You must set @min_index and @max_index in the main loop of the program
|
190
223
|
when 'UP'
|
@@ -220,7 +253,8 @@ def main_getkey # GET KEY FROM USER
|
|
220
253
|
@w_w.p(255,52," NO!! ")
|
221
254
|
end
|
222
255
|
chrw = getchr
|
223
|
-
@
|
256
|
+
@w_l.fill; @w_r.fill # Fill the underlying windows to remove the overlaying window
|
257
|
+
@w_w.close # Remove the overlying window from memory
|
224
258
|
when 'a'
|
225
259
|
# ...etc
|
226
260
|
when 'r'
|
@@ -229,10 +263,8 @@ def main_getkey # GET KEY FROM USER
|
|
229
263
|
exit 0
|
230
264
|
when '@' # Enter "Ruby debug"
|
231
265
|
cmd = w_b_getstr("◆ ", "")
|
232
|
-
@w_b.clr
|
233
|
-
@w_b.refresh
|
234
266
|
@w_b.update = true
|
235
|
-
@w_r.
|
267
|
+
@w_r.fill
|
236
268
|
info = "Command: #{cmd}\n\n"
|
237
269
|
begin
|
238
270
|
info += eval(cmd).to_s
|
@@ -247,8 +279,8 @@ def main_getkey # GET KEY FROM USER
|
|
247
279
|
@w_r.p(eval(cmd))
|
248
280
|
rescue StandardError => e
|
249
281
|
w_b("Error: #{e.inspect}")
|
282
|
+
chr = STDIN.getc
|
250
283
|
end
|
251
|
-
#@w_b.update = false
|
252
284
|
end
|
253
285
|
while STDIN.ready?
|
254
286
|
chr = STDIN.getc
|
@@ -259,11 +291,12 @@ end
|
|
259
291
|
|
260
292
|
# BOTTOM WINDOW FUNCTIONS
|
261
293
|
def w_b(info) # SHOW INFO IN @W_B
|
262
|
-
@w_b.
|
263
|
-
info = "Choose window: i=IMDB list (+/- to add/remove from
|
264
|
-
info = info[1..(@w_b.
|
265
|
-
info += " " * (@w_b.
|
294
|
+
@w_b.fill
|
295
|
+
info = "Choose window: i=IMDB list (+/- to add/remove from my? list), g=Genres (+/- to add/remove), m=my? list. " if info == nil
|
296
|
+
info = info[1..(@w_b.mx? - 3)] + "…" if info.length + 3 > @w_b.mx?
|
297
|
+
info += " " * (@w_b.mx? - info.length) if info.length < @w_b.mx?
|
266
298
|
@w_b.p(info)
|
299
|
+
@w_b.nl
|
267
300
|
@w_b.update = false
|
268
301
|
end
|
269
302
|
def w_b_getstr(pretext, text) # A SIMPLE READLINE-LIKE ROUTINE
|
@@ -273,11 +306,10 @@ def w_b_getstr(pretext, text) # A SIMPLE READLINE-LIKE ROUTINE
|
|
273
306
|
pos = text.length
|
274
307
|
chr = ""
|
275
308
|
while chr != "ENTER"
|
276
|
-
@w_b.
|
277
|
-
|
278
|
-
|
279
|
-
@w_b.
|
280
|
-
@w_b.setpos(0,pretext.length + pos)
|
309
|
+
@w_b.xy(0,0)
|
310
|
+
@w_b.p(pretext + text)
|
311
|
+
@w_b.nl
|
312
|
+
@w_b.xy(pretext.length + pos,0)
|
281
313
|
@w_b.refresh
|
282
314
|
chr = getchr
|
283
315
|
case chr
|
@@ -306,8 +338,8 @@ def w_b_getstr(pretext, text) # A SIMPLE READLINE-LIKE ROUTINE
|
|
306
338
|
pos += 1
|
307
339
|
end
|
308
340
|
end
|
309
|
-
Curses.curs_set(0)
|
310
|
-
Curses.noecho
|
341
|
+
Curses.curs_set(1); Curses.curs_set(0)
|
342
|
+
#Curses.noecho
|
311
343
|
return text
|
312
344
|
end
|
313
345
|
|
@@ -339,18 +371,24 @@ loop do # OUTER LOOP - (catching refreshes via 'r')
|
|
339
371
|
# Set foreground and background colors and attributes
|
340
372
|
@w_t.fg, @w_t.bg, @w_t.attr = 255, 23, 0
|
341
373
|
@w_b.fg, @w_b.bg, @w_b.attr = 231, 238, 0
|
342
|
-
@w_l.fg, @w_l.bg, @w_l.attr =
|
374
|
+
@w_l.fg, @w_l.bg, @w_l.attr = 24, 233, 0
|
343
375
|
@w_r.fg, @w_r.bg, @w_r.attr = 202, 235, 0
|
344
|
-
@w_t.
|
376
|
+
@w_t.update = true
|
377
|
+
@w_b.update = true
|
378
|
+
@w_l.update = true
|
379
|
+
@w_r.update = true
|
380
|
+
@w_l.fill; @w_r.fill
|
345
381
|
loop do # INNER, CORE LOOP
|
346
|
-
@w_b.fill; @w_l.fill; @w_r.fill
|
347
382
|
# Example code to write to the panes in various ways
|
348
|
-
@w_t.
|
349
|
-
@w_b.
|
350
|
-
@w_l.
|
351
|
-
@w_l.
|
352
|
-
@
|
353
|
-
@
|
383
|
+
@w_t.p0("Top window") if @w_t.update
|
384
|
+
@w_b.p0("Bottom window - try pressing '?'") if @w_b.update
|
385
|
+
@w_l.frame
|
386
|
+
@w_l.xy(@w_l.mx?/2-6, @w_l.my?/2)
|
387
|
+
@w_l.p(87,17,Curses::A_BOLD,"Left window")
|
388
|
+
@w_l.fill(24, 1, 2)
|
389
|
+
@w_l.fill(24,@w_l.my?-2,@w_l.my?-1)
|
390
|
+
@w_r.xy(@w_r.mx?/2-7, @w_r.my?/2)
|
391
|
+
@w_r.p("Right window") if @w_r.update
|
354
392
|
|
355
393
|
# Top window (info line)
|
356
394
|
|
@@ -360,6 +398,9 @@ loop do # OUTER LOOP - (catching refreshes via 'r')
|
|
360
398
|
|
361
399
|
# Right window
|
362
400
|
|
401
|
+
# Clear residual cursor
|
402
|
+
Curses.curs_set(1); Curses.curs_set(0)
|
403
|
+
|
363
404
|
# Get key from user
|
364
405
|
main_getkey
|
365
406
|
|
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: '3.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-13 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
|
-
the curses-template.rb more informative and sexy'
|
38
|
+
basis for my own curses applications. New in 3.0: Major rewrite. Lots of changes/improvements.'
|
40
39
|
email: g@isene.com
|
41
40
|
executables: []
|
42
41
|
extensions: []
|