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
- LEVEL_ICONS =
{error: " \u2718 ", warning: " \u26A0 ", info: " \u2139 "}.freeze
Class Method Summary collapse
-
.level_styles ⇒ Object
Builds level styles from current theme settings.
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.
41 42 43 |
# File 'lib/tui/flash.rb', line 41 def initialize @entries = [] end |
Class Method Details
.level_styles ⇒ Object
Builds level styles from current theme settings. Called per-render so hot-reloaded theme changes take effect immediately.
33 34 35 36 37 38 39 |
# File 'lib/tui/flash.rb', line 33 def self.level_styles { error: {fg: Settings.theme_flash_error_fg, bg: Settings.theme_flash_error_bg}, warning: {fg: Settings.theme_flash_warning_fg, bg: Settings.theme_flash_warning_bg}, info: {fg: Settings.theme_flash_info_fg, bg: Settings.theme_flash_info_bg} } end |
Instance Method Details
#any? ⇒ Boolean
Removes expired entries and returns true if any remain.
61 62 63 64 |
# File 'lib/tui/flash.rb', line 61 def any? expire! @entries.any? end |
#dismiss! ⇒ Object
Removes all entries immediately (e.g. on keypress).
72 73 74 |
# File 'lib/tui/flash.rb', line 72 def dismiss! @entries.clear end |
#empty? ⇒ Boolean
67 68 69 |
# File 'lib/tui/flash.rb', line 67 def empty? !any? end |
#error(message) ⇒ Object
46 47 48 |
# File 'lib/tui/flash.rb', line 46 def error() push(, :error) end |
#info(message) ⇒ Object
56 57 58 |
# File 'lib/tui/flash.rb', line 56 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.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/tui/flash.rb', line 83 def render(frame, area, tui) expire! return 0 if @entries.empty? height = [@entries.size, area.height / Settings.flash_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
51 52 53 |
# File 'lib/tui/flash.rb', line 51 def warning() push(, :warning) end |