Method: CLI::UI::Frame.close
- Defined in:
- lib/cli/ui/frame.rb
.close(text, color: nil, elapsed: nil, frame_style: nil, to: $stdout) ⇒ Object
Closes a frame Automatically called for a block-form open
Attributes
-
text- (required) the text/title to output in the frame
Options
-
:color- The color of the frame. Defaults to nil -
:elapsed- How long did the frame take? Defaults to nil -
frame_style- The frame style to use for this frame. Defaults to nil -
: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.close('Close')
Default Output:
┗━━ Close ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Raises
MUST be inside an open frame or it raises a UnnestedFrameException
: (String? text, ?color: colorable?, ?elapsed: Numeric?, ?frame_style: frame_stylable?, ?to: io_like) -> void
203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/cli/ui/frame.rb', line 203 def close(text, color: nil, elapsed: nil, frame_style: nil, to: $stdout) fs_item = FrameStack.pop raise UnnestedFrameException, 'No frame nesting to unnest' unless fs_item close_color = CLI::UI.resolve_color(color || fs_item.color) frame_style = CLI::UI.resolve_style(frame_style || fs_item.frame_style) elapsed_string = elapsed ? "(#{elapsed.round(2)}s)" : nil CLI::UI.raw do to.print(prefix.chop) to.puts(frame_style.close(text.to_s, color: close_color, right_text: elapsed_string)) end end |