lib/cli/ui/frame/frame_style/box.rb in cli-ui-2.2.3 vs lib/cli/ui/frame/frame_style/box.rb in cli-ui-2.3.0
- old
+ new
@@ -1,6 +1,7 @@
# typed: true
+# frozen_string_literal: true
module CLI
module UI
module Frame
module FrameStyle
@@ -92,11 +93,12 @@
def edge(text, color:, first:, right_text: nil)
color = CLI::UI.resolve_color(color)
preamble = +''
- preamble << color.code << first << (HORIZONTAL * 2)
+ preamble << color.code if CLI::UI.enable_color?
+ preamble << first << (HORIZONTAL * 2)
unless text.empty?
preamble << ' ' << CLI::UI.resolve_text("{{#{color.name}:#{text}}}") << ' '
end
@@ -126,22 +128,21 @@
# next line and call it poor usage of this API.
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'])
+ unless CLI::UI.enable_cursor?
linewidth = [0, termwidth - (preamble_end + suffix_width + 1)].max
- o << color.code << preamble
- o << color.code << (HORIZONTAL * linewidth)
- o << color.code << suffix
- o << CLI::UI::Color::RESET.code << "\n"
+ o << color.code if CLI::UI.enable_color?
+ o << preamble
+ o << color.code if CLI::UI.enable_color?
+ o << (HORIZONTAL * linewidth)
+ o << color.code if CLI::UI.enable_color?
+ o << suffix
+ o << CLI::UI::Color::RESET.code if CLI::UI.enable_color?
+ o << "\n"
return o
end
# Jumping around the line can cause some unwanted flashes
o << CLI::UI::ANSI.hide_cursor
@@ -156,15 +157,15 @@
# | preamble_end | suffix_end
# | | | | termwidth
# | | | | |
# V V V V V
# --- Preamble text --------------------- suffix text --
- o << color.code
+ o << color.code if CLI::UI.enable_color?
o << print_at_x(preamble_start, HORIZONTAL * (termwidth - preamble_start)) # draw a full line
o << print_at_x(preamble_start, preamble)
- o << color.code
+ o << color.code if CLI::UI.enable_color?
o << print_at_x(suffix_start, suffix)
- o << CLI::UI::Color::RESET.code
+ o << CLI::UI::Color::RESET.code if CLI::UI.enable_color?
o << CLI::UI::ANSI.show_cursor
o << "\n"
o
end