In-terminal code editor with AI-powered code completion
Powered by DeepSeek V4 & Textual
g023's Code Completer is a terminal-based text editor that brings AI-assisted coding directly into your command line. Built with Python and the Textual TUI framework, it provides a lightweight, distraction-free editing environment with deep integration of DeepSeek's state-of-the-art language model to help you write code faster.
Whether you're editing configuration files, writing Python scripts, or tweaking HTML/CSS, the editor offers syntax highlighting, smooth keyboard navigation, and on-demand AI completions – all without leaving your terminal.
| Feature | Description |
|---|---|
| Syntax Highlighting | Supports Python, JavaScript, HTML, CSS, JSON, and many more languages |
| AI Code Completion | Trigger intelligent completions with Alt+G |
| Non‑blocking Async | Completions run in the background – your workflow never pauses |
| File Management | Open (Ctrl+O) and save (Ctrl+S) files easily |
| Modal File Browser | Visually browse and select files from anywhere in your home directory |
| Smart Indentation | Tab inserts 4 spaces; type‑aware and consistent |
| Status Bar | Real‑time feedback and messages about file operations and completions |
| Mouse Support | Fully interactive with your terminal mouse (if supported) |
- Python 3.8+
- Textual – the modern TUI framework
- A DeepSeek API key – get one from DeepSeek Platform
# Clone the repository
git clone https://github.com/g023/code_completer.git
cd code_completer
# Install the required dependency
pip install textualThe editor needs your DeepSeek API key to work. You can provide it in two ways:
export DEEPSEEK_API_KEY="your-api-key-here"Place a file named K.dat one directory above the project root. The file should contain your API key as a single line.
💡 The key resolution logic looks for
../K.datrelative to the script location. This keeps your key out of the repository while still working across environments.
python code_completer.pyTo open a specific file on launch:
python code_completer.py path/to/your/file.py| Shortcut | Action |
|---|---|
| Ctrl+O | Open a file |
| Ctrl+S | Save the current file |
| Ctrl+Q | Quit the editor |
| Alt+G | Request AI completion at cursor position |
| Tab | Insert 4 spaces (indent) |
| Mouse | Click to move cursor, navigate file browser |
The editor is split into two main components:
- Built with Textual – a reactive TUI framework with CSS-like styling
- Manages the main editing area, file browser modal, and status updates
- Handles user input, syntax highlighting, and file I/O
- A minimal, zero‑dependency DeepSeek client
- Implements rate limiting, retry logic, and automatic API key resolution
- Supports
chat_prefix_complete()– DeepSeek V4’s efficient prefix completion API
- When you press Alt+G, the current code and cursor position are captured.
- The code is split into prefix (text before cursor) and suffix (text after cursor).
- A structured prompt is sent to DeepSeek V4 using the
chat_prefix_completeendpoint – this tells the model to only return raw completion text (no greetings, no markdown, no explanations). - The response is then cleaned:
- Meta‑phrases like "Here's the completion:" are stripped.
- Lines ending with a question mark are removed (when enabled).
- Short or empty completions are filtered out.
- The cleaned completion is inserted at the cursor – asynchronously, so the editor never freezes.
All heavy API calls run in a dedicated thread; UI updates are safely posted back to the main thread.
The behaviour of the AI completion can be adjusted by editing the constants at the top of code_completer.py:
| Parameter | Default | Description |
|---|---|---|
COMPLETION_TEMPERATURE |
0.15 | Lower = more deterministic, higher = more creative |
COMPLETION_MAX_TOKENS |
512 | Maximum length of the completion response |
MIN_COMPLETION_LENGTH |
3 | Drop completions shorter than this (filters stray characters) |
MAX_COMPLETION_LENGTH |
2000 | Hard cap on returned characters |
STRIP_QUESTION_LINES |
True |
Remove lines that look like clarifying questions |
STRIP_META_LINES |
True |
Remove conversational filler (e.g., "Sure, here's...") |
- Make sure you’ve set the
DEEPSEEK_API_KEYenvironment variable, or created../K.datrelative to the project folder. - Verify the key is valid and has sufficient credits.
- Check your internet connection.
- Ensure you’ve installed
textual(pip install textual). - Try running the script from outside a virtual environment if you suspect dependency conflicts.
- The built‑in cleaning logic may be filtering out legitimate output. Try setting
STRIP_META_LINES = FalseandMIN_COMPLETION_LENGTH = 1temporarily to see the raw response. - DeepSeek V4 works best with clear context. Make sure your code is well‑structured and the cursor is placed logically.
- Completions run asynchronously, so they shouldn’t block typing. If you experience lag, check your terminal emulator settings or try a different terminal (e.g., Alacritty, Kitty, iTerm2).
MIT – feel free to use, modify, and distribute.
