lib/dev/ui/frame.rb in dev-ui-0.1.1 vs lib/dev/ui/frame.rb in dev-ui-0.1.2
- old
+ new
@@ -27,28 +27,28 @@
# * +:failure_text+ - If the block failed, what do we output? Defaults to nil
# * +:success_text+ - If the block succeeds, what do we output? Defaults to nil
# * +:timing+ - How long did the frame content take? Invalid for blockless. Defaults to true for the block form
#
# ==== Example
- #
+ #
# ===== Block Form (Assumes +Dev::UI::StdoutRouter.enable+ has been called)
#
# Dev::UI::Frame.open('Open') { puts 'hi' }
#
# Output:
# ┏━━ Open ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# ┃ hi
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ (0.0s) ━━
- #
+ #
# ===== Blockless Form
#
# Dev::UI::Frame.open('Open')
#
# Output:
# ┏━━ Open ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
#
- #
+ #
def open(
text,
color: DEFAULT_FRAME_COLOR,
failure_text: nil,
success_text: nil,
@@ -78,11 +78,11 @@
closed = false
begin
success = false
success = yield
- rescue Exception
+ rescue
closed = true
t_diff = timing ? (Time.now.to_f - t_start) : nil
close(failure_text, color: :red, elapsed: t_diff)
raise
else
@@ -116,11 +116,11 @@
# Dev::UI::Frame.close('Close')
#
# Output:
# ┗━━ Close ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
#
- #
+ #
def close(text, color: DEFAULT_FRAME_COLOR, elapsed: nil)
color = Dev::UI.resolve_color(color)
FrameStack.pop
kwargs = {}
@@ -186,11 +186,11 @@
<< Dev::UI::Box::Heavy::VERT << ' ' << Dev::UI::Color::RESET.code
end
pfx
end
- # Override a color for a given thread.
+ # Override a color for a given thread.
#
# ==== Attributes
#
# * +color+ - The color to override to
#
@@ -200,11 +200,11 @@
yield
ensure
Thread.current[:devui_frame_color_override] = prev
end
- # The width of a prefix given the number of Frames in the stack
+ # The width of a prefix given the number of Frames in the stack
#
def prefix_width
w = FrameStack.items.size
w.zero? ? 0 : w + 1
end
@@ -252,18 +252,18 @@
is_ci = ![0, '', nil].include?(ENV['CI'])
# Jumping around the line can cause some unwanted flashes
o << Dev::UI::ANSI.hide_cursor
- if is_ci
- # In CI, we can't use absolute horizontal positions because of timestamps.
- # So we move around the line by offset from this cursor position.
- o << Dev::UI::ANSI.cursor_save
- else
- # Outside of CI, we reset to column 1 so that things like ^C don't
- # cause output misformatting.
- o << "\r"
- end
+ o << if is_ci
+ # In CI, we can't use absolute horizontal positions because of timestamps.
+ # So we move around the line by offset from this cursor position.
+ Dev::UI::ANSI.cursor_save
+ else
+ # Outside of CI, we reset to column 1 so that things like ^C don't
+ # cause output misformatting.
+ "\r"
+ end
o << color.code
o << Dev::UI::Box::Heavy::HORZ * termwidth # draw a full line
o << print_at_x(prefix_start, prefix, is_ci)
o << color.code