module CLI::UI::Frame::FrameStyle::Bracket
Constants
- BOTTOM_LEFT
- DIVIDER
- HORIZONTAL
- TOP_LEFT
- VERTICAL
Public Class Methods
close(text, color:, right_text: nil)
click to toggle source
Draws the “Close” line for this frame style
Attributes¶ ↑
-
text
- (required) the text/title to output in the frame
Options¶ ↑
-
:color
- (required) The color of the frame. -
:right_text
- Text to print at the right of the line. Defaults to nil
Output:¶ ↑
┗━━ Close
# File lib/cli/ui/frame/frame_style/bracket.rb, line 74 def close(text, color:, right_text: nil) edge(text, color: color, right_text: right_text, first: BOTTOM_LEFT) end
divider(text, color:)
click to toggle source
Draws a “divider” line for the current frame style
Attributes¶ ↑
-
text
- (required) the text/title to output in the frame
Options¶ ↑
-
:color
- (required) The color of the frame.
Output:¶ ↑
┣━━ Divider
# File lib/cli/ui/frame/frame_style/bracket.rb, line 55 def divider(text, color:) edge(text, color: color, first: DIVIDER) end
name()
click to toggle source
# File lib/cli/ui/frame/frame_style/bracket.rb, line 15 def name 'bracket' end
open(text, color:)
click to toggle source
Draws the “Open” line for this frame style
Attributes¶ ↑
-
text
- (required) the text/title to output in the frame
Options¶ ↑
-
:color
- (required) The color of the frame.
Output¶ ↑
┏━━ Open
# File lib/cli/ui/frame/frame_style/bracket.rb, line 37 def open(text, color:) edge(text, color: color, first: TOP_LEFT) end
prefix()
click to toggle source
# File lib/cli/ui/frame/frame_style/bracket.rb, line 19 def prefix VERTICAL end
Private Class Methods
edge(text, color:, first:, right_text: nil)
click to toggle source
# File lib/cli/ui/frame/frame_style/bracket.rb, line 80 def edge(text, color:, first:, right_text: nil) color = CLI::UI.resolve_color(color) preamble = +'' preamble << color.code << first << (HORIZONTAL * 2) text ||= '' unless text.empty? preamble << ' ' << CLI::UI.resolve_text("{{#{color.name}:#{text}}}") << ' ' end suffix = +'' if right_text suffix << ' ' << right_text << ' ' end o = +'' # Shopify's CI system supports terminal emulation, but not some of # the fancier features that we normally use to draw frames # extra-reliably, so we fall back to a less foolproof strategy. This # is probably better in general for cases with impoverished terminal # emulators and no active user. unless [0, '', nil].include?(ENV['CI']) o << color.code << preamble o << color.code << suffix o << CLI::UI::Color::RESET.code o << "\n" return o end preamble_start = Frame.prefix_width # If prefix_width is non-zero, we need to subtract the width of # the final space, since we're going to write over it. preamble_start -= 1 unless preamble_start.zero? # Prefix_width includes the width of the terminal space, which we # want to remove. The clamping is done to avoid a negative # preamble start which can occur for the first frame. o << CLI::UI::ANSI.hide_cursor # reset to column 1 so that things like ^C don't ruin formatting o << "\r" o << color.code o << print_at_x(preamble_start, preamble + color.code + suffix) o << CLI::UI::Color::RESET.code o << "\n" o end