The backspace escape \b in elixir isn't working

Viewed 187

The backspace escape

From my experience in C

iex> IO.puts("Hello Wor\bld\b!")

should actually return

"Hello Wol!"

With this it means that the \b actually backspaced the character that came before it. So I tried to do this same thing in elixir and got a different output with the same. The output is as follows Output as per my entries

"Hello World!"

This happens the same in escaping for a new line. \n Please help.. Trying to solve a kata here. Other characters that escape are as follows

\a BEL (0x07) 
\b BS (0x08)
\d DEL (0x7f)
\e ESC (0x1b) 
\f FF (0x0c)
\n NL (0x0a)
\r CR (0x0d) 
\s SP (0x20)
\t TAB (0x09)
\v VT (0x0b) \
\uhhh 1–6 hex digits 
\xhh 2 hex digits
1 Answers

Erlang console erl, iex, is built on the top of, plays dirty tricks with the standard input and output.

Use :stderr to print your string, it’s untouched by erl driver:

iex|1 ▶ IO.puts(:stderr, "Hello Wor\bld\b!")
Hello Wol!

If you have the code in the file/project that is run with mix or directly as elixir my_file.ex everything will obviously work for any standard output.

Related