Skip to content

Commit

Permalink
Move TTY::Cursor up and down explicitly
Browse files Browse the repository at this point in the history
Terminal.app does not respect ANSI cursor save and restore sequences so
instead this commit moves the cursor explicitly with up and down
commands to ensure compatibility.
  • Loading branch information
austb committed Jul 28, 2017
1 parent dcf138d commit a8a0fbf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
8 changes: 5 additions & 3 deletions lib/tty/spinner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,12 @@ def execute_on_line
output.print "\n"
@first_run = false
else
output.print TTY::Cursor.save
output.print TTY::Cursor.up lines_up
output.print TTY::Cursor.up(lines_up)
yield if block_given?
output.print TTY::Cursor.restore
output.print TTY::Cursor.down(lines_up - 1)

# Returns to beginning of the line
output.print TTY::Cursor.next_line
end
end
else
Expand Down
15 changes: 9 additions & 6 deletions spec/unit/spin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,28 @@
expect(output.read).to eq([
"\e[1G|\n",
"\e[1G|\n",
"\e[s", # save position
"\e[2A", # up 2 lines
"\e[1G/",
"\e[u" # restore position
"\e[1B", # down 1 line
"\e[E", # next line
"\e[1G"
].join)

spinner2.spin
output.rewind
expect(output.read).to eq([
"\e[1G|\n",
"\e[1G|\n",
"\e[s", # save position
"\e[2A", # up 2 lines
"\e[1G/",
"\e[u", # restore position
"\e[s", # save position
"\e[1B", # down 1 line
"\e[E", # next line
"\e[1G",
"\e[1A", # up 1 line
"\e[1G/",
"\e[u" # restore position
"\e[0B", # down 0 line
"\e[E", # next line
"\e[1G"
].join)

end
Expand Down

0 comments on commit a8a0fbf

Please sign in to comment.