-
Couldn't load subscription status.
- Fork 3k
Description
Describe the bug
It seems whenever a command being written to the shell does not have a newline, one is automatically added since Erlang/OTP 28. However, if the newline is followed by ANSI escape codes, then the current code considers the newline is missing, adding one additional newline.
See this snippet:
9> spawn(fun() -> receive after 1000 -> ok end, io:put_chars(["omg"]) end).
<0.108.0>
omg
10> spawn(fun() -> receive after 1000 -> ok end, io:put_chars(["omg\n"]) end).
<0.110.0>
omg
11> spawn(fun() -> receive after 1000 -> ok end, io:put_chars(["omg\n", <<27,91,48,109>>]) end).
<0.112.0>
omg
12>
The <<27,91,48,109>> bit is the ANSI escape reset, which is not visibile at all, but still causes an additional newline to be printed.
Expected behavior
We should probably detect if all we have after the newline are ANSI escapes and ignore them. I believe there is already code in prim_tty to deal with these cases.
Affected versions
As far as I know, from Erlang/OTP 28. I believe this commit is the root cause: 8538a8b
This bug was originally reported here: elixir-lang/elixir#14841