How to stop input inside iex

How could I send an EOF/EOT inside an input in iex?

Say inside

iex> :all

Usually we do it by pressing ctrl+D on other shells, but that’s something else in Erlang.

If there isn’t a way, how could I stop the input in a way that I could access the data already entered?

You can use Ctrl + G to enter Job control mode, there you can interrupt the running job (e.g. with i 1) and connect to it back.

iex(5)> :all

User switch command
 --> j
   1* {erlang,apply,[#Fun<Elixir.IEx.CLI.1.121285560>,[]]}
 --> i 1
 --> c 1
{:error, :interrupted}

But this way I do not get the input.

I hope there’s a way of transmitting EOT or EOF.

I’m unable to find any info on how to send EOF manually, so I’d guess that the next best thing is to use custom string to terminate the input.

defmodule A do
   def read(acc \\ "") do
     case, :line) do
       "eof\n" -> acc
       line -> read(acc <> line)

1 line
2 line
"1 line\n2 line\n"

You can also just use IO.gets, if you’re only interested in the first line.

Another way to write it:, :line) |> Stream.take_while(&(&1 != "EOF\n")) |> Enum.reduce("", &(&2 <> &1))