Skip to content

Commit

Permalink
Update tty-cursor version for #save and #restore
Browse files Browse the repository at this point in the history
  • Loading branch information
austb committed Aug 1, 2017
1 parent 083935b commit 5db19c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
6 changes: 2 additions & 4 deletions lib/tty/spinner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,10 @@ def execute_on_line
output.print "\n"
@first_run = false
else
output.print TTY::Cursor.save
output.print TTY::Cursor.up(lines_up)
yield if block_given?
output.print TTY::Cursor.down(lines_up - 1) if lines_up > 1

# Returns to beginning of the line
output.print TTY::Cursor.next_line
output.print TTY::Cursor.restore
end
end
else
Expand Down
17 changes: 9 additions & 8 deletions spec/unit/spin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
spinner2 = TTY::Spinner.new(output: output, interval: 100)
spinner2.add_multispinner(multi_spinner, 1)

save = Gem.win_platform? ? "\e[s" : "\e7"
restore = Gem.win_platform? ? "\e[u" : "\e8"

spinner.spin
spinner2.spin
output.rewind
Expand All @@ -66,27 +69,25 @@
expect(output.read).to eq([
"\e[1G|\n",
"\e[1G|\n",
save,
"\e[2A", # up 2 lines
"\e[1G/",
"\e[1B", # down 1 line
"\e[E", # next line
"\e[1G"
restore
].join)

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

end
Expand Down
2 changes: 1 addition & 1 deletion tty-spinner.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
spec.files = Dir['lib/**/*.rb', 'LICENSE.txt', 'README.md']
spec.require_paths = ['lib']

spec.add_runtime_dependency 'tty-cursor'
spec.add_runtime_dependency 'tty-cursor', '>= 0.5.0'
spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
spec.add_development_dependency 'rake'
end

0 comments on commit 5db19c3

Please sign in to comment.