Skip to content

Commit

Permalink
Fix cursor hiding in threaded run
Browse files Browse the repository at this point in the history
auto_spin ensure was called right after starting to spin, so the
cursor was never actually hidden.
  • Loading branch information
orgads committed Sep 15, 2023
1 parent 596bf41 commit 2aa1e62
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change log

## [v0.10.0] - unreleased
* Fix cursor hiding in threaded run

### Added
* Add Spinner#log method for logging messages above the spinner
Expand Down
6 changes: 2 additions & 4 deletions lib/tty/spinner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,10 @@ def auto_spin
spin
sleep(sleep_time)
end
ensure
write(TTY::Cursor.show, false) if @hide_cursor
end
end
ensure
if @hide_cursor
write(TTY::Cursor.show, false)
end
end

# Checked if current spinner is paused
Expand Down
13 changes: 9 additions & 4 deletions spec/unit/auto_spin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
expect(spinner).to have_received(:spin).at_least(5).times
end

it "restores cursor when erorr is raised" do
it "restores cursor when error is raised" do
spinner = TTY::Spinner.new(output: output, hide_cursor: true)

spinner.auto_spin {
raise "boom"
}
Thread.report_on_exception = false
begin
spinner.run do
raise "boom"
end
rescue RuntimeError
end
Thread.report_on_exception = true

output.rewind
expect(output.read).to start_with("\e[?25l").and end_with("\e[?25h")
Expand Down

0 comments on commit 2aa1e62

Please sign in to comment.