[Elixir] Tab Autocomplete Stage QP2 - How to detect TAB key?

Hi everyone,

I'm working on the Shell challenge in Elixir and I'm stuck on Stage QP2 (Autocompletion - Builtin completion).

## Problem
When the test presses TAB, I receive spaces instead of the TAB character (byte 9):
- **Expected**: `"$ echo "`
- **Received**: `"$ ech   "` (with spaces)

## What I've Tried

1. **ex_readline library** - Has a bug where tab completion only works with "/" prefix
2. **Custom implementation** with `IO.getn` - Detects TAB (byte 9) locally but not in test environment
3. **stty raw mode** - Works in TTY but CodeCrafters test environment is non-TTY

## My Implementation
```elixir
defp read_loop(buffer, completion_fn, prompt) do
  input = IO.getn("", 1)
  case input do
    <<9>> when completion_fn != nil ->  # TAB
      new_buffer = handle_tab_completion(buffer, completion_fn, prompt)
      read_loop(new_buffer, completion_fn, prompt)
    # ... other cases
  end
end

Questions

  1. Has anyone successfully completed this stage in Elixir?
  2. Is there a specific library or approach recommended for Elixir?
  3. How does the test environment simulate TAB key presses?

Repository

All my attempts are documented here: GitHub - Illuminaxx/codecrafters-shell-elixir See AUTOCOMPLETE_NOTES.md for detailed investigation

The Elixir ecosystem doesn’t have a mature readline library like Python’s readline or Rust’s rustyline, which makes this stage particularly challenging.

Any help would be greatly appreciated! :folded_hands:

1 Like

Hey @Illuminaxx, thanks for documenting everything so thoroughly!

Would you mind elaborating a bit on which specific issues you ran into when working with raw mode?

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.