curses-extension 1.1.3 → 1.2
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 +31 -0
- data/lib/curses-extension.rb +14 -0
- data/lib/curses-template.rb +27 -6
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7498f40bb4872284aeb236f6a5d585e57ec07f221c932170b33a07c4dd356ae
|
4
|
+
data.tar.gz: b9cd6a36554a25fd3b8c2c7de39a48f74496b04700d017e90cfdc0c9833095d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e6222c8fe2dd03a9746693722cafa3a3faf875c76cf1acdaaad62d7d4d7d4601e60d8c6dc134bdfbdcb52e06d074923b3243c614306b2e258aecdbd7f183221
|
7
|
+
data.tar.gz: 8afba7364535e4f10b1a670908c45c5d94ae1b6ee025aa3b1ebc0c8947e23ce34343745378f7d3136b828d70b886ea87f747623e918770598a41f37447810b55
|
data/lib/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Ruby-Curses-Class-Extension
|
2
|
+
Extending the Ruby Curses module with some obvious functionality
|
3
|
+
|
4
|
+
## Attributes
|
5
|
+
Attribute | Description
|
6
|
+
--------------------|--------------------------------------------------------
|
7
|
+
color | Set the window's color to an already initiated color pair (with `init_pair(index, forground, backround`)
|
8
|
+
fg | Foreground color for window (0-255)
|
9
|
+
bg | Background color for window (0-255)
|
10
|
+
attr | Attributes for window (such as Curses::A_BOLD) - string with "\|" (such as Curses::A_BOLD \| Curses::A_UNDERLINE)
|
11
|
+
update | Whether to update the window on the next refresh
|
12
|
+
|
13
|
+
## Functions
|
14
|
+
Function | Description
|
15
|
+
------------------------------------|--------------------------------------------------------
|
16
|
+
clr | Clears window without flicker (win.clear flickers)
|
17
|
+
clr_to_cur_pos | Clears the window up to the current line
|
18
|
+
clr_from_cur_pos | Clears the rest of the window after the current line
|
19
|
+
fill | Fill window with color as set by :color ( or :bg if not :color is set)
|
20
|
+
fill_to_cur_pos | Fill the window up to the current line
|
21
|
+
fill_from_cur_pos | Fill the rest of the window after the current line
|
22
|
+
p(text) | Write text to window with color or fg/bg and attributes (will handle the exceptions if no colors are set)
|
23
|
+
pclr(text) | As `p(text)` but also clears the rest of the window
|
24
|
+
pa(fg, bg, attr, text) | Write text to window with specified fg, bg and attribute(s)
|
25
|
+
paclr(text) | As `pa(text)` but also clears the rest of the window
|
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
|
28
|
+
format_text(text) | Format text so that it linebreaks neatly inside window
|
29
|
+
|
30
|
+
## Curses template
|
31
|
+
The `curses_template.rb` includes the class extension and serves as the basis for my curses applications.
|
data/lib/curses-extension.rb
CHANGED
@@ -88,4 +88,18 @@ class Curses::Window # CLASS EXTENSION
|
|
88
88
|
self.attron(color_pair(self.fg) | self.attr) { self << text }
|
89
89
|
self.refresh
|
90
90
|
end
|
91
|
+
def puts(text, fg=255, bg=0, attr=0) # Clears window and puts text with optional attributes
|
92
|
+
self.clr
|
93
|
+
self.refresh
|
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
|
101
|
+
end
|
102
|
+
def format_text(text) # Format text so that it linebreaks neatly inside window
|
103
|
+
return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
|
104
|
+
end
|
91
105
|
end
|
data/lib/curses-template.rb
CHANGED
@@ -117,6 +117,20 @@ class Curses::Window # CLASS EXTENSION
|
|
117
117
|
self.attron(color_pair(self.fg) | self.attr) { self << text }
|
118
118
|
self.refresh
|
119
119
|
end
|
120
|
+
def puts(text, fg=255, bg=0, attr=0) # Clears window and puts text with optional attributes
|
121
|
+
self.clr
|
122
|
+
self.refresh
|
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
|
130
|
+
end
|
131
|
+
def format_text(text) # Format text so that it linebreaks neatly inside window
|
132
|
+
return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
|
133
|
+
end
|
120
134
|
end
|
121
135
|
|
122
136
|
def getchr # PROCESS KEY PRESSES
|
@@ -131,12 +145,19 @@ def getchr # PROCESS KEY PRESSES
|
|
131
145
|
when 'C' then chr = "RIGHT"
|
132
146
|
when 'D' then chr = "LEFT"
|
133
147
|
when 'Z' then chr = "S-TAB"
|
134
|
-
when '2' then chr = "INS" ; STDIN.getc
|
135
|
-
when '3' then chr = "DEL" ; STDIN.getc
|
136
|
-
when '5' then chr = "PgUP" ; STDIN.getc
|
137
|
-
when '6' then chr = "PgDOWN" ; STDIN.getc
|
138
|
-
when '7' then chr = "HOME" ; STDIN.getc
|
139
|
-
when '8' then chr = "END" ; STDIN.getc
|
148
|
+
when '2' then chr = "INS" ; chr = "C-INS" if STDIN.getc == "^"
|
149
|
+
when '3' then chr = "DEL" ; chr = "C-DEL" if STDIN.getc == "^"
|
150
|
+
when '5' then chr = "PgUP" ; chr = "C-PgUP" if STDIN.getc == "^"
|
151
|
+
when '6' then chr = "PgDOWN" ; chr = "C-PgDOWN" if STDIN.getc == "^"
|
152
|
+
when '7' then chr = "HOME" ; chr = "C-HOME" if STDIN.getc == "^"
|
153
|
+
when '8' then chr = "END" ; chr = "C-END" if STDIN.getc == "^"
|
154
|
+
end
|
155
|
+
when 'O'
|
156
|
+
case $stdin.getc
|
157
|
+
when 'a' then chr = "C-UP"
|
158
|
+
when 'b' then chr = "C-DOWN"
|
159
|
+
when 'c' then chr = "C-RIGHT"
|
160
|
+
when 'd' then chr = "C-LEFT"
|
140
161
|
end
|
141
162
|
end
|
142
163
|
when "", "" then chr = "BACK"
|
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: 1.
|
4
|
+
version: '1.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geir Isene
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|
@@ -35,12 +35,14 @@ 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 1.
|
38
|
+
basis for my own curses applications. New in 1.2: Added functions `print`, `puts`and
|
39
|
+
`format`.'
|
39
40
|
email: g@isene.com
|
40
41
|
executables: []
|
41
42
|
extensions: []
|
42
43
|
extra_rdoc_files: []
|
43
44
|
files:
|
45
|
+
- lib/README.md
|
44
46
|
- lib/curses-extension.rb
|
45
47
|
- lib/curses-template.rb
|
46
48
|
homepage: https://isene.com/
|
@@ -63,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
65
|
- !ruby/object:Gem::Version
|
64
66
|
version: '0'
|
65
67
|
requirements: []
|
66
|
-
rubygems_version: 3.
|
68
|
+
rubygems_version: 3.3.5
|
67
69
|
signing_key:
|
68
70
|
specification_version: 4
|
69
71
|
summary: Extending the Ruby Curses module with some obvious functionality
|