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:
- Is it expected that Elixir users add external dependencies for this stage?
- Can I modify
mix.exsto add{:erlang-readline, "~> 1.0"}or similar? - Is there a CodeCrafters-specific solution I’m missing?
- 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