curses-extension 1.2 → 2.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/lib/README.md +9 -9
- data/lib/curses-extension.rb +48 -49
- data/lib/curses-template.rb +193 -77
- 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,58 +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
|
104
|
+
|
data/lib/curses-template.rb
CHANGED
@@ -8,33 +8,51 @@
|
|
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
|
# +-------------------------------+
|
18
18
|
|
19
|
-
|
20
|
-
require '
|
21
|
-
|
19
|
+
begin #Basic setup
|
20
|
+
require 'io/console'
|
21
|
+
require 'io/wait'
|
22
|
+
require 'curses'
|
23
|
+
include Curses
|
22
24
|
|
23
|
-
Curses.init_screen
|
24
|
-
Curses.start_color
|
25
|
-
Curses.curs_set(0)
|
26
|
-
Curses.noecho
|
27
|
-
Curses.cbreak
|
28
|
-
Curses.stdscr.keypad = true
|
25
|
+
Curses.init_screen
|
26
|
+
Curses.start_color
|
27
|
+
Curses.curs_set(0)
|
28
|
+
Curses.noecho
|
29
|
+
Curses.cbreak
|
30
|
+
Curses.stdscr.keypad = true
|
31
|
+
end
|
29
32
|
|
30
33
|
class Curses::Window # CLASS EXTENSION
|
31
34
|
# General extensions (see https://github.com/isene/Ruby-Curses-Class-Extension)
|
32
|
-
|
33
|
-
#
|
34
|
-
#
|
35
|
-
# self.fg is set for the foreground color
|
36
|
-
# 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
|
37
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
|
38
56
|
def clr # Clears the whole window
|
39
57
|
self.setpos(0, 0)
|
40
58
|
self.maxy.times {self.deleteln()}
|
@@ -61,15 +79,11 @@ class Curses::Window # CLASS EXTENSION
|
|
61
79
|
x = self.curx
|
62
80
|
y = self.cury
|
63
81
|
self.setpos(0, 0)
|
82
|
+
self.bg = 0 if self.bg == nil
|
83
|
+
self.fg = 255 if self.fg == nil
|
64
84
|
blank = " " * self.maxx
|
65
|
-
|
66
|
-
|
67
|
-
self.fg = 255 if self.fg == nil
|
68
|
-
init_pair(self.fg, self.fg, self.bg)
|
69
|
-
y.times {self.attron(color_pair(self.fg)) {self << blank}}
|
70
|
-
else
|
71
|
-
y.times {self.attron(color_pair(self.color)) {self << blank}}
|
72
|
-
end
|
85
|
+
cp = Curses::Window.pair(self.fg, self.bg)
|
86
|
+
y.times {self.attron(color_pair(cp)) {self << blank}}
|
73
87
|
self.refresh
|
74
88
|
self.setpos(y, x)
|
75
89
|
end
|
@@ -77,69 +91,57 @@ class Curses::Window # CLASS EXTENSION
|
|
77
91
|
x = self.curx
|
78
92
|
y = self.cury
|
79
93
|
self.setpos(y, 0)
|
94
|
+
self.bg = 0 if self.bg == nil
|
95
|
+
self.fg = 255 if self.fg == nil
|
80
96
|
blank = " " * self.maxx
|
81
|
-
|
82
|
-
|
83
|
-
self.fg = 255 if self.fg == nil
|
84
|
-
init_pair(self.fg, self.fg, self.bg)
|
85
|
-
self.maxy.times {self.attron(color_pair(self.fg)) {self << blank}}
|
86
|
-
else
|
87
|
-
self.maxy.times {self.attron(color_pair(self.color)) {self << blank}}
|
88
|
-
end
|
97
|
+
cp = Curses::Window.pair(self.fg, self.bg)
|
98
|
+
self.maxy.times {self.attron(color_pair(cp)) {self << blank}}
|
89
99
|
self.refresh
|
90
100
|
self.setpos(y, x)
|
91
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
|
92
110
|
def p(text) # Puts text to window
|
93
111
|
self.attr = 0 if self.attr == nil
|
94
|
-
if self.
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
self.attron(color_pair(self.fg) | self.attr) { self << text }
|
99
|
-
else
|
100
|
-
self.attron(color_pair(self.color) | self.attr) { self << text }
|
101
|
-
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 }
|
102
116
|
self.refresh
|
103
117
|
end
|
104
118
|
def pclr(text) # Puts text to window and clears the rest of the window
|
105
119
|
self.p(text)
|
106
120
|
self.clr_from_cur_line
|
107
121
|
end
|
108
|
-
def
|
109
|
-
|
110
|
-
self.
|
111
|
-
end
|
112
|
-
def pa(fg, bg, attr, text) # Puts text to window with full set of attributes
|
113
|
-
self.fg = fg
|
114
|
-
self.bg = bg
|
115
|
-
self.attr = attr
|
116
|
-
init_pair(self.fg, self.fg, self.bg)
|
117
|
-
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 }
|
118
125
|
self.refresh
|
119
126
|
end
|
120
|
-
def
|
121
|
-
self.
|
122
|
-
self.
|
123
|
-
self.setpos(0, 0)
|
124
|
-
self.print(text, fg, bg, attr)
|
125
|
-
end
|
126
|
-
def print(text, fg=255, bg=0, attr=0) # Print text (from current position) with optional attributes
|
127
|
-
init_pair(fg, fg, bg)
|
128
|
-
self.attron(color_pair(fg) | attr) { self << text }
|
129
|
-
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
|
130
130
|
end
|
131
131
|
def format_text(text) # Format text so that it linebreaks neatly inside window
|
132
132
|
return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
|
133
133
|
end
|
134
|
+
alias :puts :p
|
134
135
|
end
|
135
136
|
|
136
|
-
def getchr #
|
137
|
-
c = STDIN.getch
|
137
|
+
def getchr # Process key presses
|
138
|
+
c = STDIN.getch
|
139
|
+
#c = STDIN.getch(min: 0, time: 1) # Use this if you need to poll for user keys
|
138
140
|
case c
|
139
141
|
when "\e" # ANSI escape sequences
|
140
|
-
case
|
142
|
+
case STDIN.getc
|
141
143
|
when '[' # CSI
|
142
|
-
case
|
144
|
+
case STDIN.getc
|
143
145
|
when 'A' then chr = "UP"
|
144
146
|
when 'B' then chr = "DOWN"
|
145
147
|
when 'C' then chr = "RIGHT"
|
@@ -152,8 +154,8 @@ def getchr # PROCESS KEY PRESSES
|
|
152
154
|
when '7' then chr = "HOME" ; chr = "C-HOME" if STDIN.getc == "^"
|
153
155
|
when '8' then chr = "END" ; chr = "C-END" if STDIN.getc == "^"
|
154
156
|
end
|
155
|
-
when 'O'
|
156
|
-
case
|
157
|
+
when 'O' # Set Ctrl+ArrowKey equal to ArrowKey; May be used for other purposes in the future
|
158
|
+
case STDIN.getc
|
157
159
|
when 'a' then chr = "C-UP"
|
158
160
|
when 'b' then chr = "C-DOWN"
|
159
161
|
when 'c' then chr = "C-RIGHT"
|
@@ -161,12 +163,22 @@ def getchr # PROCESS KEY PRESSES
|
|
161
163
|
end
|
162
164
|
end
|
163
165
|
when "", "" then chr = "BACK"
|
166
|
+
when "" then chr = "C-C"
|
167
|
+
when "" then chr = "C-D"
|
168
|
+
when "" then chr = "C-E"
|
169
|
+
when "" then chr = "C-G"
|
170
|
+
when "" then chr = "C-K"
|
171
|
+
when "" then chr = "C-L"
|
172
|
+
when "" then chr = "C-N"
|
173
|
+
when "" then chr = "C-O"
|
174
|
+
when "" then chr = "C-P"
|
175
|
+
when "" then chr = "C-T"
|
176
|
+
when "" then chr = "C-Y"
|
164
177
|
when "" then chr = "WBACK"
|
165
178
|
when "" then chr = "LDEL"
|
166
|
-
when "" then chr = "C-T"
|
167
179
|
when "\r" then chr = "ENTER"
|
168
180
|
when "\t" then chr = "TAB"
|
169
|
-
when
|
181
|
+
when /[[:print:]]/ then chr = c
|
170
182
|
end
|
171
183
|
return chr
|
172
184
|
end
|
@@ -196,31 +208,134 @@ def main_getkey # GET KEY FROM USER
|
|
196
208
|
@break = true
|
197
209
|
when 'q' # Exit
|
198
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
|
234
|
+
end
|
235
|
+
while STDIN.ready?
|
236
|
+
chr = STDIN.getc
|
199
237
|
end
|
200
238
|
end
|
201
239
|
|
202
240
|
# TOP WINDOW FUNCTIONS
|
203
241
|
|
204
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
|
205
296
|
|
206
297
|
# LEFT WINDOW FUNCTIONS
|
207
298
|
|
208
299
|
# RIGHT WINDOW FUNCTIONS
|
209
|
-
|
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
|
210
310
|
|
211
311
|
# MAIN PROGRAM
|
212
312
|
loop do # OUTER LOOP - (catching refreshes via 'r')
|
213
313
|
@break = false # Initialize @break variable (set if user hits 'r')
|
214
|
-
begin # Create the four windows/
|
314
|
+
begin # Create the four windows/panes
|
215
315
|
maxx = Curses.cols
|
216
|
-
exit if maxx < @w_l_width
|
217
316
|
maxy = Curses.lines
|
218
|
-
#
|
219
|
-
|
220
|
-
@
|
221
|
-
@
|
222
|
-
@
|
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
|
223
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
|
+
|
224
339
|
# Top window (info line)
|
225
340
|
|
226
341
|
# Bottom window (command line)
|
@@ -229,9 +344,10 @@ loop do # OUTER LOOP - (catching refreshes via 'r')
|
|
229
344
|
|
230
345
|
# Right window
|
231
346
|
|
232
|
-
|
347
|
+
# Get key from user
|
348
|
+
main_getkey
|
233
349
|
|
234
|
-
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'
|
235
351
|
break if Curses.cols != maxx or Curses.lines != maxy # break on terminal resize
|
236
352
|
end
|
237
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-
|
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
|
-
`format`.'
|
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: []
|