Skip to content

Commit 6553741

Browse files
jwesleyeclaude
andcommitted
docs: update multi-line editor cancel instructions
Update all documentation to reflect working cancel methods: - Remove ESC and Ctrl+C references (not working reliably) - Keep Ctrl+D (works reliably) and .cancel command - Update inline instructions in multi-line mode - Update help text and banner - Update README.md feature list - Update MULTILINE_EDITOR_ENHANCEMENTS.md comprehensively Changes: - Multi-line mode now shows: "Ctrl+D or .cancel to cancel" - Up arrow editing instructions unchanged (working correctly) - Simplified cancel options to only documented working methods - All 286 tests still passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6d3ca09 commit 6553741

4 files changed

Lines changed: 36 additions & 42 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ A feature-rich, interactive CLI for AI agents with token tracking, prompt templa
1414
- 📦 **Auto-Setup** - Automatically install agent dependencies from `requirements.txt` or `pyproject.toml`
1515
- 🔔 **Audio Notifications** - Play sound when agent completes a turn (cross-platform support)
1616
- 📜 **Command History** - Navigate previous queries with ↑↓ arrows (persisted to `~/.chat_history`)
17-
- ✍️ **Multi-line Input** - Type `\\` to enter multi-line mode with ESC to cancel and ↑ to edit previous lines
17+
- ✍️ **Multi-line Input** - Type `\\` to enter multi-line mode with Ctrl+D to cancel and ↑ to edit previous lines
1818
- 💰 **Token Tracking** - Track tokens and costs per query and session
1919
- 📝 **Prompt Templates** - Reusable prompts from `~/.prompts/`
2020
- ⚙️ **Configuration** - YAML-based config with per-agent overrides

docs/MULTILINE_EDITOR_ENHANCEMENTS.md

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@
33
## Overview
44

55
The multi-line editor has been significantly enhanced with intuitive keyboard controls:
6-
1. **ESC key cancellation** - instantly cancel with ESC
6+
1. **Ctrl+D cancellation** - instantly cancel with Ctrl+D
77
2. **Up arrow editing** - press ↑ at start of line to edit previous line
88
3. **History integration** - recall entire multi-line blocks with up arrow at main prompt
9-
4. **Multiple cancel options** - ESC, .cancel, Ctrl+C, or Ctrl+D
9+
4. **Multiple cancel options** - Ctrl+D or .cancel command
1010

1111
## Features Implemented
1212

1313
### 1. Cancel Options
1414

15-
Users can now cancel multi-line input in four ways:
15+
Users can now cancel multi-line input in two ways:
1616

17-
- **ESC key**: Press ESC at the start of any line for instant cancellation (cross-platform)
17+
- **Ctrl+D**: Press Ctrl+D for instant EOF cancellation (works reliably across platforms)
1818
- **`.cancel` command**: Type `.cancel` at any prompt to cancel
19-
- **Ctrl+C**: Keyboard interrupt to cancel
20-
- **Ctrl+D**: EOF signal to cancel
2119

22-
All cancel methods return empty string and show a clear cancellation message. The ESC key detection works on Unix/Linux/Mac (via termios) and Windows (via msvcrt).
20+
Both cancel methods return empty string and show a clear cancellation message.
2321

2422
### 2. Previous Line Editing with Up Arrow
2523

@@ -88,36 +86,37 @@ Multi-line mode:
8886

8987
The multi-line editor detects special keys at the start of each line:
9088

91-
**ESC Key** - Instant cancellation:
92-
```
93-
1│ [press ESC]
94-
✗ Multi-line input cancelled (ESC)
95-
```
96-
9789
**Up Arrow** - Edit previous line:
9890
```
9991
1│ line one
10092
2│ [press ↑]
10193
↑ Editing line 1...
10294
```
10395

96+
**Ctrl+D** - Cancel input:
97+
```
98+
1│ started typing
99+
2│ [press Ctrl+D]
100+
✗ Multi-line input cancelled (Ctrl+D)
101+
```
102+
104103
**Implementation Details**:
105-
- Uses platform-specific terminal control:
104+
- Uses platform-specific terminal control for up arrow detection:
106105
- Unix/Linux/Mac: `termios` and `tty` for raw input, `select` for sequence detection
107106
- Windows: `msvcrt` for character-level input
108-
- Detects special keys on the first character of each line
109-
- ESC key: ASCII 27 (`\x1b`)
107+
- Detects up arrow on the first character of each line
110108
- Up arrow: Escape sequence `\x1b[A` on Unix, `\xe0H` on Windows
109+
- Ctrl+D: Standard EOF signal handled by Python's EOFError exception
111110
- Falls back gracefully to `.cancel` and `.back` commands if detection unavailable
112111
- Zero dependencies - uses Python standard library only
113112

114113
**How it works**:
115114
1. Before reading a line, attempts to read a single character in raw mode
116-
2. If ESC detected, checks within 100ms for following characters:
117-
- If `[A` follows → Up arrow detected
118-
- If no characters follow → ESC key detected
119-
3. If other character detected, includes it and continues with normal `input()`
120-
4. Maintains full readline editing capabilities for mid-line input
115+
2. If escape sequence detected:
116+
- If `\x1b[A` follows → Up arrow detected
117+
3. If Ctrl+D pressed → EOFError caught and handled as cancellation
118+
4. If other character detected, includes it and continues with normal `input()`
119+
5. Maintains full readline editing capabilities for mid-line input
121120

122121
## Implementation Details
123122

@@ -132,21 +131,19 @@ The multi-line editor detects special keys at the start of each line:
132131

133132
1. **Up Arrow Editing**: The most intuitive way to edit previous lines - just press ↑ at the start of a line. Detects arrow key sequences in raw terminal mode before `input()` takes over.
134133

135-
2. **ESC for Cancel**: ESC key provides instant cancellation, matching user expectations from other terminal applications and editors.
134+
2. **Ctrl+D for Cancel**: Uses standard EOF signal (Ctrl+D) which works reliably across all platforms and terminal emulators.
136135

137-
3. **First-Character Detection Only**: Special keys (ESC, ↑) are only detected at the start of a line. Once typing begins, readline takes over with full editing capabilities (including mid-line arrow navigation).
136+
3. **First-Character Detection Only**: Up arrow is only detected at the start of a line. Once typing begins, readline takes over with full editing capabilities (including mid-line arrow navigation).
138137

139138
4. **Graceful Fallback**: If terminal control is unavailable, `.back` and `.cancel` commands always work as alternatives.
140139

141140
5. **Readline Integration**: Uses standard `readline` module for history and line editing, maintaining compatibility with existing infrastructure.
142141

143-
6. **Sequence Timing**: 100ms timeout distinguishes ESC alone from ESC as part of arrow sequence on Unix systems.
144-
145-
7. **Exception Handling**: Gracefully handles EOFError (Ctrl+D) and KeyboardInterrupt (Ctrl+C) for consistent cancel behavior.
142+
6. **Exception Handling**: Gracefully handles EOFError (Ctrl+D) for consistent cancel behavior.
146143

147-
8. **Empty Line Validation**: First line cannot be empty - prompts user to enter content or cancel.
144+
7. **Empty Line Validation**: First line cannot be empty - prompts user to enter content or cancel.
148145

149-
9. **Zero Dependencies**: Uses only Python standard library modules (`termios`, `tty`, `select` for Unix; `msvcrt` for Windows).
146+
8. **Zero Dependencies**: Uses only Python standard library modules (`termios`, `tty`, `select` for Unix; `msvcrt` for Windows).
150147

151148
## Usage Examples
152149

@@ -155,8 +152,8 @@ The multi-line editor detects special keys at the start of each line:
155152
You: \\
156153
Multi-line mode:
157154
• Empty line to submit
158-
• .cancel to cancel
159-
• .back to edit previous line
155+
Ctrl+D or .cancel to cancel
156+
↑ or .back to edit previous line
160157
1│ Here is a multi-line
161158
2│ code example:
162159
3│ def hello():
@@ -191,13 +188,13 @@ You: \\
191188
✓ 2 lines captured
192189
```
193190

194-
### Cancelling Input (ESC Key)
191+
### Cancelling Input (Ctrl+D)
195192
```
196193
You: \\
197194
1│ Started typing but
198195
2│ changed my mind
199-
3│ [press ESC]
200-
✗ Multi-line input cancelled (ESC)
196+
3│ [press Ctrl+D]
197+
✗ Multi-line input cancelled (Ctrl+D)
201198
```
202199

203200
### Cancelling Input (.cancel Command)
@@ -223,9 +220,7 @@ def hello():
223220
Comprehensive test suite with 13 test cases covering:
224221
- ✅ Basic submission
225222
- ✅ Cancel via `.cancel` command
226-
- ✅ Cancel via ESC key
227223
- ✅ Cancel via Ctrl+D (EOFError)
228-
- ✅ Cancel via Ctrl+C (KeyboardInterrupt)
229224
-`.back` command functionality
230225
-`.back` on empty lines
231226
- ✅ Up arrow key functionality

src/basic_agent_chat_loop/chat_loop.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- Command history with readline (↑↓ to navigate, saved to ~/.chat_history)
1111
- Agent logs with rotation and secure permissions (0600) in ~/.chat_loop_logs/
1212
- Multi-line input support (type \\\\ to enter multi-line mode)
13-
- ESC to cancel, ↑ arrow to edit previous line
13+
- Ctrl+D to cancel, ↑ arrow to edit previous line
1414
- Saves full block to history for later recall
1515
- Token tracking and cost estimation per query and session
1616
- Prompt templates from ~/.prompts/ with variable substitution
@@ -758,18 +758,17 @@ async def get_multiline_input(self) -> str:
758758
759759
Features:
760760
- Empty line submits
761-
- ESC key or .cancel to cancel input
761+
- Ctrl+D or .cancel to cancel input
762762
- Up arrow or .back to edit previous line
763763
- Saves to history as single entry
764764
"""
765765
lines: list[str] = []
766766
print(Colors.system("Multi-line mode:"))
767767
print(Colors.system(" • Empty line to submit"))
768+
print(Colors.system(" • Ctrl+D or .cancel to cancel"))
768769
if ESC_KEY_SUPPORT:
769-
print(Colors.system(" • ESC or .cancel to cancel"))
770770
print(Colors.system(" • ↑ or .back to edit previous line"))
771771
else:
772-
print(Colors.system(" • .cancel to cancel"))
773772
print(Colors.system(" • .back to edit previous line"))
774773

775774
while True:

src/basic_agent_chat_loop/components/display_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def display_banner(self):
112112
print(" ↑↓ - Navigate command history")
113113
print(" Enter - Submit single line")
114114
print(" \\\\ - Start multi-line input")
115-
print(" (empty line submits, ESC cancels, ↑ edits previous line)")
115+
print(" (empty line submits, Ctrl+D cancels, ↑ edits previous line)")
116116
if self.use_rich:
117117
print(" Rich - Enhanced markdown rendering with syntax highlighting")
118118

@@ -155,7 +155,7 @@ def display_help(self):
155155
print("Multi-line Input:")
156156
print(" Type \\\\ to start multi-line mode")
157157
print(" Press Enter on empty line to submit")
158-
print(" Press ESC to cancel (or type .cancel, Ctrl+C/Ctrl+D)")
158+
print(" Press Ctrl+D to cancel (or type .cancel)")
159159
print(" Press ↑ at start of line to edit previous line (or type .back)")
160160
print(" Full block saved to history - use ↑ at main prompt to recall")
161161
print(" Great for code blocks and long prompts")

0 commit comments

Comments
 (0)