class BBS::Statusbar
A status bar at the bottom of the screen. Render a list of hotkey hints like “F1=Help F2=Save Esc=Cancel”. Optionally a right-aligned status text. While a message is set, the bar shows it in place of the hints: the Application sets the hint of the highlighted menu entry there.
Constants
- ALT_LABEL
-
An Alt key label,
Alt-X; the group is the letter. - ESC_LABEL
-
The Escape key label.
- FKEY_LABEL
-
A function key label,
F1…F12; the group is the number. - Hint
-
One hint: the key as shown (
F1,Alt-x,Esc,Tabor a literal key), its label, the block run when it is activated, and whether it is hidden. - TAB_LABEL
-
The Tab key label.
Attributes
The Array of Hint objects, and the text shown at the right end (or nil).
A line shown in place of the hints while it is set (nil shows the hints).
The Array of Hint objects, and the text shown at the right end (or nil).
Public Class Methods
# File lib/bbs/statusbar.rb, line 35 def initialize(hints: [], right_text: nil, **kw) super(**kw) @hints = hints @right_text = right_text @message = nil end
Creates a status bar with hints (an Array of Hint) and an optional right_text. Other keywords go to Widget.new.
Public Instance Methods
# File lib/bbs/statusbar.rb, line 45 def add_hint(key, label, hidden: false, &on_activate) @hints << Hint.new(key: key, label: label, on_activate: on_activate, hidden: hidden) end
Adds a hint for key with label; the block runs when the key is pressed or the hint is clicked. A hidden hint is a key binding only: it works, but takes no room.
Source
# File lib/bbs/statusbar.rb, line 69 def handle_event(event) hint = event.key? ? match_key(event.key) : clicked(event) hint && (hint.on_activate&.call || :handled) end
Runs the hint whose key matches a key event, or the shown hint under a left click on the bar.
Returns the hint block’s result, or :handled when it returns nil; nil when no hint matches.
Source
# File lib/bbs/statusbar.rb, line 55 def render(frame) frame.move(bounds.x, bounds.y) frame.write(' ' * bounds.width, sgr: style(:statusbar)) return render_message(frame) if @message placed.each { |hint, x| render_hint(frame, hint, x) } render_right_text(frame) end
Draws the bar across its bounds in frame: the message across the whole bar, or else the shown hints from the left, as many as fit, and the right text when there is room for it.
Source
# File lib/bbs/statusbar.rb, line 50 def shown = @hints.reject(&:hidden)
Returns the hints that are not hidden.