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

Instance Method Summary collapse

Methods included from Logging

init_logger, log_level=, log_target=

Methods included from File_Checking

#file_check, file_check

Instance Attribute Details

#box=(value) ⇒ Object

Sets the attribute box

Parameters:

  • value

    the value to set the attribute box to.



182
183
184
# File 'lib/scrollable.rb', line 182

def box=(value)
  @box = value
end

#clipped_bottomObject (readonly)

Returns the value of attribute clipped_bottom.



183
184
185
# File 'lib/scrollable.rb', line 183

def clipped_bottom
  @clipped_bottom
end

#clipped_leftObject (readonly)

Returns the value of attribute clipped_left.



183
184
185
# File 'lib/scrollable.rb', line 183

def clipped_left
  @clipped_left
end

#clipped_rightObject (readonly)

Returns the value of attribute clipped_right.



183
184
185
# File 'lib/scrollable.rb', line 183

def clipped_right
  @clipped_right
end

#clipped_topObject (readonly)

Returns the value of attribute clipped_top.



183
184
185
# File 'lib/scrollable.rb', line 183

def clipped_top
  @clipped_top
end

#fixed_colsObject

Returns the value of attribute fixed_cols.



181
182
183
# File 'lib/scrollable.rb', line 181

def fixed_cols
  @fixed_cols
end

#fixed_rowsObject

Returns the value of attribute fixed_rows.



181
182
183
# File 'lib/scrollable.rb', line 181

def fixed_rows
  @fixed_rows
end

#heightObject

Returns the value of attribute height.



183
184
185
# File 'lib/scrollable.rb', line 183

def height
  @height
end

#widthObject

Returns the value of attribute width.



183
184
185
# File 'lib/scrollable.rb', line 183

def width
  @width
end

#xoffObject (readonly)

Returns the value of attribute xoff.



183
184
185
# File 'lib/scrollable.rb', line 183

def xoff
  @xoff
end

#yoffObject (readonly)

Returns the value of attribute yoff.



183
184
185
# File 'lib/scrollable.rb', line 183

def yoff
  @yoff
end

Instance Method Details

#downObject

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_columnObject



146
147
148
149
# File 'lib/scrollable.rb', line 146

def first_column()
  defaults() if !@have_defaults
  @xoff = 0
end

#first_lineObject



136
137
138
139
# File 'lib/scrollable.rb', line 136

def first_line()
  defaults() if !@have_defaults
  @yoff = 0
end

#homeObject

read the code



125
126
127
128
# File 'lib/scrollable.rb', line 125

def home() 
  first_line
  first_column
end

#last_columnObject



151
152
153
154
# File 'lib/scrollable.rb', line 151

def last_column()
  defaults() if !@have_defaults
  @xoff = num_columns - 1
end

#last_lineObject



141
142
143
144
# File 'lib/scrollable.rb', line 141

def last_line()
  defaults() if !@have_defaults
  @yoff = @lines.length 
end

#leftObject

scrolls



93
94
95
96
# File 'lib/scrollable.rb', line 93

def left()
  defaults() if !@have_defaults
  scroll_x(@step_x * -1)
end

#rightObject

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

#showObject

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_endObject

dto.



131
132
133
134
# File 'lib/scrollable.rb', line 131

def to_end()
  last_column
  last_line
end

#upObject

scrolls



105
106
107
108
# File 'lib/scrollable.rb', line 105

def up()
  defaults() if !@have_defaults
  scroll_y(@step_y * -1 )
end