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

add a timer fallback to hideprompt #301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ end
const is_blocking_repl_input = Ref{Bool}(false)

function blockinput()
is_blocking_repl_input[] && return
is_blocking_repl_input[] = true
try
Base.disable_sigint() do
Expand All @@ -112,6 +113,8 @@ function blockinput()
nothing
end

const timer = Ref(Timer(0))

function hideprompt(f)
isREPL() || return f()
isdebugging() && return f()
Expand All @@ -133,6 +136,18 @@ function hideprompt(f)
if INIT_COMPLETE[]
# Escape REPL modes, then write sentinel and trigger chars.
can_write_to_terminal = something(Atom.@rpc(writeToTerminal("\b\a$(REPL_SENTINEL_CHAR)$(REPL_TRIGGER_CHAR)")), true)
Copy link
Member

@aviatesk aviatesk Mar 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this check ? Can't we always writeToTerminal and then blockinput for this pass ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point -- we should only start the timer if can_write_to_terminal == true.


# If, for some reason (e.g. weird repl modes), the above statement returns
# true but the Julia REPL never receives the keypresses, we'll just pretend
# everything is fine after 0.75 seconds and carry on.
isopen(timer[]) && close(timer[])
@async begin
timer[] = Timer(0.75)
wait(timer[])
blockinput()
end
yield()

can_write_to_terminal && take!(waiter_out)
end
r = nothing
Expand All @@ -145,7 +160,11 @@ function hideprompt(f)
sleep(0.05)

pos = @rpc cursorpos()

# cleanup
INIT_COMPLETE[] && can_write_to_terminal && is_blocking_repl_input[] && put!(waiter_in, nothing)
isopen(timer[]) && close(timer[])

pos[1] != 0 && println()

# restore prompt
Expand Down