class BBS::Windows::Info
A centered window for messages, splash screens, info displays.
BBS::Windows::Info.open(app, title: ' Welcome ', width: 70, height: 17, body: [ { text: banner_line, style: :accent }, "plain label with optional \e[1;33mraw ANSI\e[0m", :spacer, :rule, { kv: [['Online users', '5'], ['Ruby', RUBY_VERSION]] }, ], buttons: [{ label: '&Continue', primary: true }] )
When scroll: true, body items are flattened into a single ScrollView filling the inner area. Use this for long, paginated content lists.
Body item types:
- String
-
label with the
:window_textstyle :spacer,'',nil-
blank row
:rule-
horizontal line
{ text:, style:, align: }-
styled label
{ kv: [[k, v], ...], label_width: }-
key/value rows
{ widget:, height: }-
arbitrary widget (non-scroll only)
BBS::Widget-
as-is, its own height or 1 row (non-scroll only)
Default buttons: a single centered [ Close ] if buttons: is nil.
Constants
- DEFAULT_BUTTON
-
The button row used when no
buttonsare given: one Close button. - DEFAULT_PADDING
-
The blank cells around the body: columns on each side, rows above, and rows below the button row.
- OPTIONS
-
The options of
::newand their defaults. - SCROLL_ROWS
-
The body rows of a scrolling window without a height of its own.
Attributes
The BBS::Widgets::ScrollView holding the body in scroll mode; nil otherwise.
Public Class Methods
# File lib/bbs/windows/info.rb, line 88 def initialize(app:, title:, **options) unknown = options.keys - OPTIONS.keys raise ArgumentError, "unknown info options: #{unknown.inspect}" unless unknown.empty? @options = OPTIONS.merge(options) super(title: title, modal: false, maximizable: @options[:maximizable]) self.theme = app.theme @app = app @buttons = @options[:buttons].nil? ? DEFAULT_BUTTON.dup : Array(@options[:buttons]) @padding = DEFAULT_PADDING.merge(@options[:padding] || {}) build end
Creates the window and its widgets, centred on app‘s screen. It is not opened; see attach.
- app
-
the
BBS::Application - title
-
the window title
The options (OPTIONS):
- body
-
an Array of body items (see above)
- buttons
-
an Array of
BBS::Windows::ButtonBardescriptors;nilgivesDEFAULT_BUTTON,[]no buttons - width
-
the window width (default 60)
- height
-
the window height; by default it fits the body (
SCROLL_ROWSbody rows in scroll mode) - scroll
-
puts the body in a scrolling view
- padding
-
a Hash overriding
DEFAULT_PADDINGentries - maximizable
-
gives the window the zoom gadget
Raises ArgumentError for an unknown option, and when a widget body item is used in scroll mode.
BBS::Window::new
Source
# File lib/bbs/windows/info.rb, line 60 def self.open(app, **) new(app: app, **).tap(&:attach) end
Public Instance Methods
Source
# File lib/bbs/windows/info.rb, line 105 def attach @app.open_window(self) reset_focus focus_manager.focus(@primary_button) if @primary_button self end
Opens the window on the application and focuses the primary button, when there is one.
Returns self.
Source
# File lib/bbs/windows/info.rb, line 118 def normal_rect w = [@options[:width], @app.cols - 4].min h = [@options[:height] || (body_rows + chrome_rows), @app.rows - 4].min [((@app.cols - w) / 2) + 1, ((@app.rows - h) / 2) + 1, w, h] end
Returns the un-maximized bounds as [x, y, width, height]: the requested size (or the fitted height), shrunk to leave a two-cell margin, centred on the screen.
Source
# File lib/bbs/windows/info.rb, line 126 def place(x, y, width, height) layout(x, y, width, height) rows = [height - chrome_rows, 1].max @scroll_view.layout(*inside(x, y, width), rows) @scroll_view.scroll = @scroll_view.scroll.clamp(0, [@scroll_view.lines.size - rows, 0].max) ButtonBar.place(self, @bar[:widgets], @buttons) end
The scroll body fills the new size; its lines were wrapped by the caller, so a wider window shows them as they are.
Source
# File lib/bbs/windows/info.rb, line 113 def resizable? = @options[:scroll]
Only the scrolling body can be laid out at another size.