class BBS::FakeOS::Definition
Immutable-ish description of one simulated OS, built via the define DSL.
Attributes
The boot and ready blocks, the commands (a Hash of lower-case name to a Hash with :name, :help and :block), the canonical command names in registration order, and the on_unknown block.
The boot and ready blocks, the commands (a Hash of lower-case name to a Hash with :name, :help and :block), the canonical command names in registration order, and the on_unknown block.
The boot and ready blocks, the commands (a Hash of lower-case name to a Hash with :name, :help and :block), the canonical command names in registration order, and the on_unknown block.
The boot and ready blocks, the commands (a Hash of lower-case name to a Hash with :name, :help and :block), the canonical command names in registration order, and the on_unknown block.
The boot and ready blocks, the commands (a Hash of lower-case name to a Hash with :name, :help and :block), the canonical command names in registration order, and the on_unknown block.
Public Class Methods
Source
# File lib/bbs/fake_os.rb, line 71 def initialize @name = 'OS' @prompt = '> ' @colors = DEFAULT_COLORS.dup @boot_block = nil @ready_block = nil @commands = {} @order = [] @unknown = nil end
Creates a definition named OS with a '> ' prompt, the DEFAULT_COLORS, and no boot, ready or commands.
Public Instance Methods
Source
# File lib/bbs/fake_os.rb, line 105 def boot(&block) = (@boot_block = block)
Sets the boot sequence, run in the Console before anything else.
Source
# File lib/bbs/fake_os.rb, line 100 def colors(overrides = nil) overrides ? @colors.merge!(overrides) : @colors end
Merges SGR overrides into the colour roles, e.g. colors text: "\e[0;32m". Returns the colour Hash with no argument.
# File lib/bbs/fake_os.rb, line 114 def command(*names, help: nil, &block) primary = names.first.to_s @order << primary unless @order.include?(primary) names.each do |n| @commands[n.to_s.downcase] = { name: primary, help: help, block: block } end end
Registers a command under one or more names (the first is the canonical one shown in help); names match case-insensitively. The block receives (args_string, console). help is an optional description stored with the command.
Source
# File lib/bbs/fake_os.rb, line 84 def name(value = nil) value.nil? ? @name : (@name = value) end
Sets the OS name with an argument (name 'MS-DOS'); returns it without one.
Source
# File lib/bbs/fake_os.rb, line 125 def on_unknown(&block) = (@unknown = block)
Sets the fallback for input that matches no command. The block gets (input, console). Without one, the shell prints βBad command or file nameβ.
Source
# File lib/bbs/fake_os.rb, line 90 def prompt(value = nil, &block) if block then @prompt = block elsif !value.nil? then @prompt = value else @prompt end end
Sets the shell prompt with a String argument, or with a block called with the context before each line; returns it with neither.
Source
# File lib/bbs/fake_os.rb, line 108 def ready(&block) = (@ready_block = block)
Sets the block run in the Console once after boot, before the first prompt.