Skip to content

Commit

Permalink
Merge f3b0b9b into 8765128
Browse files Browse the repository at this point in the history
  • Loading branch information
benklop committed Dec 3, 2019
2 parents 8765128 + f3b0b9b commit 67f1040
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/tty/spinner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def spin
# @api private
def redraw_indent
if @hide_cursor && !spinning?
write(ECMA_CSI + DEC_TCEM + DEC_RST)
write(TTY::Cursor.hide)
end

write("", false)
Expand Down
65 changes: 47 additions & 18 deletions spec/unit/spin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,55 @@
].join)
end

it "can spin and redraw indent" do
multi_spinner = double("MultiSpinner")
allow(multi_spinner).to receive(:synchronize).and_yield
allow(multi_spinner).to receive(:next_row).and_return(1)
allow(multi_spinner).to receive(:rows).and_return(1)
allow(multi_spinner).to receive(:line_inset).and_return("--- ")
context "with the cursor" do
before do
multi_spinner = double("MultiSpinner")
allow(multi_spinner).to receive(:synchronize).and_yield
allow(multi_spinner).to receive(:next_row).and_return(1)
allow(multi_spinner).to receive(:rows).and_return(1)
allow(multi_spinner).to receive(:line_inset).and_return("--- ")

spinner = TTY::Spinner.new(output: output)
spinner.attach_to(multi_spinner)
spinner.spin
spinner.redraw_indent
spinner = TTY::Spinner.new(output: output, hide_cursor: hide_cursor)
spinner.attach_to(multi_spinner)
spinner.spin
spinner.redraw_indent

output.rewind
expect(output.read).to eq([
"\e[1G--- |\n",
save,
"\e[1A",
"--- ",
restore,
].join)
output.rewind
end

context "on" do
let(:hide_cursor) { false }

it "can spin and redraw indent" do
expect(output.read).to eq([
"\e[1G--- |\n",
save,
"\e[1A",
"--- ",
restore,
].join)
end
end

context "off" do
let(:hide_cursor) { true }

it "can spin and redraw indent" do
expect(output.read).to eq([
"--- ",
"\e[?25l\n",
save,
"\e[1A",
"\e[1G",
"--- |",
restore,
save,
"\e[1A",
"--- ",
restore,
].join)
end
end
end

it "spins with many threads" do
Expand Down

0 comments on commit 67f1040

Please sign in to comment.