curses-extension 2.3 → 3.0

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: 42000c1ac48e5ea98e193df0c18c8874146f26e53f671cf84f6338a7dda7cce6
4
- data.tar.gz: ec6dad6abda95da23ecbbabc23be1019860f9da2929f6a0f3962baaede26df7c
3
+ metadata.gz: f99e5edb8a0e53f52e18c5f5c8ad401fb50092275288cbc32fa6bf0c7c18cc07
4
+ data.tar.gz: 20842d9a7eeea019df04a4e29073322c6a351c998fe45e0424d5cd4abd8d7cff
5
5
  SHA512:
6
- metadata.gz: 2ab8dbfc99e8d9a93c030b5c1a24390abb8b747911cd3bed0a4495ec4fe67d91ee79d8a0415b08ca42f09a624d92fd2644c8bb6cc8fcd67e075ff3ae5807a92a
7
- data.tar.gz: ae787aa46b4e57d114714577ae000992bf7a55c40f90eb6a6ca9982c937a05a7294a9f7f99081f5f4617ce576c0ce473ce9a6c448e8bac1cb5685f3809d88b6e
6
+ metadata.gz: 71bd0aa9bb4fd5246454af6dcd92f38b0cccbaf1d11412a1e309892b18e99aa0f2e1269ccb52979245e970e1faf6acf5f55a753eace7bf9ef5a4d7e01744b973
7
+ data.tar.gz: 221a4711ff5cf9eb22b4eab34b0e7e174c4fa4164bae7d2a2e54d94c941240b7412729acf600f2bd4228f375b2b339b61b0f552c184336008d4cced4542d0631
data/lib/README.md CHANGED
@@ -20,7 +20,7 @@ the text in bold green on a gray background.
20
20
  There is also the handy method `nl` that fills the rest of the line with
21
21
  spaces and (optional) background color, making it an effective newline.
22
22
 
23
- And then there is the convenient `frame`method that adds a... frame to the
23
+ And then there is the convenient `frame`method that toggles a frame for the
24
24
  window.
25
25
 
26
26
  The `curses-template.rb` contains code that helps you understand how you can
@@ -33,27 +33,34 @@ Attribute | Description
33
33
  --------------------|--------------------------------------------------------
34
34
  fg | Foreground color for window (0-255)
35
35
  bg | Background color for window (0-255)
36
- attr | Attributes for window (such as Curses::A_BOLD) - string with "\|" (such as Curses::A_BOLD \| Curses::A_UNDERLINE)
36
+ attr | Attributes for window (such as Curses::A_BOLD) - combine with "\|" (such as Curses::A_BOLD \| Curses::A_UNDERLINE)
37
37
  update | Whether to update the window on the next refresh
38
38
  index | Used to track an index for each window (used to display lists such as the content of a directory, etc.)
39
39
 
40
- ## Functions
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
+
41
47
  Parameters in square are optional.
42
48
 
43
- Function | Description
44
- ------------------------------------|--------------------------------------------------------
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
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
57
64
 
58
65
  ## Curses template
59
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.
@@ -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,79 +21,114 @@ class Curses::Window # CLASS EXTENSION
21
21
  @p.index([fg,bg])
22
22
  end
23
23
  end
24
- def clr # Clears the whole window
25
- self.setpos(0, 0)
26
- self.maxy.times {self.deleteln()}
27
- self.refresh
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 clr_to_cur_line
31
- l = self.cury
32
- self.setpos(0, 0)
33
- l.times {self.deleteln()}
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 clr_from_cur_line
37
- l = self.cury
38
- (self.maxy - l).times {self.deleteln()}
39
- self.refresh
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 fill # Fill window with color as set by self.color (or self.bg if not set)
43
- self.setpos(0, 0)
44
- self.fill_from_cur_pos
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 fill_to_cur_pos # Fills the window up to current line
47
- x = self.curx
48
- y = self.cury
49
- self.setpos(0, 0)
50
- self.bg = 0 if self.bg == nil
51
- self.fg = 255 if self.fg == nil
52
- blank = " " * self.maxx
53
- cp = Curses::Window.pair(self.fg, self.bg)
54
- y.times {self.attron(color_pair(cp)) {self << blank}}
55
- self.refresh
56
- self.setpos(y, x)
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
57
  end
58
- def fill_from_cur_pos # Fills the rest of the window from current line
59
- x = self.curx
60
- y = self.cury
61
- self.setpos(y, 0)
62
- self.bg = 0 if self.bg == nil
63
- self.fg = 255 if self.fg == nil
64
- blank = " " * self.maxx
65
- cp = Curses::Window.pair(self.fg, self.bg)
66
- self.maxy.times {self.attron(color_pair(cp)) {self << blank}}
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)
66
+ end
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.setpos(y, x)
79
+ self.xy(0, 0)
69
80
  end
70
- def p(fg = self.fg, bg = self.bg, attr = self.attr, text) # Puts text to window with full set of attributes
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 = Curses::Window.pair(fg, bg)
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.maxx - self.curx)
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 pclr(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
+ 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.clr_from_cur_line
99
+ self.nl(bg)
100
+ self.xy(0, 0)
86
101
  end
87
- def frame(fg = self.fg, bg = self.bg)
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 ? " " : "┘"
88
111
  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) + "┘")
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)
92
126
  end
93
- def format(text) # Format text so that it linebreaks neatly inside window
127
+ def format(text) # FORMAT TEXT SO THAT IT LINEBREAKS NEATLY INSIDE WINDOW
94
128
  return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
95
129
  end
96
130
  alias :puts :p
131
+ alias :puts0 :p0
97
132
  end
98
133
 
99
134
  # vim: set sw=2 sts=2 et fdm=syntax fdn=2 fcs=fold\:\ :
@@ -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 clr # Clears the whole window
57
- self.setpos(0, 0)
58
- self.maxy.times {self.deleteln()}
59
- self.refresh
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 clr_to_cur_line
63
- l = self.cury
64
- self.setpos(0, 0)
65
- l.times {self.deleteln()}
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 clr_from_cur_line
69
- l = self.cury
70
- (self.maxy - l).times {self.deleteln()}
71
- self.refresh
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 fill # Fill window with color as set by self.color (or self.bg if not set)
75
- self.setpos(0, 0)
76
- self.fill_from_cur_pos
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 fill_to_cur_pos # Fills the window up to current line
79
- x = self.curx
80
- y = self.cury
81
- self.setpos(0, 0)
82
- self.bg = 0 if self.bg == nil
83
- self.fg = 255 if self.fg == nil
84
- blank = " " * self.maxx
85
- cp = Curses::Window.pair(self.fg, self.bg)
86
- y.times {self.attron(color_pair(cp)) {self << blank}}
87
- self.refresh
88
- self.setpos(y, x)
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)
89
82
  end
90
- def fill_from_cur_pos # Fills the rest of the window from current line
91
- x = self.curx
92
- y = self.cury
93
- self.setpos(y, 0)
94
- self.bg = 0 if self.bg == nil
95
- self.fg = 255 if self.fg == nil
96
- blank = " " * self.maxx
97
- cp = Curses::Window.pair(self.fg, self.bg)
98
- self.maxy.times {self.attron(color_pair(cp)) {self << blank}}
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)
98
+ end
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.setpos(y, x)
111
+ self.xy(0, 0)
101
112
  end
102
- def p(fg = self.fg, bg = self.bg, attr = self.attr, text) # Puts text to window with full set of attributes
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,25 +118,49 @@ 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.maxx - self.curx)
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 pclr(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
+ 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.clr_from_cur_line
131
+ self.nl(bg)
132
+ self.xy(0, 0)
118
133
  end
119
- def frame(fg = self.fg, bg = self.bg)
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 ? " " : "┘"
120
143
  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) + "┘")
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)
124
158
  end
125
- def format(text) # Format text so that it linebreaks neatly inside window
159
+ def format(text) # FORMAT TEXT SO THAT IT LINEBREAKS NEATLY INSIDE WINDOW
126
160
  return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
127
161
  end
128
162
  alias :puts :p
163
+ alias :puts0 :p0
129
164
  end
130
165
 
131
166
  # GENERAL FUNCTIONS
@@ -181,10 +216,8 @@ def main_getkey # GET KEY FROM USER
181
216
  chr = getchr
182
217
  case chr
183
218
  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
219
+ @w_t.p0(255,27,"Try pressing 'w'")
220
+ @w_t.update = false
188
221
  # Examples of moving up and down in a window
189
222
  # You must set @min_index and @max_index in the main loop of the program
190
223
  when 'UP'
@@ -220,7 +253,8 @@ def main_getkey # GET KEY FROM USER
220
253
  @w_w.p(255,52," NO!! ")
221
254
  end
222
255
  chrw = getchr
223
- @w_w.close
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
224
258
  when 'a'
225
259
  # ...etc
226
260
  when 'r'
@@ -229,10 +263,8 @@ def main_getkey # GET KEY FROM USER
229
263
  exit 0
230
264
  when '@' # Enter "Ruby debug"
231
265
  cmd = w_b_getstr("◆ ", "")
232
- @w_b.clr
233
- @w_b.refresh
234
266
  @w_b.update = true
235
- @w_r.clr
267
+ @w_r.fill
236
268
  info = "Command: #{cmd}\n\n"
237
269
  begin
238
270
  info += eval(cmd).to_s
@@ -247,8 +279,8 @@ def main_getkey # GET KEY FROM USER
247
279
  @w_r.p(eval(cmd))
248
280
  rescue StandardError => e
249
281
  w_b("Error: #{e.inspect}")
282
+ chr = STDIN.getc
250
283
  end
251
- #@w_b.update = false
252
284
  end
253
285
  while STDIN.ready?
254
286
  chr = STDIN.getc
@@ -259,11 +291,12 @@ end
259
291
 
260
292
  # BOTTOM WINDOW FUNCTIONS
261
293
  def w_b(info) # SHOW INFO IN @W_B
262
- @w_b.clr
263
- info = "Choose window: i=IMDB list (+/- to add/remove from My list), g=Genres (+/- to add/remove), m=My list. " if info == nil
264
- info = info[1..(@w_b.maxx - 3)] + "…" if info.length + 3 > @w_b.maxx
265
- info += " " * (@w_b.maxx - info.length) if info.length < @w_b.maxx
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?
266
298
  @w_b.p(info)
299
+ @w_b.nl
267
300
  @w_b.update = false
268
301
  end
269
302
  def w_b_getstr(pretext, text) # A SIMPLE READLINE-LIKE ROUTINE
@@ -273,11 +306,10 @@ def w_b_getstr(pretext, text) # A SIMPLE READLINE-LIKE ROUTINE
273
306
  pos = text.length
274
307
  chr = ""
275
308
  while chr != "ENTER"
276
- @w_b.setpos(0,0)
277
- text = pretext + text
278
- text += " " * (@w_b.maxx - text.length) if text.length < @w_b.maxx
279
- @w_b.p(text)
280
- @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)
281
313
  @w_b.refresh
282
314
  chr = getchr
283
315
  case chr
@@ -306,8 +338,8 @@ def w_b_getstr(pretext, text) # A SIMPLE READLINE-LIKE ROUTINE
306
338
  pos += 1
307
339
  end
308
340
  end
309
- Curses.curs_set(0)
310
- Curses.noecho
341
+ Curses.curs_set(1); Curses.curs_set(0)
342
+ #Curses.noecho
311
343
  return text
312
344
  end
313
345
 
@@ -339,18 +371,24 @@ loop do # OUTER LOOP - (catching refreshes via 'r')
339
371
  # Set foreground and background colors and attributes
340
372
  @w_t.fg, @w_t.bg, @w_t.attr = 255, 23, 0
341
373
  @w_b.fg, @w_b.bg, @w_b.attr = 231, 238, 0
342
- @w_l.fg, @w_l.bg, @w_l.attr = 46, 234, 0
374
+ @w_l.fg, @w_l.bg, @w_l.attr = 24, 233, 0
343
375
  @w_r.fg, @w_r.bg, @w_r.attr = 202, 235, 0
344
- @w_t.fill
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
345
381
  loop do # INNER, CORE LOOP
346
- @w_b.fill; @w_l.fill; @w_r.fill
347
382
  # Example code to write to the panes in various ways
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)
351
- @w_l.p(196,182,Curses::A_BOLD,"Left window")
352
- @w_r.setpos(@w_r.maxy/2, @w_r.maxx/2-7)
353
- @w_r.p("Right window")
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
354
392
 
355
393
  # Top window (info line)
356
394
 
@@ -360,6 +398,9 @@ loop do # OUTER LOOP - (catching refreshes via 'r')
360
398
 
361
399
  # Right window
362
400
 
401
+ # Clear residual cursor
402
+ Curses.curs_set(1); Curses.curs_set(0)
403
+
363
404
  # Get key from user
364
405
  main_getkey
365
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: '2.3'
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-10 00:00:00.000000000 Z
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 2.2: Added the method `frame` and made
39
- the curses-template.rb more informative and sexy'
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: []