curses-extension 2.2 → 2.3
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 +27 -11
- data/lib/curses-extension.rb +6 -0
- data/lib/curses-template.rb +50 -17
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42000c1ac48e5ea98e193df0c18c8874146f26e53f671cf84f6338a7dda7cce6
|
4
|
+
data.tar.gz: ec6dad6abda95da23ecbbabc23be1019860f9da2929f6a0f3962baaede26df7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ab8dbfc99e8d9a93c030b5c1a24390abb8b747911cd3bed0a4495ec4fe67d91ee79d8a0415b08ca42f09a624d92fd2644c8bb6cc8fcd67e075ff3ae5807a92a
|
7
|
+
data.tar.gz: ae787aa46b4e57d114714577ae000992bf7a55c40f90eb6a6ca9982c937a05a7294a9f7f99081f5f4617ce576c0ce473ce9a6c448e8bac1cb5685f3809d88b6e
|
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,8 +15,18 @@ 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.
|
17
22
|
|
23
|
+
And then there is the convenient `frame`method that adds a... frame to the
|
24
|
+
window.
|
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
|
@@ -26,18 +38,22 @@ 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
40
|
## Functions
|
41
|
+
Parameters in square are optional.
|
42
|
+
|
29
43
|
Function | Description
|
30
44
|
------------------------------------|--------------------------------------------------------
|
31
|
-
clr
|
32
|
-
clr_to_cur_line
|
33
|
-
clr_from_cur_line
|
34
|
-
fill
|
35
|
-
fill_to_cur_pos
|
36
|
-
fill_from_cur_pos
|
37
|
-
p(fg, bg, attr, text)
|
38
|
-
|
39
|
-
pclr(text)
|
40
|
-
|
45
|
+
clr | Clears window without flicker (win.clear flickers)
|
46
|
+
clr_to_cur_line | Clears the window up to the current line
|
47
|
+
clr_from_cur_line | Clears the rest of the window after the current line
|
48
|
+
fill | Fill window with color as set by :color ( or :bg if not :color is set)
|
49
|
+
fill_to_cur_pos | Fill the window up to the current line
|
50
|
+
fill_from_cur_pos | Fill the rest of the window after the current line
|
51
|
+
p([fg], [bg], [attr], text) | Write text to window with fg/bg and attributes (will handle the exceptions if no colors are set)
|
52
|
+
You can use `puts` instead of `p` (it's an alias). `fg`, `bg` and `attr` are optional parameters
|
53
|
+
pclr(text) | As `p(text)` but also clears the rest of the window
|
54
|
+
nl([bg]) | Newline. Puts spaces with (optional) background colors until the end of the line
|
55
|
+
frame([fg],[bg]) | Frame the window
|
56
|
+
format(text) | Format text so that it linebreaks neatly inside window
|
41
57
|
|
42
58
|
## Curses template
|
43
59
|
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
@@ -84,6 +84,12 @@ class Curses::Window # CLASS EXTENSION
|
|
84
84
|
self.p(fg, bg, attr, text)
|
85
85
|
self.clr_from_cur_line
|
86
86
|
end
|
87
|
+
def frame(fg = self.fg, bg = self.bg)
|
88
|
+
self.setpos(0,0)
|
89
|
+
self.p("┌" + "─"*(self.maxx-2) + "┐")
|
90
|
+
(self.maxy-2).times {self.p("│" + " "*(self.maxx-2) + "│")}
|
91
|
+
self.p("└" + "─"*(self.maxx-2) + "┘")
|
92
|
+
end
|
87
93
|
def format(text) # Format text so that it linebreaks neatly inside window
|
88
94
|
return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
|
89
95
|
end
|
data/lib/curses-template.rb
CHANGED
@@ -116,12 +116,19 @@ class Curses::Window # CLASS EXTENSION
|
|
116
116
|
self.p(fg, bg, attr, text)
|
117
117
|
self.clr_from_cur_line
|
118
118
|
end
|
119
|
+
def frame(fg = self.fg, bg = self.bg)
|
120
|
+
self.setpos(0,0)
|
121
|
+
self.p("┌" + "─"*(self.maxx-2) + "┐")
|
122
|
+
(self.maxy-2).times {self.p("│" + " "*(self.maxx-2) + "│")}
|
123
|
+
self.p("└" + "─"*(self.maxx-2) + "┘")
|
124
|
+
end
|
119
125
|
def format(text) # Format text so that it linebreaks neatly inside window
|
120
126
|
return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
|
121
127
|
end
|
122
128
|
alias :puts :p
|
123
129
|
end
|
124
130
|
|
131
|
+
# GENERAL FUNCTIONS
|
125
132
|
def getchr # Process key presses
|
126
133
|
c = STDIN.getch
|
127
134
|
#c = STDIN.getch(min: 0, time: 1) # Use this if you need to poll for user keys
|
@@ -170,27 +177,51 @@ def getchr # Process key presses
|
|
170
177
|
end
|
171
178
|
return chr
|
172
179
|
end
|
173
|
-
|
174
180
|
def main_getkey # GET KEY FROM USER
|
175
181
|
chr = getchr
|
176
182
|
case chr
|
177
|
-
when '?' # Show helptext in right window
|
178
|
-
|
179
|
-
|
180
|
-
|
183
|
+
when '?' # Show helptext in right window - add code to show help text here
|
184
|
+
@w_t.clr
|
185
|
+
@w_t.p("Try pressing 'w'")
|
186
|
+
@w_t.nl
|
187
|
+
@w_t.update = false
|
188
|
+
# Examples of moving up and down in a window
|
189
|
+
# You must set @min_index and @max_index in the main loop of the program
|
190
|
+
when 'UP'
|
191
|
+
@w_l.index = @w_l.index <= @min_index ? @max_index : @w_l.index - 1
|
181
192
|
when 'DOWN'
|
182
|
-
@index = @index >= @max_index ? @min_index : @index + 1
|
193
|
+
@w_l.index = @w_l.index >= @max_index ? @min_index : @w_l.index + 1
|
183
194
|
when 'PgUP'
|
184
|
-
@index -= @w_l.maxy - 2
|
185
|
-
@index = @min_index if @index < @min_index
|
195
|
+
@w_l.index -= @w_l.maxy - 2
|
196
|
+
@w_l.index = @min_index if @w_l.index < @min_index
|
186
197
|
when 'PgDOWN'
|
187
|
-
@index += @w_l.maxy - 2
|
188
|
-
@index = @max_index if @index > @max_index
|
198
|
+
@w_l.index += @w_l.maxy - 2
|
199
|
+
@w_l.index = @max_index if @w_l.index > @max_index
|
189
200
|
when 'HOME'
|
190
|
-
@index = @min_index
|
201
|
+
@w_l.index = @min_index
|
191
202
|
when 'END'
|
192
|
-
@index = @max_index
|
193
|
-
when '
|
203
|
+
@w_l.index = @max_index
|
204
|
+
when 'w' # Shows how you can add a window and get input from there and then close the window
|
205
|
+
maxx = Curses.cols
|
206
|
+
maxy = Curses.lines
|
207
|
+
# Curses::Window.new ( h, w, y, x)
|
208
|
+
@w_w = Curses::Window.new( 6, 20, maxy/2-3, maxx/2-10)
|
209
|
+
@w_w.fg, @w_w.bg, @w_w.attr = 255, 233, Curses::A_BOLD
|
210
|
+
@w_w.frame
|
211
|
+
@w_w.setpos(4, 7)
|
212
|
+
@w_w.p(255,130," y/n? ")
|
213
|
+
chrw = getchr
|
214
|
+
case chrw
|
215
|
+
when 'y'
|
216
|
+
@w_w.setpos(4, 7)
|
217
|
+
@w_w.p(255,22," YES! ")
|
218
|
+
when 'n'
|
219
|
+
@w_w.setpos(4, 7)
|
220
|
+
@w_w.p(255,52," NO!! ")
|
221
|
+
end
|
222
|
+
chrw = getchr
|
223
|
+
@w_w.close
|
224
|
+
when 'a'
|
194
225
|
# ...etc
|
195
226
|
when 'r'
|
196
227
|
@break = true
|
@@ -310,13 +341,15 @@ loop do # OUTER LOOP - (catching refreshes via 'r')
|
|
310
341
|
@w_b.fg, @w_b.bg, @w_b.attr = 231, 238, 0
|
311
342
|
@w_l.fg, @w_l.bg, @w_l.attr = 46, 234, 0
|
312
343
|
@w_r.fg, @w_r.bg, @w_r.attr = 202, 235, 0
|
344
|
+
@w_t.fill
|
313
345
|
loop do # INNER, CORE LOOP
|
314
|
-
@
|
315
|
-
|
346
|
+
@w_b.fill; @w_l.fill; @w_r.fill
|
316
347
|
# Example code to write to the panes in various ways
|
317
|
-
@w_t.p("Top window")
|
318
|
-
@w_b.p("Bottom window")
|
348
|
+
@w_t.p("Top window") unless @w_t.update == false
|
349
|
+
@w_b.p("Bottom window - try pressing '?'")
|
350
|
+
@w_l.setpos(@w_l.maxy/2, @w_l.maxx/2-6)
|
319
351
|
@w_l.p(196,182,Curses::A_BOLD,"Left window")
|
352
|
+
@w_r.setpos(@w_r.maxy/2, @w_r.maxx/2-7)
|
320
353
|
@w_r.p("Right window")
|
321
354
|
|
322
355
|
# Top window (info line)
|
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.3'
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|
@@ -35,8 +35,8 @@ 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.2:
|
39
|
-
|
38
|
+
basis for my own curses applications. New in 2.2: Added the method `frame` and made
|
39
|
+
the curses-template.rb more informative and sexy'
|
40
40
|
email: g@isene.com
|
41
41
|
executables: []
|
42
42
|
extensions: []
|