Module: Clacky::RichUI::Components::BaseComponent
- Included in:
- ApprovalDialog, Clacky::RichUI::ConfigMenuDialog, FormDialog, RichContextPanel, RichTasksPanel, RichWorkPanel
- Defined in:
- lib/clacky/rich_ui/components/base_component.rb
Overview
BaseComponent provides shared rendering primitives for RichUI components. Used by sidebar panels and dialogs to eliminate duplicated ANSI-color helpers.
Instance Method Summary collapse
-
#colored(text, color) ⇒ Object
Render colored text with a named color.
-
#muted(text) ⇒ Object
Render muted (dim) text commonly used for secondary info.
-
#status_marker(status) ⇒ Object
Status marker symbol for todo / activity items.
-
#theme ⇒ Object
Theme accessor for future theme switching.
-
#truncate(text, limit = 40) ⇒ Object
Truncate text to a maximum length, appending “…” when cut.
Instance Method Details
#colored(text, color) ⇒ Object
Render colored text with a named color
17 18 19 |
# File 'lib/clacky/rich_ui/components/base_component.rb', line 17 def colored(text, color) "#{RubyRich::AnsiCode.color(color, true)}#{text}#{RubyRich::AnsiCode.reset}" end |
#muted(text) ⇒ Object
Render muted (dim) text commonly used for secondary info
12 13 14 |
# File 'lib/clacky/rich_ui/components/base_component.rb', line 12 def muted(text) "#{RubyRich::AnsiCode.color(:black, true)}#{text}#{RubyRich::AnsiCode.reset}" end |
#status_marker(status) ⇒ Object
Status marker symbol for todo / activity items
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/clacky/rich_ui/components/base_component.rb', line 22 def status_marker(status) case status when :done, :completed colored("✓", :green) when :running, :in_progress, :active colored("●", :blue) when :failed, :error colored("!", :red) else muted("○") end end |
#theme ⇒ Object
Theme accessor for future theme switching. Currently defaults to agent_dark; can be overridden per-component.
44 45 46 |
# File 'lib/clacky/rich_ui/components/base_component.rb', line 44 def theme @theme ||= RubyRich::Theme.agent_dark end |
#truncate(text, limit = 40) ⇒ Object
Truncate text to a maximum length, appending “…” when cut
36 37 38 39 40 |
# File 'lib/clacky/rich_ui/components/base_component.rb', line 36 def truncate(text, limit = 40) return "" if text.nil? || text.empty? text.length > limit ? "#{text[0...limit]}…" : text end |