I would like to implement a REPL in another language than Erlang, and am really intrigued by this feature of the interactive erl
(Eshell) prompt:
1> spawn(fun() -> timer:sleep(5000), io:format("~p~n", ["later"]) end).
<0.34.0>
2> i can ty
So what I did here is spawn some background process that eventually writes to the terminal. In the meantime I've typed i can ty
just as five seconds have passed by and "later"
gets inserted right above 2>
, resulting in:
1> spawn(fun() -> timer:sleep(5000), io:format("~p~n", ["later"]) end).
<0.34.0>
"later"
2> i can type...
In other languages, such as Bash or Node.js, this would rather have resulted in something like:
2> i can ty"later"
pe...
How does Erlang do that? I've tried googling around and even had a quick look at its source code, but could not find out how this gets accomplished. I assume it must involve some terminal control sequences?