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

**URL:** https://forum.codecrafters.io/t/elixir-tab-autocomplete-stage-qp2-how-to-detect-tab-key/15535
**Category:** Challenges
**Tags:** challenge:shell
**Created:** [November 15, 2025, 9:19pm UTC](https://forum.codecrafters.io/t/elixir-tab-autocomplete-stage-qp2-how-to-detect-tab-key/15535 "2025-11-15T21:19:23Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Illuminaxx](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/illuminaxx/32/19931_2.png) [@Illuminaxx](https://forum.codecrafters.io/u/Illuminaxx)
#### Post date: [November 15, 2025, 9:19pm UTC](https://forum.codecrafters.io/t/elixir-tab-autocomplete-stage-qp2-how-to-detect-tab-key/15535/1 "2025-11-15T21:19:23Z")

</div>

````auto
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](https://github.com/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! 🙏

---

<div class="post-metadata">

### Author: ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)
#### Post date: [November 19, 2025, 3:45am UTC](https://forum.codecrafters.io/t/elixir-tab-autocomplete-stage-qp2-how-to-detect-tab-key/15535/4 "2025-11-19T03:45:33Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)
#### Post date: [November 25, 2025, 12:15am UTC](https://forum.codecrafters.io/t/elixir-tab-autocomplete-stage-qp2-how-to-detect-tab-key/15535/6 "2025-11-25T00:15:27Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)
#### Post date: [November 30, 2025, 12:15am UTC](https://forum.codecrafters.io/t/elixir-tab-autocomplete-stage-qp2-how-to-detect-tab-key/15535/7 "2025-11-30T00:15:46Z")

</div>

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