class BBS::Cursor
Where the cursor of a session is, as far as the code drawing on it knows, and the escape sequences that move it from there: the drawing primitives BBS::Field and BBS::Editor share.
Moves are relative, from the position the cursor was last moved to or written up to, so a C64 never gets HOME. On a PETSCII line the cursor goes down with RETURN rather than cursor down: what is drawn works the same through the C64’s screen editor and through a terminal program that handles the control codes itself.
The methods return the bytes to write rather than writing them, so a caller sends a whole screen update at once.
Attributes
The column of the cursor, 1-based (relative to where counting began).
The row of the cursor, 1-based (relative to where counting began).
Public Class Methods
# File lib/bbs/cursor.rb, line 23 def initialize(session, row: 1, col: 1) @session = session @petscii = session.respond_to?(:petscii?) && session.petscii? @row = row @col = col end
Starts counting at row, col on the screen of session.
Public Instance Methods
Source
# File lib/bbs/cursor.rb, line 74 def cells(text) @petscii ? text.each_char.map { |c| Petscii.cell(c) }.join : text end
text as the screen shows it, one cell a character: on a C64 a character with no single PETSCII glyph becomes ? (see BBS::Petscii.cell), so the columns stay where they are counted.
Source
# File lib/bbs/cursor.rb, line 44 def clear @row = 1 @col = 1 @petscii ? "#{Ansi::RESET}#{Ansi::CLEAR_SCREEN}" : "#{Ansi::RESET}#{Ansi::CLEAR}" end
Returns the bytes that reset the colours, clear the screen and home the cursor (on a C64 CLR homes it by itself), and counts from 1, 1.
Source
# File lib/bbs/cursor.rb, line 35 def key key = @session.readkey raise IOError, 'the caller hung up' if key.nil? key end
Reads a key from the session (see BBS::Telnet#readkey). Raises IOError when the caller hangs up.
Source
# File lib/bbs/cursor.rb, line 51 def move(row, col) out = +'' if row > @row && @petscii out << (Ansi::CRLF * (row - @row)) @col = 1 elsif row != @row out << (row > @row ? "#{Ansi::CSI}#{row - @row}B" : "#{Ansi::CSI}#{@row - row}A") end out << (col > @col ? "#{Ansi::CSI}#{col - @col}C" : "#{Ansi::CSI}#{@col - col}D") unless col == @col @row = row @col = col out end
Returns the bytes that move the cursor to row, col.
Source
# File lib/bbs/cursor.rb, line 31 def petscii? = @petscii
True when the session is a PETSCII line (a C64).
Source
# File lib/bbs/cursor.rb, line 67 def wrote(count) @col += count end
Counts count characters written at the cursor: it is that many columns further right.