class BBS::Petscii::Encoder
Turns what a BBS writes into PETSCII. It keeps the cursor’s column, so a line of exactly 40 characters, which the C64 wraps by itself, is not followed by an empty one, and it keeps the state of an escape sequence cut in two by separate writes.
Constants
- CONTROL_ACTIONS
-
What a control character does, by code: the method that handles it.
- PLAIN_PEN
-
The pen after a reset: no bold, no dim, the default colour.
Public Class Methods
Source
# File lib/bbs/petscii/encoder.rb, line 20 def initialize @col = 0 @wrapped = false @lone_cr = false @rvs = false @pen = PLAIN_PEN @color = nil @esc = nil end
Creates an encoder at column 0 with no colour, reverse video or escape sequence pending.
Public Instance Methods
Source
# File lib/bbs/petscii/encoder.rb, line 37 def encode(data) text = data.to_s.dup.force_encoding(Encoding::UTF_8) text = text.scrub('?') unless text.valid_encoding? out = +''.b text.each_char { |ch| feed(ch, out) } out end
Returns the PETSCII bytes (a binary String) for data, UTF-8 text with ANSI escape sequences. Letters swap case, box drawing and other symbols become the nearest PETSCII glyph (GLYPHS, accents dropped, ? when there is none), SGR colours and reverse video become colour and RVS codes, cursor moves become cursor control codes, and \e[2J clears the screen. Other sequences are dropped. The encoder’s column and colour state carry over to the next call.