Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TTY::Cursor.hide instead of constants #39

Merged
merged 4 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
benklop marked this conversation as resolved.
Show resolved Hide resolved
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