Repository navigation
Fixed the edit-mode selector with Claude Code 2.1.x #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
oleg68
merged 4 commits into
nbplugins:main
from
oleg68:bugfix/edit-mode-selector-cycling
Oct 18, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c109b49
Fix mode cycling mid-prompt
Rizky92 3828e9a
Addressed review comments on the edit-mode selector fix
610b00f
Fixed a queued edit-mode request being dropped when the active switch…
3e72112
Fixed a repeated edit-mode request being dropped after a failed switch
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Capture the rendered footer (bottom screen lines) of the Claude Code TUI while | ||
| cycling edit modes with Shift+Tab, both when idle and while Claude is working. | ||
|
|
||
| Answers: which line is the bottom-most non-blank one in each mode, and does the | ||
| mode indicator always live on it? ScreenContentDetector.detectEditMode() only | ||
| inspects that single line, so anything rendered below the mode indicator makes | ||
| the mode undetectable. | ||
|
|
||
| Cross-platform: uses pywinpty on Windows, the stdlib pty elsewhere, and pyte to | ||
| render the byte stream into a screen grid (the same view JediTerm gives the plugin). | ||
|
|
||
| pip install pyte pywinpty # pywinpty only on Windows | ||
| python test_edit_mode_footer.py [--work] | ||
| """ | ||
|
|
||
| import os | ||
| import shutil | ||
| import sys | ||
| import tempfile | ||
| import threading | ||
| import time | ||
|
|
||
| import pyte | ||
|
|
||
| COLS, ROWS = 120, 40 | ||
| SHIFT_TAB = '\x1b[Z' | ||
|
|
||
|
|
||
| class Term: | ||
| def __init__(self, argv, cwd): | ||
| env = dict(os.environ) | ||
| env.pop('CLAUDECODE', None) | ||
| env.pop('CLAUDE_CODE_ENTRYPOINT', None) | ||
| env['TERM'] = 'xterm-256color' | ||
| self.screen = pyte.Screen(COLS, ROWS) | ||
| self.stream = pyte.Stream(self.screen) | ||
| self.lock = threading.Lock() | ||
| if os.name == 'nt': | ||
| from winpty import PtyProcess | ||
| self.proc = PtyProcess.spawn(argv, cwd=cwd, env=env, dimensions=(ROWS, COLS)) | ||
| self._read = lambda: self.proc.read(4096) | ||
| self._write = self.proc.write | ||
| else: | ||
| import pty | ||
| import subprocess | ||
| master, slave = pty.openpty() | ||
| import fcntl, struct, termios | ||
| fcntl.ioctl(slave, termios.TIOCSWINSZ, struct.pack('HHHH', ROWS, COLS, 0, 0)) | ||
| self.proc = subprocess.Popen(argv, cwd=cwd, env=env, stdin=slave, | ||
| stdout=slave, stderr=slave, close_fds=True) | ||
| self._read = lambda: os.read(master, 4096).decode('utf-8', 'replace') | ||
| self._write = lambda s: os.write(master, s.encode()) | ||
| threading.Thread(target=self._pump, daemon=True).start() | ||
|
|
||
| def _pump(self): | ||
| while True: | ||
| try: | ||
| data = self._read() | ||
| except Exception: | ||
| return | ||
| if not data: | ||
| time.sleep(0.01) | ||
| continue | ||
| with self.lock: | ||
| self.stream.feed(data) | ||
|
|
||
| def write(self, s): | ||
| self._write(s) | ||
|
|
||
| def lines(self): | ||
| with self.lock: | ||
| return [l.rstrip() for l in self.screen.display] | ||
|
|
||
| def bottom(self, n=4): | ||
| nb = [l for l in self.lines() if l.strip()] | ||
| return nb[-n:] | ||
|
|
||
| def wait_for(self, text, timeout=30): | ||
| end = time.time() + timeout | ||
| while time.time() < end: | ||
| if any(text in l for l in self.lines()): | ||
| return True | ||
| time.sleep(0.1) | ||
| return False | ||
|
|
||
| def close(self): | ||
| try: | ||
| if os.name == 'nt': | ||
| self.proc.terminate(force=True) | ||
| else: | ||
| self.proc.kill() | ||
| except Exception: | ||
| pass | ||
|
|
||
|
|
||
| def dump(term, label): | ||
| print(f'--- {label}') | ||
| for l in term.bottom(): | ||
| print(' |' + l) | ||
|
|
||
|
|
||
| def main(): | ||
| work = '--work' in sys.argv | ||
| claude = shutil.which('claude') | ||
| if claude is None: | ||
| sys.exit('claude not found on PATH') | ||
| cwd = tempfile.mkdtemp(prefix='cc-mode-footer-') | ||
| term = Term([claude], cwd) | ||
| try: | ||
| if term.wait_for('Yes, I trust', 15): | ||
| time.sleep(1) | ||
| term.write('\x1b[B') # default is "No, exit" — move to "Yes" | ||
| time.sleep(0.5) | ||
| term.write('\r') | ||
| if not term.wait_for('shift+tab', 30) and not term.wait_for('for shortcuts', 5): | ||
| dump(term, 'startup (no footer found)') | ||
| time.sleep(2) | ||
| dump(term, 'idle initial') | ||
| for i in range(5): | ||
| term.write(SHIFT_TAB) | ||
| time.sleep(1.2) | ||
| dump(term, f'idle after shift+tab #{i + 1}') | ||
|
|
||
| if work: | ||
| term.write('Count slowly from 1 to 40, one number per line, no tools.') | ||
| time.sleep(0.5) | ||
| term.write('\r') | ||
| time.sleep(2.5) | ||
| dump(term, 'working initial') | ||
| for i in range(5): | ||
| term.write(SHIFT_TAB) | ||
| time.sleep(1.2) | ||
| dump(term, f'working after shift+tab #{i + 1}') | ||
| term.wait_for('40', 60) | ||
| time.sleep(3) | ||
| dump(term, 'idle after response') | ||
| finally: | ||
| term.close() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.