Implementing TAB autocompletion in Elixir - Need guidance

Hi CodeCrafters team,

I’m working on the Shell challenge using Elixir and I’m stuck on Stage #QP2 (Tab Autocompletion - Builtin completion).

The Problem: The test expects TAB autocompletion to work, but Elixir/Erlang doesn’t have native readline support in standalone escripts like Node.js does with its built-in readline module.

What I’ve Tried:

  • :io.setopts(:standard_io, [expand_fun: &my_func/1])
  • Application.put_env(:stdlib, :shell_expand_fun, &my_func/1)
  • Manual character-by-character reading with IO.getn/2
  • Various terminal control sequences (ANSI, backspace, etc.)

None of these approaches work because Erlang’s expand_fun only works in an interactive Erlang shell, not in a compiled escript running standalone.

The Issue: In JavaScript (as shown in the community solutions), you can use Node.js’s readline module with a completer function:

javascript

readline.createInterface({
    completer: (line) => { /* autocomplete logic */ }
});

Elixir doesn’t have an equivalent built-in feature. The only solution would be to use an external library like erlang-readline or implement a C NIF binding to libreadline.

My Questions:

  1. Is it expected that Elixir users add external dependencies for this stage?
  2. Can I modify mix.exs to add {:erlang-readline, "~> 1.0"} or similar?
  3. Is there a CodeCrafters-specific solution I’m missing?
  4. Should I skip this stage for now if no native solution exists?

Current Test Output:

Expected: "$ echo "
Received: "$ ech   "

The autocompletion function is never triggered because there’s no way to hook into TAB handling in an Elixir escript without external libraries.

Any guidance would be greatly appreciated!

Thanks,
Illuminaxx

Hi, thanks for your post!

I’m currently out of the office for the holidays and will be back on January 5. I’ll get back to you as soon as possible once I return.