Skip to content
Snippets Groups Projects
Commit 2762f323 authored by stijn's avatar stijn Committed by Damien George
Browse files

windows: Fix line wrapping behaviour on the REPL.

This enables going back to previous wrapped lines using backspace or left
arrow: instead of just sticking to the beginning of a line, the cursor will
move a line up.
parent 4f447787
Branches
No related tags found
No related merge requests found
...@@ -106,12 +106,23 @@ void mp_hal_set_interrupt_char(char c) { ...@@ -106,12 +106,23 @@ void mp_hal_set_interrupt_char(char c) {
} }
void mp_hal_move_cursor_back(uint pos) { void mp_hal_move_cursor_back(uint pos) {
if (!pos) {
return;
}
assure_conout_handle(); assure_conout_handle();
CONSOLE_SCREEN_BUFFER_INFO info; CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(con_out, &info); GetConsoleScreenBufferInfo(con_out, &info);
info.dwCursorPosition.X -= (short)pos; info.dwCursorPosition.X -= (short)pos;
if (info.dwCursorPosition.X < 0) { // Move up a line if needed.
while (info.dwCursorPosition.X < 0) {
info.dwCursorPosition.X = info.dwSize.X + info.dwCursorPosition.X;
info.dwCursorPosition.Y -= 1;
}
// Caller requested to move out of the screen. That's not possible so just clip,
// it's the caller's responsibility to not let this happen.
if (info.dwCursorPosition.Y < 0) {
info.dwCursorPosition.X = 0; info.dwCursorPosition.X = 0;
info.dwCursorPosition.Y = 0;
} }
SetConsoleCursorPosition(con_out, info.dwCursorPosition); SetConsoleCursorPosition(con_out, info.dwCursorPosition);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment