Class: AnsiSys::Cursor
- Inherits:
-
Object
- Object
- AnsiSys::Cursor
- Defined in:
- lib/ansisys.rb
Constant Summary collapse
- CODE_LETTERS =
Escape sequence codes processed in this Class
%w(A B C D E F G H f)
Instance Attribute Summary collapse
-
#cur_col ⇒ Object
readonly
current column number (1-).
-
#cur_row ⇒ Object
readonly
current row number (1-).
-
#max_col ⇒ Object
maximum column number.
-
#max_row ⇒ Object
maximum row number.
Instance Method Summary collapse
-
#advance!(width = 1) ⇒ Object
changes current location for a character with width to be echoed.
-
#apply_code!(letter, *pars) ⇒ Object
applies self an escape sequence code that ends with letter as String and with some pars as Integers.
-
#fit!(width = 1) ⇒ Object
check if a character with width fits within the maximum columns, feed a line if not.
-
#initialize(cur_col = 1, cur_row = 1, max_col = 80, max_row = 25) ⇒ Cursor
constructor
A new instance of Cursor.
-
#line_feed! ⇒ Object
feed a line.
Constructor Details
#initialize(cur_col = 1, cur_row = 1, max_col = 80, max_row = 25) ⇒ Cursor
Returns a new instance of Cursor.
159 160 161 162 163 164 |
# File 'lib/ansisys.rb', line 159 def initialize(cur_col = 1, cur_row = 1, max_col = 80, max_row = 25) @cur_col = cur_col @cur_row = cur_row @max_col = max_col @max_row = max_row end |
Instance Attribute Details
#cur_col ⇒ Object (readonly)
current column number (1-)
154 155 156 |
# File 'lib/ansisys.rb', line 154 def cur_col @cur_col end |
#cur_row ⇒ Object (readonly)
current row number (1-)
155 156 157 |
# File 'lib/ansisys.rb', line 155 def cur_row @cur_row end |
#max_col ⇒ Object
maximum column number
156 157 158 |
# File 'lib/ansisys.rb', line 156 def max_col @max_col end |
#max_row ⇒ Object
maximum row number
157 158 159 |
# File 'lib/ansisys.rb', line 157 def max_row @max_row end |
Instance Method Details
#advance!(width = 1) ⇒ Object
changes current location for a character with width to be echoed
211 212 213 214 215 216 217 218 219 |
# File 'lib/ansisys.rb', line 211 def advance!(width = 1) r = nil @cur_col += width if @cur_col > @max_col line_feed! r = "\n" end return r end |
#apply_code!(letter, *pars) ⇒ Object
applies self an escape sequence code that ends with letter as String and with some pars as Integers
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/ansisys.rb', line 168 def apply_code!(letter, *pars) case letter when 'A' @cur_row -= pars[0] ? pars[0] : 1 @cur_row = @max_row if @max_row and @cur_row > @max_row when 'B' @cur_row += pars[0] ? pars[0] : 1 @cur_row = @max_row if @max_row and @cur_row > @max_row when 'C' @cur_col += pars[0] ? pars[0] : 1 when 'D' @cur_col -= pars[0] ? pars[0] : 1 when 'E' @cur_row += pars[0] ? pars[0] : 1 @cur_col = 1 @max_row = @cur_row if @max_row and @cur_row > @max_row when 'F' @cur_row -= pars[0] ? pars[0] : 1 @cur_col = 1 @max_row = @cur_row if @max_row and @cur_row > @max_row when 'G' @cur_col = pars[0] ? pars[0] : 1 when 'H' @cur_row = pars[0] ? pars[0] : 1 @cur_col = pars[1] ? pars[1] : 1 @max_row = @cur_row if @max_row and @cur_row > @max_row when 'f' @cur_row = pars[0] ? pars[0] : 1 @cur_col = pars[1] ? pars[1] : 1 @max_row = @cur_row if @max_row and @cur_row > @max_row end if @cur_row < 1 @cur_row = 1 end if @cur_col < 1 @cur_col = 1 elsif @cur_col > @max_col @cur_col = @max_col end return self end |
#fit!(width = 1) ⇒ Object
check if a character with width fits within the maximum columns, feed a line if not
223 224 225 226 227 228 229 230 |
# File 'lib/ansisys.rb', line 223 def fit!(width = 1) r = nil if @cur_col + width > @max_col + 1 line_feed! r = "\n" end return r end |
#line_feed! ⇒ Object
feed a line
233 234 235 236 237 |
# File 'lib/ansisys.rb', line 233 def line_feed! @cur_col = 1 @cur_row += 1 @max_row = @cur_row if @max_row and @cur_row > @max_row end |