Method: CLI::UI::Frame.divider
- Defined in:
- lib/cli/ui/frame.rb
.divider(text, color: nil, frame_style: nil, to: $stdout) ⇒ Object
Adds a divider in a frame Used to separate information within a single frame
Attributes
-
text- (required) the text/title to output in the frame
Options
-
:color- The color of the frame. Defaults toDEFAULT_FRAME_COLOR -
frame_style- The frame style to use for this frame -
:to- Target stream, like $stdout or $stderr. Can be anything with print and puts methods, or under Sorbet, IO or StringIO. Defaults to $stdout.
Example
CLI::UI::Frame.open('Open') { CLI::UI::Frame.divider('Divider') }
Default Output:
┏━━ Open ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┣━━ Divider ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Raises
MUST be inside an open frame or it raises a UnnestedFrameException
: (String? text, ?color: colorable?, ?frame_style: frame_stylable?, ?to: io_like) -> void
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/cli/ui/frame.rb', line 161 def divider(text, color: nil, frame_style: nil, to: $stdout) fs_item = FrameStack.pop raise UnnestedFrameException, 'No frame nesting to unnest' unless fs_item divider_color = CLI::UI.resolve_color(color || fs_item.color) frame_style = CLI::UI.resolve_style(frame_style || fs_item.frame_style) CLI::UI.raw do to.print(prefix.chop) to.puts(frame_style.divider(text.to_s, color: divider_color)) end FrameStack.push(fs_item) end |