Module: Scrollable

Includes:
BasicLogging
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~┌ ┐ └ ┘ ─ │~
@@def_step_x =

pfffft. As you please.

1
@@def_step_y =
1

Constants included from BasicLogging

BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN

Instance Attribute Summary collapse

Attributes included from BasicLogging

#log_level, #target

Instance Method Summary collapse

Methods included from BasicLogging

is_muted?, #log, mute, #set_level, set_level, set_target, #set_target

Instance Attribute Details

#box=(value) ⇒ Object

Sets the attribute box

Parameters:

  • value

    the value to set the attribute box to.



174
175
176
# File 'lib/scrollable.rb', line 174

def box=(value)
  @box = value
end

#clipped_bottomObject (readonly)

Returns the value of attribute clipped_bottom.



175
176
177
# File 'lib/scrollable.rb', line 175

def clipped_bottom
  @clipped_bottom
end

#clipped_leftObject (readonly)

Returns the value of attribute clipped_left.



175
176
177
# File 'lib/scrollable.rb', line 175

def clipped_left
  @clipped_left
end

#clipped_rightObject (readonly)

Returns the value of attribute clipped_right.



175
176
177
# File 'lib/scrollable.rb', line 175

def clipped_right
  @clipped_right
end

#clipped_topObject (readonly)

Returns the value of attribute clipped_top.



175
176
177
# File 'lib/scrollable.rb', line 175

def clipped_top
  @clipped_top
end

#fixed_colsObject

Returns the value of attribute fixed_cols.



173
174
175
# File 'lib/scrollable.rb', line 173

def fixed_cols
  @fixed_cols
end

#fixed_rowsObject

Returns the value of attribute fixed_rows.



173
174
175
# File 'lib/scrollable.rb', line 173

def fixed_rows
  @fixed_rows
end

#heightObject

Returns the value of attribute height.



175
176
177
# File 'lib/scrollable.rb', line 175

def height
  @height
end

#widthObject

Returns the value of attribute width.



175
176
177
# File 'lib/scrollable.rb', line 175

def width
  @width
end

#xoffObject (readonly)

Returns the value of attribute xoff.



175
176
177
# File 'lib/scrollable.rb', line 175

def xoff
  @xoff
end

#yoffObject (readonly)

Returns the value of attribute yoff.



175
176
177
# File 'lib/scrollable.rb', line 175

def yoff
  @yoff
end

Instance Method Details

#downObject

scrolls



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

def down
  defaults() if !@have_defaults
  # increase number of visible lines by step_y
  scroll_y(@step_y)
end

#first_columnObject



138
139
140
141
# File 'lib/scrollable.rb', line 138

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

#first_lineObject



128
129
130
131
# File 'lib/scrollable.rb', line 128

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

#homeObject

read the code



117
118
119
120
# File 'lib/scrollable.rb', line 117

def home() 
  first_line
  first_column
end

#last_columnObject



143
144
145
146
# File 'lib/scrollable.rb', line 143

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

#last_lineObject



133
134
135
136
# File 'lib/scrollable.rb', line 133

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

#leftObject

scrolls



85
86
87
88
# File 'lib/scrollable.rb', line 85

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

#rightObject

dto. To the right. You guessed that.



91
92
93
94
# File 'lib/scrollable.rb', line 91

def right()
  defaults() if !@have_defaults
  scroll_x(@step_x)
end

#scroll(xoffset, yoffset) ⇒ Object

scrolls



110
111
112
113
114
# File 'lib/scrollable.rb', line 110

def scroll(xoffset, yoffset)
  defaults() if !@have_defaults
  scroll_y(yoffset)
  scroll_x(xoffset)
end

#scroll_x(offset) ⇒ Object

guess



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/scrollable.rb', line 58

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.



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/scrollable.rb', line 71

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



46
47
48
49
50
51
52
53
54
55
# File 'lib/scrollable.rb', line 46

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



157
158
159
160
161
162
163
# File 'lib/scrollable.rb', line 157

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



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

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.



123
124
125
126
# File 'lib/scrollable.rb', line 123

def to_end()
  last_column
  last_line
end

#upObject

scrolls



97
98
99
100
# File 'lib/scrollable.rb', line 97

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