Class: RubyRich::RichPanel
- Inherits:
-
Object
- Object
- RubyRich::RichPanel
- Defined in:
- lib/ruby_rich/panel.rb
Constant Summary collapse
- ANSI_CODES =
ANSI escape codes for styling
{ reset: "\e[0m", bold: "\e[1m", underline: "\e[4m", color: { black: "\e[30m", red: "\e[31m", green: "\e[32m", yellow: "\e[33m", blue: "\e[34m", magenta: "\e[35m", cyan: "\e[36m", white: "\e[37m" }, background: { black: "\e[40m", red: "\e[41m", green: "\e[42m", yellow: "\e[43m", blue: "\e[44m", magenta: "\e[45m", cyan: "\e[46m", white: "\e[47m" } }
Instance Attribute Summary collapse
-
#border_color ⇒ Object
Returns the value of attribute border_color.
-
#content ⇒ Object
Returns the value of attribute content.
-
#footer ⇒ Object
Returns the value of attribute footer.
-
#title ⇒ Object
Returns the value of attribute title.
-
#title_color ⇒ Object
Returns the value of attribute title_color.
Instance Method Summary collapse
-
#initialize(content, title: nil, footer: nil, border_color: :white, title_color: :white) ⇒ RichPanel
constructor
A new instance of RichPanel.
- #render ⇒ Object
Constructor Details
#initialize(content, title: nil, footer: nil, border_color: :white, title_color: :white) ⇒ RichPanel
Returns a new instance of RichPanel.
144 145 146 147 148 149 150 |
# File 'lib/ruby_rich/panel.rb', line 144 def initialize(content, title: nil, footer: nil, border_color: :white, title_color: :white) @content = content.is_a?(String) ? content.split("\n") : content @title = title @footer = @border_color = border_color @title_color = title_color end |
Instance Attribute Details
#border_color ⇒ Object
Returns the value of attribute border_color.
142 143 144 |
# File 'lib/ruby_rich/panel.rb', line 142 def border_color @border_color end |
#content ⇒ Object
Returns the value of attribute content.
142 143 144 |
# File 'lib/ruby_rich/panel.rb', line 142 def content @content end |
#footer ⇒ Object
Returns the value of attribute footer.
142 143 144 |
# File 'lib/ruby_rich/panel.rb', line 142 def @footer end |
#title ⇒ Object
Returns the value of attribute title.
142 143 144 |
# File 'lib/ruby_rich/panel.rb', line 142 def title @title end |
#title_color ⇒ Object
Returns the value of attribute title_color.
142 143 144 |
# File 'lib/ruby_rich/panel.rb', line 142 def title_color @title_color end |
Instance Method Details
#render ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/ruby_rich/panel.rb', line 152 def render content_lines = format_content panel_width = calculate_panel_width(content_lines) lines = [] lines << top_border(panel_width) lines += content_lines.map { |line| format_line(line, panel_width) } lines << bottom_border(panel_width) lines.join("\n") end |