You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
Copy file name to clipboardExpand all lines: docs/MULTILINE_EDITOR_ENHANCEMENTS.md
+30-35Lines changed: 30 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,23 +3,21 @@
3
3
## Overview
4
4
5
5
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
7
7
2.**Up arrow editing** - press ↑ at start of line to edit previous line
8
8
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
10
10
11
11
## Features Implemented
12
12
13
13
### 1. Cancel Options
14
14
15
-
Users can now cancel multi-line input in four ways:
15
+
Users can now cancel multi-line input in two ways:
16
16
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)
18
18
-**`.cancel` command**: Type `.cancel` at any prompt to cancel
19
-
-**Ctrl+C**: Keyboard interrupt to cancel
20
-
-**Ctrl+D**: EOF signal to cancel
21
19
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.
23
21
24
22
### 2. Previous Line Editing with Up Arrow
25
23
@@ -88,36 +86,37 @@ Multi-line mode:
88
86
89
87
The multi-line editor detects special keys at the start of each line:
90
88
91
-
**ESC Key** - Instant cancellation:
92
-
```
93
-
1│ [press ESC]
94
-
✗ Multi-line input cancelled (ESC)
95
-
```
96
-
97
89
**Up Arrow** - Edit previous line:
98
90
```
99
91
1│ line one
100
92
2│ [press ↑]
101
93
↑ Editing line 1...
102
94
```
103
95
96
+
**Ctrl+D** - Cancel input:
97
+
```
98
+
1│ started typing
99
+
2│ [press Ctrl+D]
100
+
✗ Multi-line input cancelled (Ctrl+D)
101
+
```
102
+
104
103
**Implementation Details**:
105
-
- Uses platform-specific terminal control:
104
+
- Uses platform-specific terminal control for up arrow detection:
106
105
- Unix/Linux/Mac: `termios` and `tty` for raw input, `select` for sequence detection
107
106
- 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
110
108
- Up arrow: Escape sequence `\x1b[A` on Unix, `\xe0H` on Windows
109
+
- Ctrl+D: Standard EOF signal handled by Python's EOFError exception
111
110
- Falls back gracefully to `.cancel` and `.back` commands if detection unavailable
112
111
- Zero dependencies - uses Python standard library only
113
112
114
113
**How it works**:
115
114
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
121
120
122
121
## Implementation Details
123
122
@@ -132,21 +131,19 @@ The multi-line editor detects special keys at the start of each line:
132
131
133
132
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.
134
133
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.
136
135
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).
138
137
139
138
4.**Graceful Fallback**: If terminal control is unavailable, `.back` and `.cancel` commands always work as alternatives.
140
139
141
140
5.**Readline Integration**: Uses standard `readline` module for history and line editing, maintaining compatibility with existing infrastructure.
142
141
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.
146
143
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.
148
145
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).
150
147
151
148
## Usage Examples
152
149
@@ -155,8 +152,8 @@ The multi-line editor detects special keys at the start of each line:
155
152
You: \\
156
153
Multi-line mode:
157
154
• 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
160
157
1│ Here is a multi-line
161
158
2│ code example:
162
159
3│ def hello():
@@ -191,13 +188,13 @@ You: \\
191
188
✓ 2 lines captured
192
189
```
193
190
194
-
### Cancelling Input (ESC Key)
191
+
### Cancelling Input (Ctrl+D)
195
192
```
196
193
You: \\
197
194
1│ Started typing but
198
195
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)
201
198
```
202
199
203
200
### Cancelling Input (.cancel Command)
@@ -223,9 +220,7 @@ def hello():
223
220
Comprehensive test suite with 13 test cases covering:
0 commit comments