Class: TUI::Flash
- Inherits:
-
Object
- Object
- TUI::Flash
- Defined in:
- lib/tui/flash.rb
Overview
Ephemeral notification system for the TUI, modeled after Rails flash messages. Notifications render as a colored bar at the top of the chat pane and auto-dismiss after a configurable timeout or on any keypress.
Reusable beyond Bounce Back — useful for connection status changes, background task notifications, and any transient user feedback that doesn’t belong in the chat stream.
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- AUTO_DISMISS_SECONDS =
5.0- MAX_HEIGHT_FRACTION =
Flash area occupies at most 1/3 of the chat pane height.
3- LEVEL_STYLES =
{ error: {fg: "white", bg: "red", icon: " \u2718 "}, warning: {fg: "black", bg: "yellow", icon: " \u26A0 "}, info: {fg: "white", bg: "blue", icon: " \u2139 "} }.freeze
Instance Method Summary collapse
-
#any? ⇒ Boolean
Removes expired entries and returns true if any remain.
-
#dismiss! ⇒ Object
Removes all entries immediately (e.g. on keypress).
- #empty? ⇒ Boolean
- #error(message) ⇒ Object
- #info(message) ⇒ Object
-
#initialize ⇒ Flash
constructor
A new instance of Flash.
-
#render(frame, area, tui) ⇒ Integer
Renders flash entries as colored bars at the top of the given area.
- #warning(message) ⇒ Object
Constructor Details
#initialize ⇒ Flash
Returns a new instance of Flash.
38 39 40 |
# File 'lib/tui/flash.rb', line 38 def initialize @entries = [] end |
Instance Method Details
#any? ⇒ Boolean
Removes expired entries and returns true if any remain.
58 59 60 61 |
# File 'lib/tui/flash.rb', line 58 def any? expire! @entries.any? end |
#dismiss! ⇒ Object
Removes all entries immediately (e.g. on keypress).
69 70 71 |
# File 'lib/tui/flash.rb', line 69 def dismiss! @entries.clear end |
#empty? ⇒ Boolean
64 65 66 |
# File 'lib/tui/flash.rb', line 64 def empty? !any? end |
#error(message) ⇒ Object
43 44 45 |
# File 'lib/tui/flash.rb', line 43 def error() push(, :error) end |
#info(message) ⇒ Object
53 54 55 |
# File 'lib/tui/flash.rb', line 53 def info() push(, :info) end |
#render(frame, area, tui) ⇒ Integer
Renders flash entries as colored bars at the top of the given area. Returns the height consumed so the caller can adjust layout.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/tui/flash.rb', line 80 def render(frame, area, tui) expire! return 0 if @entries.empty? height = [@entries.size, area.height / MAX_HEIGHT_FRACTION].min flash_area, _ = tui.split( area, direction: :vertical, constraints: [ tui.constraint_length(height), tui.constraint_fill(1) ] ) @entries.each_with_index do |entry, index| break if index >= height row_area = row_rect(flash_area, index, tui) render_entry(frame, row_area, entry, tui) end height end |
#warning(message) ⇒ Object
48 49 50 |
# File 'lib/tui/flash.rb', line 48 def warning() push(, :warning) end |