Problem
When running a chapter's code.py and entering a prompt longer than the terminal width, the wrapped text can visually overwrite the previous line. The submitted input remains intact; only the terminal rendering is corrupted.
Reproduction
- Run
python s01_agent_loop/code.py in a terminal using GNU Readline.
- Type a prompt long enough to wrap onto a second visual line.
- Observe that Readline redraws the wrapped input at the wrong cursor position, hiding part of the first line.
Cause
The colored prompt passed to input() contains raw ANSI escape sequences:
query = input("\033[36ms01 >> \033[0m")
These sequences do not occupy terminal columns, but Readline includes them when calculating the visible prompt width unless they are delimited as non-printing spans.
Proposed fix
Wrap each ANSI sequence with Readline's \001 and \002 markers:
query = input("\001\033[36m\002s01 >> \001\033[0m\002")
The same prompt pattern is present in the current course files from s01 through s12, so the fix should be applied consistently across those chapters.
I reproduced this while working through the course and can submit a focused PR. I used an AI coding assistant to help diagnose the cursor-width issue and prepare the proposed change; I reviewed and tested the solution.
Problem
When running a chapter's
code.pyand entering a prompt longer than the terminal width, the wrapped text can visually overwrite the previous line. The submitted input remains intact; only the terminal rendering is corrupted.Reproduction
python s01_agent_loop/code.pyin a terminal using GNU Readline.Cause
The colored prompt passed to
input()contains raw ANSI escape sequences:These sequences do not occupy terminal columns, but Readline includes them when calculating the visible prompt width unless they are delimited as non-printing spans.
Proposed fix
Wrap each ANSI sequence with Readline's
\001and\002markers:The same prompt pattern is present in the current course files from s01 through s12, so the fix should be applied consistently across those chapters.
I reproduced this while working through the course and can submit a focused PR. I used an AI coding assistant to help diagnose the cursor-width issue and prepare the proposed change; I reviewed and tested the solution.