Elixir: Behaviour of Backspace in iex

170 Views Asked by At

I'm using Elixir 1.15.0 with Erlang/OTP 26 on Arch Linux. I haven't configured anything; I'm just using the default setup.

When I type the following code in IEx:

i <- [1, 2, 3], j <- [10, 20, 30], into: %{}, do: "#{i}*{j}

And then press [Backspace], because I forgot the # before {j}, the result looks as follows:

i <- [1, 2, 3], j <- [10, 20, 30], into: %{}, do: "#{

Not only } (what I'd expect) or {j} (which would be convenient) was deleted, but also the i} part that was correct.

I noticed that [Backspace] in IEx deletes not only single characters, but entire symbols. This behaviour is not useful for me, because all the other REPLs I'm using behave differently.

How can I get my regular backspace function back in IEx?

Edit 1: The backspace character works as usual in the terminal outside of iex. My $TERM is xterm-256color. I also tested it with my default terminal qterminal as well as xterm, in which iex misbehaves the same way.

Edit 2: I have the exact same behaviour in erl, so it might be an Erlang issue, not one of the Elixir project. What's the common ground of those two REPLs?

4

There are 4 best solutions below

0
Patrick Bucher On BEST ANSWER

The issue has been resolved in Erlang OTP 26.2.1.

0
Adam Millerchip On

I don't use Arch Linux, but I couldn't reproduce your issue using Docker:

Dockerfile:

FROM archlinux:latest
RUN pacman --noconfirm -Sy --needed elixir
ENTRYPOINT ["iex"]

Building:

$ docker build . -t arch_elixir

Running:

$ docker run --rm -it arch_elixir
Erlang/OTP 26 [erts-14.1] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.15.6) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> i <- [1, 2, 3], j <- [10, 20, 30], into: %{}, do: "#{i}*{j
1
Onorio Catenacci On

To consolidate some of the clarifications I asked for in comments so they'll be more obvious if anyone searches for this:

1.) Check the terminal emulation you're using. One simple way to do this is echo $TERM. This is information which will help others to reproduce (or not) the behavior in question.

2.) Try using the backspace at the terminal prompt. If you see the extra characters wiped at the terminal prompt then it's not Elixir and you should look elsewhere for an answer.

3.) If you have an .iex.exs file present, temporarily rename it or move it to another directory. This may affect the behavior of the backspce.


EDIT:

Given what the original poster has shared about this behavior, I think this may be pertinent:

https://www.erlang.org/patches/otp-26.0

I can't link it directly but this portion: OTP-17932

Note especially this:

The TTY/terminal subsystem has been rewritten by moving more code to Erlang from the old linked-in driver and implementing all the I/O primitives needed in a NIF instead.

And this seems like it may be worth trying to see if it affects the behavior you're seeing:

-- Standard I/O now always defaults to unicode mode if supported. Previously the default was latin1 if the runtime system had been started with -oldshell or -noshell (for example in an escript). To send raw bytes over standard out, one now explicitly has to specify io:setopts(standard_io, [{encoding, latin1}]).

(Emphasis is mine.)

2
Fredrik Sjöstedt On

I have exactly the same problem on Manjaro-KDE. I found though that it has to do with the terminal.

When running in Terminology i get the described behaviour, when running in konsole it behaves as expected