Class: Curses::Window
- Inherits:
-
Object
- Object
- Curses::Window
- Defined in:
- lib/curses-extension.rb,
lib/curses-template.rb
Overview
CLASS EXTENSION
Instance Attribute Summary collapse
-
#attr ⇒ Object
General extensions (see github.com/isene/Ruby-Curses-Class-Extension) This is a class extension to Ruby Curses - a class in dire need of such.
-
#bg ⇒ Object
General extensions (see github.com/isene/Ruby-Curses-Class-Extension) This is a class extension to Ruby Curses - a class in dire need of such.
-
#fg ⇒ Object
General extensions (see github.com/isene/Ruby-Curses-Class-Extension) This is a class extension to Ruby Curses - a class in dire need of such.
-
#framed ⇒ Object
General extensions (see github.com/isene/Ruby-Curses-Class-Extension) This is a class extension to Ruby Curses - a class in dire need of such.
-
#index ⇒ Object
General extensions (see github.com/isene/Ruby-Curses-Class-Extension) This is a class extension to Ruby Curses - a class in dire need of such.
-
#update ⇒ Object
General extensions (see github.com/isene/Ruby-Curses-Class-Extension) This is a class extension to Ruby Curses - a class in dire need of such.
Class Method Summary collapse
-
.pair(fg, bg) ⇒ Object
INTERNAL FUNCTION.
Instance Method Summary collapse
-
#fill(bg = self.bg, l1 = 0, l2 = self.my?) ⇒ Object
FILL WINDOW WITH BG COLOR FROM LINES L1 TO L2.
-
#format(text) ⇒ Object
FORMAT TEXT SO THAT IT LINEBREAKS NEATLY INSIDE WINDOW.
-
#frame(fg = self.fg, bg = self.bg) ⇒ Object
TOGGLE FRAMING OF THE WINDOW.
-
#mx? ⇒ Boolean
GET THE MAXIMUM X (COLUMN).
-
#my? ⇒ Boolean
GET THE MAXIMUM Y (ROW).
-
#nl(bg = self.bg) ⇒ Object
ADD NEWLINE.
-
#p(fg = self.fg, bg = self.bg, attr = self.attr, text) ⇒ Object
(also: #puts)
PUTS TEXT TO WINDOW WITH FULL SET OF ATTRIBUTES.
-
#p0(fg = self.fg, bg = self.bg, attr = self.attr, text) ⇒ Object
(also: #puts0)
PUTS TEXT AT 0,0 AND CLEARS THE REST OF THE LINE.
-
#x(x) ⇒ Object
SET/GOTO X (COLUMN).
-
#x? ⇒ Boolean
GET THE CURRENT X (COLUMN).
-
#xy(x, y) ⇒ Object
SET/GOTO X & Y (COLUMN & ROW).
-
#y(y) ⇒ Object
SET/GOTO Y (ROW).
-
#y? ⇒ Boolean
GET THE CURRENT Y (ROW).
Instance Attribute Details
#attr ⇒ Object
General extensions (see github.com/isene/Ruby-Curses-Class-Extension) This is a class extension to Ruby Curses - a class in dire need of such. self.pair keeps a registry of colors as they are encountered - defined with: init_pair(index, foreground, background) self.fg is set for the foreground color self.bg is set for the background color self.attr is set for text attributes like Curses::A_BOLD self.update can be used to indicate if a window should be updated (true/false) self.index can be used to keep track of the current list item in a window
11 12 13 |
# File 'lib/curses-extension.rb', line 11 def attr @attr end |
#bg ⇒ Object
General extensions (see github.com/isene/Ruby-Curses-Class-Extension) This is a class extension to Ruby Curses - a class in dire need of such. self.pair keeps a registry of colors as they are encountered - defined with: init_pair(index, foreground, background) self.fg is set for the foreground color self.bg is set for the background color self.attr is set for text attributes like Curses::A_BOLD self.update can be used to indicate if a window should be updated (true/false) self.index can be used to keep track of the current list item in a window
11 12 13 |
# File 'lib/curses-extension.rb', line 11 def bg @bg end |
#fg ⇒ Object
General extensions (see github.com/isene/Ruby-Curses-Class-Extension) This is a class extension to Ruby Curses - a class in dire need of such. self.pair keeps a registry of colors as they are encountered - defined with: init_pair(index, foreground, background) self.fg is set for the foreground color self.bg is set for the background color self.attr is set for text attributes like Curses::A_BOLD self.update can be used to indicate if a window should be updated (true/false) self.index can be used to keep track of the current list item in a window
11 12 13 |
# File 'lib/curses-extension.rb', line 11 def fg @fg end |
#framed ⇒ Object
General extensions (see github.com/isene/Ruby-Curses-Class-Extension) This is a class extension to Ruby Curses - a class in dire need of such. self.pair keeps a registry of colors as they are encountered - defined with: init_pair(index, foreground, background) self.fg is set for the foreground color self.bg is set for the background color self.attr is set for text attributes like Curses::A_BOLD self.update can be used to indicate if a window should be updated (true/false) self.index can be used to keep track of the current list item in a window
11 12 13 |
# File 'lib/curses-extension.rb', line 11 def framed @framed end |
#index ⇒ Object
General extensions (see github.com/isene/Ruby-Curses-Class-Extension) This is a class extension to Ruby Curses - a class in dire need of such. self.pair keeps a registry of colors as they are encountered - defined with: init_pair(index, foreground, background) self.fg is set for the foreground color self.bg is set for the background color self.attr is set for text attributes like Curses::A_BOLD self.update can be used to indicate if a window should be updated (true/false) self.index can be used to keep track of the current list item in a window
11 12 13 |
# File 'lib/curses-extension.rb', line 11 def index @index end |
#update ⇒ Object
General extensions (see github.com/isene/Ruby-Curses-Class-Extension) This is a class extension to Ruby Curses - a class in dire need of such. self.pair keeps a registry of colors as they are encountered - defined with: init_pair(index, foreground, background) self.fg is set for the foreground color self.bg is set for the background color self.attr is set for text attributes like Curses::A_BOLD self.update can be used to indicate if a window should be updated (true/false) self.index can be used to keep track of the current list item in a window
11 12 13 |
# File 'lib/curses-extension.rb', line 11 def update @update end |
Class Method Details
.pair(fg, bg) ⇒ Object
INTERNAL FUNCTION
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/curses-extension.rb', line 12 def self.pair(fg, bg) # INTERNAL FUNCTION @p = [[]] if @p == nil fg = fg.to_i; bg = bg.to_i if @p.include?([fg,bg]) @p.index([fg,bg]) else @p.push([fg,bg]) cp = @p.index([fg,bg]) init_pair(cp, fg, bg) @p.index([fg,bg]) end end |
Instance Method Details
#fill(bg = self.bg, l1 = 0, l2 = self.my?) ⇒ Object
FILL WINDOW WITH BG COLOR FROM LINES L1 TO L2
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/curses-extension.rb', line 67 def fill(bg = self.bg, l1 = 0, l2 = self.my?) # FILL WINDOW WITH BG COLOR FROM LINES L1 TO L2 self.xy(0, l1) bg = 0 if self.bg == nil blank = " " * self.mx? cp = Curses::Window.pair(0, bg) lines = l2 - l1 lines.times do y = self.y? self.attron(color_pair(cp)) {self << blank} self.xy(0,y+1) end self.refresh self.xy(0, 0) end |
#format(text) ⇒ Object
FORMAT TEXT SO THAT IT LINEBREAKS NEATLY INSIDE WINDOW
127 128 129 |
# File 'lib/curses-extension.rb', line 127 def format(text) # FORMAT TEXT SO THAT IT LINEBREAKS NEATLY INSIDE WINDOW return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n") end |
#frame(fg = self.fg, bg = self.bg) ⇒ Object
TOGGLE FRAMING OF THE WINDOW
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/curses-extension.rb', line 102 def frame(fg = self.fg, bg = self.bg) # TOGGLE FRAMING OF THE WINDOW fr = self.framed tl = self.framed ? " " : "┌" tc = self.framed ? " " : "─" tr = self.framed ? " " : "┐" lr = self.framed ? " " : "│" bl = self.framed ? " " : "└" bc = self.framed ? " " : "─" br = self.framed ? " " : "┘" self.setpos(0,0) self.p(tl + tc*(self.maxx-2) + tr) (self.maxy-2).times do y = self.cury mx = self.maxx self.setpos(y,0); self.p(lr) self.setpos(y,maxx-1); self.p(lr) end self.p(bl + bc*(self.maxx-2) + br) if self.framed == nil self.framed = true else self.framed = !self.framed end self.xy(0,0) end |
#mx? ⇒ Boolean
GET THE MAXIMUM X (COLUMN)
34 35 36 37 38 |
# File 'lib/curses-extension.rb', line 34 def mx? # GET THE MAXIMUM X (COLUMN) mx = self.maxx mx -= 2 if self.framed mx end |
#my? ⇒ Boolean
GET THE MAXIMUM Y (ROW)
39 40 41 42 43 |
# File 'lib/curses-extension.rb', line 39 def my? # GET THE MAXIMUM Y (ROW) my = self.maxy my -= 2 if self.framed my end |
#nl(bg = self.bg) ⇒ Object
ADD NEWLINE
89 90 91 92 93 94 95 |
# File 'lib/curses-extension.rb', line 89 def nl(bg = self.bg) # ADD NEWLINE y = self.y? bg = 232 if bg == nil f = " " * (self.mx? - self.x?) self.p(self.fg, bg, self.attr, f) self.xy(0,y+1) end |
#p(fg = self.fg, bg = self.bg, attr = self.attr, text) ⇒ Object Also known as: puts
PUTS TEXT TO WINDOW WITH FULL SET OF ATTRIBUTES
81 82 83 84 85 86 87 88 |
# File 'lib/curses-extension.rb', line 81 def p(fg = self.fg, bg = self.bg, attr = self.attr, text) # PUTS TEXT TO WINDOW WITH FULL SET OF ATTRIBUTES fg = 255 if fg == nil bg = 0 if bg == nil attr = 0 if attr == nil cp = Curses::Window.pair(fg, bg) self.attron(color_pair(cp) | attr) { self << text } self.refresh end |
#p0(fg = self.fg, bg = self.bg, attr = self.attr, text) ⇒ Object Also known as: puts0
PUTS TEXT AT 0,0 AND CLEARS THE REST OF THE LINE
96 97 98 99 100 101 |
# File 'lib/curses-extension.rb', line 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 self.xy(0, 0) self.p(fg, bg, attr, text) self.nl(bg) self.xy(0, 0) end |
#x(x) ⇒ Object
SET/GOTO X (COLUMN)
44 45 46 47 48 49 50 |
# File 'lib/curses-extension.rb', line 44 def x(x) # SET/GOTO X (COLUMN) x += 1 if self.framed mx = self.mx? x = mx if x > mx y = self.cury self.setpos(y,x) end |
#x? ⇒ Boolean
GET THE CURRENT X (COLUMN)
24 25 26 27 28 |
# File 'lib/curses-extension.rb', line 24 def x? # GET THE CURRENT X (COLUMN) x = self.curx x -= 1 if self.framed x end |
#xy(x, y) ⇒ Object
SET/GOTO X & Y (COLUMN & ROW)
58 59 60 61 62 63 64 65 66 |
# File 'lib/curses-extension.rb', line 58 def xy(x,y) # SET/GOTO X & Y (COLUMN & ROW) x += 1 if self.framed y += 1 if self.framed mx = self.mx? x = mx if x > mx? my = self.my? y = my if y > my? self.setpos(y,x) end |
#y(y) ⇒ Object
SET/GOTO Y (ROW)
51 52 53 54 55 56 57 |
# File 'lib/curses-extension.rb', line 51 def y(y) # SET/GOTO Y (ROW) y += 1 if self.framed my = self.my? y = my if y > my x = self.curx self.setpos(y,x) end |
#y? ⇒ Boolean
GET THE CURRENT Y (ROW)
29 30 31 32 33 |
# File 'lib/curses-extension.rb', line 29 def y? # GET THE CURRENT Y (ROW) y = self.cury y -= 1 if self.framed y end |