Module: Scrollable
- Extended by:
- Logging
- Defined in:
- lib/scrollable.rb
Overview
Objects which include this module are supposed to be multi-line text as they have to respond to :to_s. The new functionality will allow this text to become scrollable in a terminal-window. See the scroll-functions up(), down(), left() and right().
You can have a box around the scrollable “window” by setting the attribute ‘box’ to true and, -as I do not care to be asked for my opinion-, you should.
Constant Summary collapse
- @@box =
may not be needed at all, but when it is.., you want it on class level.
%w~┌ ┐ └ ┘ ─ │~
- @@log =
dto. and how so!
self.init_logger(STDOUT)
- @@def_step_x =
pfffft. As you please.
1
- @@def_step_y =
1
Instance Attribute Summary collapse
-
#box ⇒ Object
writeonly
Sets the attribute box.
-
#clipped_bottom ⇒ Object
readonly
Returns the value of attribute clipped_bottom.
-
#clipped_left ⇒ Object
readonly
Returns the value of attribute clipped_left.
-
#clipped_right ⇒ Object
readonly
Returns the value of attribute clipped_right.
-
#clipped_top ⇒ Object
readonly
Returns the value of attribute clipped_top.
-
#fixed_cols ⇒ Object
Returns the value of attribute fixed_cols.
-
#fixed_rows ⇒ Object
Returns the value of attribute fixed_rows.
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
-
#xoff ⇒ Object
readonly
Returns the value of attribute xoff.
-
#yoff ⇒ Object
readonly
Returns the value of attribute yoff.
Instance Method Summary collapse
-
#down ⇒ Object
scrolls.
- #first_column ⇒ Object
- #first_line ⇒ Object
-
#home ⇒ Object
read the code.
- #last_column ⇒ Object
- #last_line ⇒ Object
-
#left ⇒ Object
scrolls.
-
#right ⇒ Object
dto.
-
#scroll(xoffset, yoffset) ⇒ Object
scrolls.
-
#scroll_x(offset) ⇒ Object
guess.
-
#scroll_y(offset) ⇒ Object
scroll up or down by offset lines.
-
#show ⇒ Object
does it.
-
#step_x=(step) ⇒ Object
set the size of a horizontal scroll step.
-
#step_y=(step) ⇒ Object
set the size of a vertical scroll step.
-
#to_end ⇒ Object
dto.
-
#up ⇒ Object
scrolls.
Methods included from Logging
init_logger, log_level=, log_target=
Methods included from File_Checking
Instance Attribute Details
#box=(value) ⇒ Object
Sets the attribute box
182 183 184 |
# File 'lib/scrollable.rb', line 182 def box=(value) @box = value end |
#clipped_bottom ⇒ Object (readonly)
Returns the value of attribute clipped_bottom.
183 184 185 |
# File 'lib/scrollable.rb', line 183 def clipped_bottom @clipped_bottom end |
#clipped_left ⇒ Object (readonly)
Returns the value of attribute clipped_left.
183 184 185 |
# File 'lib/scrollable.rb', line 183 def clipped_left @clipped_left end |
#clipped_right ⇒ Object (readonly)
Returns the value of attribute clipped_right.
183 184 185 |
# File 'lib/scrollable.rb', line 183 def clipped_right @clipped_right end |
#clipped_top ⇒ Object (readonly)
Returns the value of attribute clipped_top.
183 184 185 |
# File 'lib/scrollable.rb', line 183 def clipped_top @clipped_top end |
#fixed_cols ⇒ Object
Returns the value of attribute fixed_cols.
181 182 183 |
# File 'lib/scrollable.rb', line 181 def fixed_cols @fixed_cols end |
#fixed_rows ⇒ Object
Returns the value of attribute fixed_rows.
181 182 183 |
# File 'lib/scrollable.rb', line 181 def fixed_rows @fixed_rows end |
#height ⇒ Object
Returns the value of attribute height.
183 184 185 |
# File 'lib/scrollable.rb', line 183 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
183 184 185 |
# File 'lib/scrollable.rb', line 183 def width @width end |
#xoff ⇒ Object (readonly)
Returns the value of attribute xoff.
183 184 185 |
# File 'lib/scrollable.rb', line 183 def xoff @xoff end |
#yoff ⇒ Object (readonly)
Returns the value of attribute yoff.
183 184 185 |
# File 'lib/scrollable.rb', line 183 def yoff @yoff end |
Instance Method Details
#down ⇒ Object
scrolls
111 112 113 114 115 |
# File 'lib/scrollable.rb', line 111 def down defaults() if !@have_defaults # increase number of visible lines by step_y scroll_y(@step_y) end |
#first_column ⇒ Object
146 147 148 149 |
# File 'lib/scrollable.rb', line 146 def first_column() defaults() if !@have_defaults @xoff = 0 end |
#first_line ⇒ Object
136 137 138 139 |
# File 'lib/scrollable.rb', line 136 def first_line() defaults() if !@have_defaults @yoff = 0 end |
#home ⇒ Object
read the code
125 126 127 128 |
# File 'lib/scrollable.rb', line 125 def home() first_line first_column end |
#last_column ⇒ Object
151 152 153 154 |
# File 'lib/scrollable.rb', line 151 def last_column() defaults() if !@have_defaults @xoff = num_columns - 1 end |
#last_line ⇒ Object
141 142 143 144 |
# File 'lib/scrollable.rb', line 141 def last_line() defaults() if !@have_defaults @yoff = @lines.length end |
#left ⇒ Object
scrolls
93 94 95 96 |
# File 'lib/scrollable.rb', line 93 def left() defaults() if !@have_defaults scroll_x(@step_x * -1) end |
#right ⇒ Object
dto. To the right. You guessed that.
99 100 101 102 |
# File 'lib/scrollable.rb', line 99 def right() defaults() if !@have_defaults scroll_x(@step_x) end |
#scroll(xoffset, yoffset) ⇒ Object
scrolls
118 119 120 121 122 |
# File 'lib/scrollable.rb', line 118 def scroll(xoffset, yoffset) defaults() if !@have_defaults scroll_y(yoffset) scroll_x(xoffset) end |
#scroll_x(offset) ⇒ Object
guess
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/scrollable.rb', line 66 def scroll_x(offset) defaults(self) if !@have_defaults if(offset != 0) xt = @xoff + offset width_x = num_columns - xt if(width_x > 0) @xoff = xt end end show() end |
#scroll_y(offset) ⇒ Object
scroll up or down by offset lines.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/scrollable.rb', line 79 def scroll_y(offset) defaults() if !@have_defaults # any offset is okay if(offset != 0 ) yt = @yoff + offset height_y = @lines.length + yt if(height_y > 0) @yoff = yt end end show() end |
#show ⇒ Object
does it
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/scrollable.rb', line 54 def show defaults() if !@have_defaults system('clear') new_view = limit_lines if @box box(new_view) else puts new_view end end |
#step_x=(step) ⇒ Object
set the size of a horizontal scroll step
165 166 167 168 169 170 171 |
# File 'lib/scrollable.rb', line 165 def step_x=(step) if step > 0 @step_x = step else raise ScrollException.new('ERROR: scroll-steps must be positive numbers') end end |
#step_y=(step) ⇒ Object
set the size of a vertical scroll step
156 157 158 159 160 161 162 |
# File 'lib/scrollable.rb', line 156 def step_y=(step) if step > 0 @step_y = step else raise ScrollException.new('ERROR: scroll-steps must be positive numbers') end end |
#to_end ⇒ Object
dto.
131 132 133 134 |
# File 'lib/scrollable.rb', line 131 def to_end() last_column last_line end |
#up ⇒ Object
scrolls
105 106 107 108 |
# File 'lib/scrollable.rb', line 105 def up() defaults() if !@have_defaults scroll_y(@step_y * -1 ) end |