Skip to content

Commit

Permalink
Change to replace direct codes with cursor calls
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Aug 5, 2017
1 parent 96aa542 commit 6038a01
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/tty/spinner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ class Spinner
# @raised when attempting to join dead thread
NotSpinningError = Class.new(StandardError)

ECMA_ESC = "\x1b".freeze
ECMA_CSI = "\x1b[".freeze
ECMA_CHA = 'G'.freeze
ECMA_CLR = 'K'.freeze

DEC_RST = 'l'.freeze
DEC_SET = 'h'.freeze
DEC_TCEM = '?25'.freeze

MATCHER = /:spinner/
TICK = '✔'.freeze
CROSS = '✖'.freeze
Expand Down Expand Up @@ -280,7 +274,7 @@ def spin
return if @done

if @hide_cursor && !spinning?
write(ECMA_CSI + DEC_TCEM + DEC_RST)
write(TTY::Cursor.hide)
end

data = message.gsub(MATCHER, @frames[@current])
Expand Down Expand Up @@ -312,7 +306,7 @@ def stop(stop_message = '')
return if @done

if @hide_cursor
write(ECMA_CSI + DEC_TCEM + DEC_SET, false)
write(TTY::Cursor.show, false)
end
return clear_line if @clear

Expand Down Expand Up @@ -426,7 +420,7 @@ def execute_on_line
# @api private
def write(data, clear_first = false)
execute_on_line do
output.print(ECMA_CSI + '1' + ECMA_CHA) if clear_first
output.print(TTY::Cursor.column(1)) if clear_first

# If there's a top level spinner, print with inset
characters_in = @multispinner.nil? ? "" : @multispinner.line_inset(self)
Expand Down

0 comments on commit 6038a01

Please sign in to comment.