Skip to content

Commit f945691

Browse files
committed
cursors
1 parent 5f7e94d commit f945691

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

test/wizard.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import Pkg: PackageSpec
44

55
import BinaryBuilder.BinaryBuilderBase: available_gcc_builds, available_llvm_builds, getversion
66

7+
# cursor movement in the terminal
8+
const UP = "\e[A"
9+
const DOWN = "\e[B"
10+
const RGHT = "\e[C"
11+
const LEFR = "\e[D"
12+
713
function with_wizard_output(f::Function, state, step_func::Function)
814
# Create fake terminal to communicate with BinaryBuilder over
915
pty = VT100.create_pty(false)
@@ -156,14 +162,14 @@ end
156162

157163
state = Wizard.WizardState()
158164
with_wizard_output(state, Wizard.step1) do ins, outs
159-
call_response(ins, outs, "Make a platform selection", "\e[B\r")
160-
call_response(ins, outs, "Select operating systems", "\e[B\rd"; newline = false)
165+
call_response(ins, outs, "Make a platform selection", "$DOWN\r")
166+
call_response(ins, outs, "Select operating systems", "$DOWN\rd"; newline = false)
161167
end
162168

163169
state = Wizard.WizardState()
164170
with_wizard_output(state, Wizard.step1) do ins, outs
165-
call_response(ins, outs, "Make a platform selection", "\e[B\e[B\r")
166-
call_response(ins, outs, "Select platforms", "\e[B\rd"; newline = false)
171+
call_response(ins, outs, "Make a platform selection", "$DOWN$DOWN\r")
172+
call_response(ins, outs, "Select platforms", "$DOWN\rd"; newline = false)
167173
end
168174
@test length(state.platforms) == 1
169175
end
@@ -194,7 +200,7 @@ end
194200
call_response(ins, outs, "Do you want to customize the set of compilers?", "Y")
195201
call_response(ins, outs, "Select compilers for the project", "ad")
196202
call_response(ins, outs, "Select the preferred GCC version", "\r")
197-
call_response(ins, outs, "Select the preferred LLVM version", "\e[B\e[B\e[B\r")
203+
call_response(ins, outs, "Select the preferred LLVM version", "$DOWN$DOWN$DOWN\r")
198204
end
199205
# Check that the state is modified appropriately
200206
@test state.source_urls == ["http://127.0.0.1:$(port)/a/source.tar.gz"]
@@ -400,7 +406,7 @@ end
400406
call_response(ins, outs, "Would you like to edit this script now?", "N")
401407

402408
# Clean environment
403-
call_response(ins, outs, "Return to build environment", "\e[B\r")
409+
call_response(ins, outs, "Return to build environment", "$DOWN\r")
404410
end
405411
@test state.step === :step3
406412
end
@@ -496,7 +502,7 @@ end
496502
state = step5_state("exit 1")
497503
with_wizard_output(state, state->Wizard.step5_internal(state, first(state.platforms))) do ins, outs
498504
call_response(ins, outs, "Press Enter to continue...", "\n")
499-
call_response(ins, outs, "How would you like to proceed?", "\e[B\e[B\r")
505+
call_response(ins, outs, "How would you like to proceed?", "$DOWN$DOWN\r")
500506
end
501507
@test isempty(state.platforms)
502508
end
@@ -549,7 +555,7 @@ end
549555
# First, test local deployment
550556
mktempdir() do out_dir
551557
with_wizard_output(state, state->Wizard._deploy(state)) do ins, outs
552-
call_response(ins, outs, "How should we deploy this build recipe?", "\e[B\r")
558+
call_response(ins, outs, "How should we deploy this build recipe?", "$DOWN\r")
553559
call_response(ins, outs, "Enter directory to write build_tarballs.jl to:", "$(out_dir)\r")
554560
end
555561
@test isfile(joinpath(out_dir, "build_tarballs.jl"))
@@ -559,7 +565,7 @@ end
559565
# Next, test writing out to stdout
560566
state = step7_state()
561567
with_wizard_output(state, state->Wizard._deploy(state)) do ins, outs
562-
call_response(ins, outs, "How should we deploy this build recipe?", "\e[B\e[B\r")
568+
call_response(ins, outs, "How should we deploy this build recipe?", "$DOWN$DOWN\r")
563569
@test readuntil_sift(outs, "Your generated build_tarballs.jl:") !== nothing
564570
@test readuntil_sift(outs, "name = \"libfoo\"") !== nothing
565571
@test readuntil_sift(outs, "make install") !== nothing

0 commit comments

Comments
 (0)