I found a similar question on stackoverflow.
Based on that you could do something like this
using REPL
# Run listener as separate task using channels, put keypresses in channel for main loop
function key_listener(c::Channel)
t = REPL.TerminalMenus.terminal
while true
REPL.Terminals.raw!(t, true) || error("unable to switch to raw mode")
keypress = Char(REPL.TerminalMenus.readkey(t.in_stream))
REPL.Terminals.raw!(t, false) || error("unable to switch back from raw mode")
put!(c, keypress)
end
end
function main()
channel = Channel(key_listener, 10) # Start task, 10 is buffer size for channel
stop = false
while !stop
println("Doing some long calculation")
sleep(1)
while !isempty(channel) # Process all keypresses
c = take!(channel)
if c == 'q'
println("quitting")
stop = true
close(channel)
break
else
println("$c is not a recognized command")
end
end
end
end