class BBS::Editor
A full-screen text editor on a telnet line, for a modern terminal and a Commodore 64 alike, for text longer than a BBS::Field holds: the cursor keys move anywhere in the text, typing inserts at the cursor, DEL (backspace) deletes before it, and the text wraps at word boundaries as it is typed. The text and the cursor live in a BBS::TextBuffer, so the editing keys do what they do in a BBS::Field.
The editor owns the screen while it runs: a reversed title bar on the first row, the text below it, and a row of key hints near the bottom. It draws through a BBS::Cursor, which moves only relative to where it left the cursor; it never writes into the last column or the last row, which on a C64 would link or scroll lines.
Keys:
- cursor keys
-
move; up and down keep the column
- HOME, END
-
the start and the end of the screen row
- PgUp, PgDn
-
a screenful up or down
- RETURN
-
a new line; saves in a single-line editor
- DEL, backspace
-
deletes the character before the cursor
- Delete
-
deletes the character under the cursor
- RUN/STOP, ←, Esc
-
asks on the bottom row: S saves, Q quits without saving, any other key goes back to the text
- F1, Ctrl-S
-
saves at once, where the terminal program lets the key through (the Ultimate Term keeps F1 for itself)
text = BBS::Editor.new(session, text: post.body, title: 'BODY').run post.body = text if text
Constants
- MENU_KEYS
-
The keys that ask whether to save or quit.
- PAGE_MOVES
-
The keys that move a screenful up or down, keeping the column.
- ROW_MOVES
-
The keys that move a row up or down, keeping the column.
- SAVE_KEYS
-
The keys that save the text at once.
Public Class Methods
# File lib/bbs/editor.rb, line 56 def initialize(session, text: '', title: '', single_line: false, max: nil, cols: nil, rows: nil) @session = session @screen = Cursor.new(session) @buffer = TextBuffer.new(text, max: max, single_line: single_line) @single = single_line @cols = cols || session.term_cols @rows = rows || session.term_rows @width = @cols - 2 @height = @rows - 3 @goal = nil @top = 0 @chrome = Chrome.new(@screen, title: title.to_s, single_line: single_line, max: max, cols: @cols, rows: @rows) end
Creates an editor for session.
- text
-
the text to start from; lines end with LF
- title
-
the text of the title bar
- single_line
-
one paragraph, wrapped on the screen: RETURN saves and line ends in
textbecome spaces - max
-
the most characters the text may hold (line ends count as one), or
nilforTextBuffer::MAX_LENGTH; the title bar counts them when it is given - cols
-
the screen width; default the session’s
- rows
-
the screen height; default the session’s
Public Instance Methods
Source
# File lib/bbs/editor.rb, line 75 def run first_paint loop do key = @screen.key done = finish(key) return done == :quit ? nil : @buffer.text if done handle(key) paint end end
Runs the editor until the caller saves or quits, then leaves the screen as it is; the caller draws the next one.
Returns the text, lines joined by LF, when saved, and nil when the caller quit. Raises IOError when the caller hangs up.