curses-extension 2.2 → 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 +38 -15
- data/lib/curses-extension.rb +89 -48
- data/lib/curses-template.rb +157 -83
- 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
@@ -1,6 +1,8 @@
|
|
1
1
|
# Ruby-Curses-Class-Extension
|
2
2
|
Extending the Ruby Curses module with some obvious needed functionality.
|
3
3
|
|
4
|
+
No more fiddling with color pairs. No more manual filling lines or framing.
|
5
|
+
|
4
6
|
With this extension, you don't need to initiate any color pairs or add text to
|
5
7
|
windows with odd syntax. Use any foreground and backround color you see fit
|
6
8
|
and let this extension take care of the weird need to pair colors and initiate
|
@@ -13,31 +15,52 @@ default foreground, background and attribute for a window (e.g. `win.fg =
|
|
13
15
|
to a window with `win.p("Hello World")` where the defaults will be applied.
|
14
16
|
You can override the defaults with e.g. `win.p(124, "Hello World")` to write
|
15
17
|
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.
|
18
|
+
the text in bold green on a gray background.
|
19
|
+
|
20
|
+
There is also the handy method `nl` that fills the rest of the line with
|
21
|
+
spaces and (optional) background color, making it an effective newline.
|
22
|
+
|
23
|
+
And then there is the convenient `frame`method that toggles a frame for the
|
24
|
+
window.
|
17
25
|
|
26
|
+
The `curses-template.rb` contains code that helps you understand how you can
|
27
|
+
easily create curses applications in Ruby. It is a fully runnable app that
|
28
|
+
doesn't do much - but you can fiddle around with the code and test
|
29
|
+
functionality for yourself.
|
18
30
|
|
19
31
|
## Attributes
|
20
32
|
Attribute | Description
|
21
33
|
--------------------|--------------------------------------------------------
|
22
34
|
fg | Foreground color for window (0-255)
|
23
35
|
bg | Background color for window (0-255)
|
24
|
-
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)
|
25
37
|
update | Whether to update the window on the next refresh
|
26
38
|
index | Used to track an index for each window (used to display lists such as the content of a directory, etc.)
|
27
39
|
|
28
|
-
## Functions
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
+
|
47
|
+
Parameters in square are optional.
|
48
|
+
|
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
|
41
64
|
|
42
65
|
## Curses template
|
43
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,73 +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
|
+
end
|
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)
|
57
66
|
end
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
self.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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)
|
101
|
+
end
|
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 ? " " : "┘"
|
111
|
+
self.setpos(0,0)
|
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)
|
86
126
|
end
|
87
|
-
def format(text) #
|
127
|
+
def format(text) # FORMAT TEXT SO THAT IT LINEBREAKS NEATLY INSIDE WINDOW
|
88
128
|
return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
|
89
129
|
end
|
90
130
|
alias :puts :p
|
131
|
+
alias :puts0 :p0
|
91
132
|
end
|
92
133
|
|
93
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
|
-
|
85
|
-
|
86
|
-
y
|
87
|
-
self.
|
88
|
-
|
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)
|
82
|
+
end
|
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)
|
89
98
|
end
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
self.
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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,21 +118,52 @@ 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)
|
133
|
+
end
|
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 ? " " : "┘"
|
143
|
+
self.setpos(0,0)
|
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)
|
118
158
|
end
|
119
|
-
def format(text) #
|
159
|
+
def format(text) # FORMAT TEXT SO THAT IT LINEBREAKS NEATLY INSIDE WINDOW
|
120
160
|
return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
|
121
161
|
end
|
122
162
|
alias :puts :p
|
163
|
+
alias :puts0 :p0
|
123
164
|
end
|
124
165
|
|
166
|
+
# GENERAL FUNCTIONS
|
125
167
|
def getchr # Process key presses
|
126
168
|
c = STDIN.getch
|
127
169
|
#c = STDIN.getch(min: 0, time: 1) # Use this if you need to poll for user keys
|
@@ -170,27 +212,50 @@ def getchr # Process key presses
|
|
170
212
|
end
|
171
213
|
return chr
|
172
214
|
end
|
173
|
-
|
174
215
|
def main_getkey # GET KEY FROM USER
|
175
216
|
chr = getchr
|
176
217
|
case chr
|
177
|
-
when '?' # Show helptext in right window
|
178
|
-
|
179
|
-
|
180
|
-
|
218
|
+
when '?' # Show helptext in right window - add code to show help text here
|
219
|
+
@w_t.p0(255,27,"Try pressing 'w'")
|
220
|
+
@w_t.update = false
|
221
|
+
# Examples of moving up and down in a window
|
222
|
+
# You must set @min_index and @max_index in the main loop of the program
|
223
|
+
when 'UP'
|
224
|
+
@w_l.index = @w_l.index <= @min_index ? @max_index : @w_l.index - 1
|
181
225
|
when 'DOWN'
|
182
|
-
@index = @index >= @max_index ? @min_index : @index + 1
|
226
|
+
@w_l.index = @w_l.index >= @max_index ? @min_index : @w_l.index + 1
|
183
227
|
when 'PgUP'
|
184
|
-
@index -= @w_l.maxy - 2
|
185
|
-
@index = @min_index if @index < @min_index
|
228
|
+
@w_l.index -= @w_l.maxy - 2
|
229
|
+
@w_l.index = @min_index if @w_l.index < @min_index
|
186
230
|
when 'PgDOWN'
|
187
|
-
@index += @w_l.maxy - 2
|
188
|
-
@index = @max_index if @index > @max_index
|
231
|
+
@w_l.index += @w_l.maxy - 2
|
232
|
+
@w_l.index = @max_index if @w_l.index > @max_index
|
189
233
|
when 'HOME'
|
190
|
-
@index = @min_index
|
234
|
+
@w_l.index = @min_index
|
191
235
|
when 'END'
|
192
|
-
@index = @max_index
|
193
|
-
when '
|
236
|
+
@w_l.index = @max_index
|
237
|
+
when 'w' # Shows how you can add a window and get input from there and then close the window
|
238
|
+
maxx = Curses.cols
|
239
|
+
maxy = Curses.lines
|
240
|
+
# Curses::Window.new ( h, w, y, x)
|
241
|
+
@w_w = Curses::Window.new( 6, 20, maxy/2-3, maxx/2-10)
|
242
|
+
@w_w.fg, @w_w.bg, @w_w.attr = 255, 233, Curses::A_BOLD
|
243
|
+
@w_w.frame
|
244
|
+
@w_w.setpos(4, 7)
|
245
|
+
@w_w.p(255,130," y/n? ")
|
246
|
+
chrw = getchr
|
247
|
+
case chrw
|
248
|
+
when 'y'
|
249
|
+
@w_w.setpos(4, 7)
|
250
|
+
@w_w.p(255,22," YES! ")
|
251
|
+
when 'n'
|
252
|
+
@w_w.setpos(4, 7)
|
253
|
+
@w_w.p(255,52," NO!! ")
|
254
|
+
end
|
255
|
+
chrw = getchr
|
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
|
258
|
+
when 'a'
|
194
259
|
# ...etc
|
195
260
|
when 'r'
|
196
261
|
@break = true
|
@@ -198,10 +263,8 @@ def main_getkey # GET KEY FROM USER
|
|
198
263
|
exit 0
|
199
264
|
when '@' # Enter "Ruby debug"
|
200
265
|
cmd = w_b_getstr("◆ ", "")
|
201
|
-
@w_b.clr
|
202
|
-
@w_b.refresh
|
203
266
|
@w_b.update = true
|
204
|
-
@w_r.
|
267
|
+
@w_r.fill
|
205
268
|
info = "Command: #{cmd}\n\n"
|
206
269
|
begin
|
207
270
|
info += eval(cmd).to_s
|
@@ -216,8 +279,8 @@ def main_getkey # GET KEY FROM USER
|
|
216
279
|
@w_r.p(eval(cmd))
|
217
280
|
rescue StandardError => e
|
218
281
|
w_b("Error: #{e.inspect}")
|
282
|
+
chr = STDIN.getc
|
219
283
|
end
|
220
|
-
#@w_b.update = false
|
221
284
|
end
|
222
285
|
while STDIN.ready?
|
223
286
|
chr = STDIN.getc
|
@@ -228,11 +291,12 @@ end
|
|
228
291
|
|
229
292
|
# BOTTOM WINDOW FUNCTIONS
|
230
293
|
def w_b(info) # SHOW INFO IN @W_B
|
231
|
-
@w_b.
|
232
|
-
info = "Choose window: i=IMDB list (+/- to add/remove from
|
233
|
-
info = info[1..(@w_b.
|
234
|
-
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?
|
235
298
|
@w_b.p(info)
|
299
|
+
@w_b.nl
|
236
300
|
@w_b.update = false
|
237
301
|
end
|
238
302
|
def w_b_getstr(pretext, text) # A SIMPLE READLINE-LIKE ROUTINE
|
@@ -242,11 +306,10 @@ def w_b_getstr(pretext, text) # A SIMPLE READLINE-LIKE ROUTINE
|
|
242
306
|
pos = text.length
|
243
307
|
chr = ""
|
244
308
|
while chr != "ENTER"
|
245
|
-
@w_b.
|
246
|
-
|
247
|
-
|
248
|
-
@w_b.
|
249
|
-
@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)
|
250
313
|
@w_b.refresh
|
251
314
|
chr = getchr
|
252
315
|
case chr
|
@@ -275,8 +338,8 @@ def w_b_getstr(pretext, text) # A SIMPLE READLINE-LIKE ROUTINE
|
|
275
338
|
pos += 1
|
276
339
|
end
|
277
340
|
end
|
278
|
-
Curses.curs_set(0)
|
279
|
-
Curses.noecho
|
341
|
+
Curses.curs_set(1); Curses.curs_set(0)
|
342
|
+
#Curses.noecho
|
280
343
|
return text
|
281
344
|
end
|
282
345
|
|
@@ -308,16 +371,24 @@ loop do # OUTER LOOP - (catching refreshes via 'r')
|
|
308
371
|
# Set foreground and background colors and attributes
|
309
372
|
@w_t.fg, @w_t.bg, @w_t.attr = 255, 23, 0
|
310
373
|
@w_b.fg, @w_b.bg, @w_b.attr = 231, 238, 0
|
311
|
-
@w_l.fg, @w_l.bg, @w_l.attr =
|
374
|
+
@w_l.fg, @w_l.bg, @w_l.attr = 24, 233, 0
|
312
375
|
@w_r.fg, @w_r.bg, @w_r.attr = 202, 235, 0
|
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
|
313
381
|
loop do # INNER, CORE LOOP
|
314
|
-
@w_t.fill; @w_b.fill; @w_l.fill; @w_r.fill
|
315
|
-
|
316
382
|
# Example code to write to the panes in various ways
|
317
|
-
@w_t.
|
318
|
-
@w_b.
|
319
|
-
@w_l.
|
320
|
-
@
|
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
|
321
392
|
|
322
393
|
# Top window (info line)
|
323
394
|
|
@@ -327,6 +398,9 @@ loop do # OUTER LOOP - (catching refreshes via 'r')
|
|
327
398
|
|
328
399
|
# Right window
|
329
400
|
|
401
|
+
# Clear residual cursor
|
402
|
+
Curses.curs_set(1); Curses.curs_set(0)
|
403
|
+
|
330
404
|
# Get key from user
|
331
405
|
main_getkey
|
332
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
|
-
newline"'
|
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: []
|