class BBS::FakeOS::Console
The live terminal: owns the telnet session and all output primitives, and drives the boot sequence + shell loop. Handlers receive this as io.
Attributes
The context Hash, the BBS::Session, and the Definition being run.
The context Hash, the BBS::Session, and the Definition being run.
The context Hash, the BBS::Session, and the Definition being run.
Public Class Methods
# File lib/bbs/fake_os.rb, line 141 def initialize(session, definition, context) @session = session @definition = definition @ctx = context @colors = definition.colors @running = true end
Creates a console running definition on session with the context Hash context.
Public Instance Methods
Source
# File lib/bbs/fake_os.rb, line 192 def cls = @session.write("#{reset}#{Ansi::CLEAR}")
Resets the colours and clears the screen, cursor to the top left.
Source
# File lib/bbs/fake_os.rb, line 223 def cols = @session.term_cols || Telnet::DEFAULT_COLS
The terminal width in columns; 80 when the terminal did not report it.
Source
# File lib/bbs/fake_os.rb, line 229 def halt = (@running = false)
Stops the shell loop after the current command (used by an exit/quit command).
# File lib/bbs/fake_os.rb, line 212 def memtest(kilobytes, step: 2048, delay: 0.03, label: 'Memory Test : ') counted = 0 while counted < kilobytes counted = [counted + step, kilobytes].min @session.write("#{Ansi::CR}#{color(:text)}#{label}#{counted}K #{reset}") sleep_for(delay) end @session.write("#{color(:text)}#{label}#{kilobytes}K OK#{reset}#{Ansi::CRLF}") end
The classic counting memory test: memtest 16_384 writes โMemory Test : 16384K OKโ, counting up in place by step kilobytes every delay seconds.
Source
# File lib/bbs/fake_os.rb, line 189 def newline(count = 1) = @session.write(Ansi::CRLF * count)
Writes count CRLFs.
Source
# File lib/bbs/fake_os.rb, line 195 def pause(seconds) = sleep_for(seconds)
Sleeps for seconds (nothing for zero or nil).
# File lib/bbs/fake_os.rb, line 171 def print(text = '', delay: 0, style: :text, newline: 1) @session.write("#{color(style)}#{text}#{reset}#{Ansi::CRLF * newline}") sleep_for(delay) end
Writes text in style followed by newline CRLFs, then sleeps delay seconds. Handy for boot messages: print 'POST OK', delay: 0.3.
# File lib/bbs/fake_os.rb, line 164 def puts(text = '', style: :text) @session.write("#{color(style)}#{text}#{reset}#{Ansi::CRLF}") end
Writes text (or a blank line) in the colour role style, followed by CRLF.
Source
# File lib/bbs/fake_os.rb, line 225 def rows = @session.term_rows || Telnet::DEFAULT_ROWS
The terminal height in rows; 24 when the terminal did not report it.
Source
# File lib/bbs/fake_os.rb, line 154 def run instance_eval(&@definition.boot_block) if @definition.boot_block instance_eval(&@definition.ready_block) if @definition.ready_block run_shell end
Runs the boot block, the ready block, then the shell: prints the prompt, reads a line, and runs the matching command or the on_unknown block, until halt is called or the line drops. An error raised by a command is logged and printed; IOError and SystemCallError are re-raised.
# File lib/bbs/fake_os.rb, line 178 def type(text, style: :text, cps: 900, newline: 1) delay = cps.positive? ? 1.0 / cps : 0 @session.write(color(style)) text.to_s.each_char do |ch| @session.write(ch) sleep_for(delay) end @session.write("#{reset}#{Ansi::CRLF * newline}") end
Typewriter effect: writes text one character at a time at cps characters a second, then newline CRLFs.