curses-extension 1.1.4 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20ace1645f195ea2d92bbf0cb9b84955194bfc10d1eaee5f9d535a0dd8c18668
4
- data.tar.gz: 9b2b5cc6e581753260fd16c9a474f0bdf19fc108a050d1e64671212009eb42f4
3
+ metadata.gz: 7a03325b4dbf6aa5c2cd506e50e642f62588a07cc543314d98eafce40cb7d2e3
4
+ data.tar.gz: 2862dc209031c64df476ca07c3bd7fcba8f2929620966492f53f858903f30207
5
5
  SHA512:
6
- metadata.gz: 49d8d315491a99d4c3cb343d10d2d0c8f1bdce3d988458e9fdea17a38b213822accc77e49ac5f517c329a987131e13fc8cb761d12f64259f7bed05e683a7dd6a
7
- data.tar.gz: 2a1de1c02140013d55fd8ae130ab55267ba80a5ba3374727aac41ad1d9652031a1a853127a5d67fdea1799287237457b55217cac3891df3861747e67fe2d4aed
6
+ metadata.gz: be4ab27081169af7f9219df23272012e287e3f838f78407bc495d7470f522d1c1fd9c945c7b3ce99ea9dd48a81930ab2a7411e76efbe0b11d75da18a86af425d
7
+ data.tar.gz: 3eaa3fba2972af226cffa6380d55a3a3e034bc0ba8984c2893d6cec6cee7801eafdbbae023c711195217f5def9e48e34450dbf97229762d9a20d1f7b8ad4a6bd
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.
@@ -1,6 +1,6 @@
1
1
  class Curses::Window # CLASS EXTENSION
2
2
  # General extensions (see https://github.com/isene/Ruby-Curses-Class-Extension)
3
- attr_accessor :color, :fg, :bg, :attr, :update
3
+ attr_accessor :color, :fg, :bg, :attr, :update, :index
4
4
  # Set self.color for an already defined color pair such as: init_pair(1, 255, 3)
5
5
  # The color pair is defined like this: init_pair(index, foreground, background)
6
6
  # self.fg is set for the foreground color (and is used if self.color is not set)
@@ -88,4 +88,20 @@ 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
106
+
107
+ # vim: set sw=2 sts=2 et fdm=syntax fdn=2 fcs=fold\:\ :
@@ -16,20 +16,23 @@
16
16
  # | @w_b |
17
17
  # +-------------------------------+
18
18
 
19
- require 'io/console'
20
- require 'curses'
21
- include Curses
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
- attr_accessor :color, :fg, :bg, :attr, :update
35
+ attr_accessor :color, :fg, :bg, :attr, :update, :index
33
36
  # Set self.color for an already defined color pair such as: init_pair(1, 255, 3)
34
37
  # The color pair is defined like this: init_pair(index, foreground, background)
35
38
  # self.fg is set for the foreground color (and is used if self.color is not set)
@@ -117,15 +120,30 @@ class Curses::Window # CLASS EXTENSION
117
120
  self.attron(color_pair(self.fg) | self.attr) { self << text }
118
121
  self.refresh
119
122
  end
123
+ def puts(text, fg=255, bg=0, attr=0) # Clears window and puts text with optional attributes
124
+ self.clr
125
+ self.refresh
126
+ self.setpos(0, 0)
127
+ self.print(text, fg, bg, attr)
128
+ end
129
+ def print(text, fg=255, bg=0, attr=0) # Print text (from current position) with optional attributes
130
+ init_pair(fg, fg, bg)
131
+ self.attron(color_pair(fg) | attr) { self << text }
132
+ self.refresh
133
+ end
134
+ def format_text(text) # Format text so that it linebreaks neatly inside window
135
+ return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
136
+ end
120
137
  end
121
138
 
122
- def getchr # PROCESS KEY PRESSES
123
- c = STDIN.getch(min: 0, time: 1)
139
+ def getchr # Process key presses
140
+ c = STDIN.getch
141
+ #c = STDIN.getch(min: 0, time: 1) # Use this if you need to poll for user keys
124
142
  case c
125
143
  when "\e" # ANSI escape sequences
126
- case $stdin.getc
144
+ case STDIN.getc
127
145
  when '[' # CSI
128
- case $stdin.getc
146
+ case STDIN.getc
129
147
  when 'A' then chr = "UP"
130
148
  when 'B' then chr = "DOWN"
131
149
  when 'C' then chr = "RIGHT"
@@ -138,8 +156,8 @@ def getchr # PROCESS KEY PRESSES
138
156
  when '7' then chr = "HOME" ; chr = "C-HOME" if STDIN.getc == "^"
139
157
  when '8' then chr = "END" ; chr = "C-END" if STDIN.getc == "^"
140
158
  end
141
- when 'O'
142
- case $stdin.getc
159
+ when 'O' # Set Ctrl+ArrowKey equal to ArrowKey; May be used for other purposes in the future
160
+ case STDIN.getc
143
161
  when 'a' then chr = "C-UP"
144
162
  when 'b' then chr = "C-DOWN"
145
163
  when 'c' then chr = "C-RIGHT"
@@ -147,12 +165,22 @@ def getchr # PROCESS KEY PRESSES
147
165
  end
148
166
  end
149
167
  when "", "" then chr = "BACK"
168
+ when "" then chr = "C-C"
169
+ when "" then chr = "C-D"
170
+ when "" then chr = "C-E"
171
+ when "" then chr = "C-G"
172
+ when " " then chr = "C-K"
173
+ when " " then chr = "C-L"
174
+ when "" then chr = "C-N"
175
+ when "" then chr = "C-O"
176
+ when "" then chr = "C-P"
177
+ when "" then chr = "C-T"
178
+ when "" then chr = "C-Y"
150
179
  when "" then chr = "WBACK"
151
180
  when "" then chr = "LDEL"
152
- when "" then chr = "C-T"
153
181
  when "\r" then chr = "ENTER"
154
182
  when "\t" then chr = "TAB"
155
- when /./ then chr = c
183
+ when /[[:print:]]/ then chr = c
156
184
  end
157
185
  return chr
158
186
  end
@@ -183,6 +211,9 @@ def main_getkey # GET KEY FROM USER
183
211
  when 'q' # Exit
184
212
  exit 0
185
213
  end
214
+ while STDIN.ready?
215
+ chr = STDIN.getc
216
+ end
186
217
  end
187
218
 
188
219
  # TOP WINDOW FUNCTIONS
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.1.4
4
+ version: '1.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: 2021-12-18 00:00:00.000000000 Z
11
+ date: 2023-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -35,13 +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.1.4: In the template, also catch
39
- Control+Key sequence'
38
+ basis for my own curses applications. New in 1.3: Included :index as Class accessor
39
+ and other improvements'
40
40
  email: g@isene.com
41
41
  executables: []
42
42
  extensions: []
43
43
  extra_rdoc_files: []
44
44
  files:
45
+ - lib/README.md
45
46
  - lib/curses-extension.rb
46
47
  - lib/curses-template.rb
47
48
  homepage: https://isene.com/
@@ -64,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
65
  - !ruby/object:Gem::Version
65
66
  version: '0'
66
67
  requirements: []
67
- rubygems_version: 3.1.2
68
+ rubygems_version: 3.3.5
68
69
  signing_key:
69
70
  specification_version: 4
70
71
  summary: Extending the Ruby Curses module with some obvious functionality