class BBS::Theme
A Theme maps the style ROLES (such as :window_border or :button_focused) to ANSI SGR sequences. Widgets fetch styles through Widget#style.
The presets are data, a Hash each in PRESETS:
:synchronet-
white and yellow on blue windows over a black screen, after Synchronet
:nortoncommander-
cyan and blue panels, after Norton Commander
:dosnavigator-
black on light grey with cyan bars, after DOS Navigator
:neumanntronics-
teal and amber on black in 256 colours
:mono-
no colour, only bold, dim, underline and reverse, for terminals without colour
::fetch builds one; derive a variant with merge:
BBS::Theme.fetch(:synchronet).merge(window_bg: "\e[41m")
Constants
- PRESETS
-
The presets: each a Hash of every style role to its SGR sequence. The first one’s roles are
Theme::ROLES, and every preset defines all of them. - ROLES
-
The style roles every preset defines and a theme may set.
Attributes
The style Hash (role Symbol => SGR String) and the theme’s name Symbol.
The style Hash (role Symbol => SGR String) and the theme’s name Symbol.
Public Class Methods
Source
# File lib/bbs/theme.rb, line 36 def self.fetch(name) return name if name.is_a?(Theme) styles = PRESETS.fetch(name.to_s.to_sym) { raise ArgumentError, "unknown theme: #{name.inspect}" } new(name.to_sym, styles) end
Source
# File lib/bbs/theme.rb, line 55 def self.mono = fetch(:mono)
The :mono preset (see ::fetch).
Source
# File lib/bbs/theme.rb, line 53 def self.neumanntronics = fetch(:neumanntronics)
The :neumanntronics preset (see ::fetch).
Source
# File lib/bbs/theme.rb, line 60 def initialize(name, styles) unknown = styles.keys - ROLES raise ArgumentError, "unknown theme roles: #{unknown.inspect}" unless unknown.empty? @name = name @styles = styles.frozen? ? styles : styles.dup.freeze freeze end
Source
# File lib/bbs/theme.rb, line 49 def self.nortoncommander = fetch(:nortoncommander)
The :nortoncommander preset (see ::fetch).
Source
# File lib/bbs/theme.rb, line 47 def self.synchronet = fetch(:synchronet)
The :synchronet preset (see ::fetch).
Public Instance Methods
Source
# File lib/bbs/theme.rb, line 71 def [](key) = @styles[key]
Returns the SGR String for the role key, or nil when the theme does not define it.
Source
# File lib/bbs/theme.rb, line 79 def merge(overrides) = Theme.new(@name, @styles.merge(overrides))