-
Notifications
You must be signed in to change notification settings - Fork 14k
console: allow using arrow left/right, home/end keys and history mode #17836
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
Conversation
|
Thanks @ServeurpersoCom for testing & adding some improvements on windows! CC @ggerganov , this is a small feature but quite important for the UX - hope to get it merged soon! |
cd05610 to
77ca259
Compare
Xsn/cli arrow left right
|
FYI, I merged some more changes from @ServeurpersoCom to include history too (using up/down keys) |
|
pinging @ggerganov in case you missed the PR. I added a video to demo how it works with the current in long term, I think we can remove linenoise and use the |
ggerganov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on Mac, works as expected.
- Would be nice to add support for "Delete" if possible
- During chat, when I type a new message and hit "Up + Down" it forgets what I wrote - could be improved.
|
I'll add Delete/VK_DELETE support first, and test a temporary buffer for a modern bash-like history! |
|
@ServeurpersoCom do you want to add both Delete and Ctrl+Arrow support into this PR? Lmk which commit should I cherry-pick, thanks! |
|
Bash behavior : |
- Add KEY_CTRL_ARROW_LEFT and KEY_CTRL_ARROW_RIGHT codes - Windows: detect CTRL modifier via dwControlKeyState - Linux: parse ANSI sequences with modifier (1;5D/C) - Implement move_word_left/right with space-skipping logic - Refactor escape sequence parsing to accumulate params
I put our work back in this branch (rebased) |
- Windows: VK_DELETE detection - Linux: ESC[3~ sequence parsing - Forward character deletion with UTF-8 support
- Edit any history line during UP/DOWN navigation, edits persist - Pressing Enter appends edited version as new history entry - Original line stay untouched in their positions
|
Done |
…to xsn/cli_arrow_left_right
|
just tested the history function on windows and mac, works fine! |
|
@ggerganov could you test again to see if the 2 problems in your last comment are all resolved? Thanks! |
|
Looks like this behaviour changed in #17827, so not related to this PR. |
Yes I discovered that in #17824 too, the problem is that the My quick fix on the other PR is to directly use |
|
There was a race condition on the colors I fixed when adding the reasoning to llama-cli. The problem is the tight coupling to the log routine. Please see #16603 changes to console.h/cpp |

Fix #17828
Fix #17829
To test it, run
llama-cli, write some text (without sending it) and use left/right arrows to edit themEdit: Home/end keys and history support is allso added thanks to @ServeurpersoCom
Screen.Recording.2025-12-08.at.11.29.15.mov
Disclosure AI usage:
next_utf8_char_posis written by AI because I have no experience working with windows API. The rest is mostly written by me (minus some small auto-completion)