From 59d60463964483d3c656d92b5006060be19635ee Mon Sep 17 00:00:00 2001 From: SilasD Date: Tue, 3 Nov 2026 10:50:58 -0800 Subject: [PATCH] Console-windows: don't advance a line when input reaches last column by printing the line with a method that doesn't advance the cursor position, and by handling the cooked cursor appropriately when it is located at the last column. this also prevents the occasional flicker of the cursor at the beginning of the line whenever the line is updated. note that with this change to output(), it is now identical to blankout(). further work could involve merging the two. alternately, consider moving the creation of a line of spaces into blankout() where it belongs, and changing its function parameters accordingly. --- docs/changelog.txt | 1 + library/Console-windows.cpp | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index c2470dbe87..50098e4638 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -60,6 +60,7 @@ Template for new versions: ## New Features ## Fixes +- Core: Windows console editing will no longer move the cursor to the next line or scroll the screen when the length of the text being edited exceeds the screen width. ## Misc Improvements diff --git a/library/Console-windows.cpp b/library/Console-windows.cpp index bb6b1fc8fb..97178a8e2f 100644 --- a/library/Console-windows.cpp +++ b/library/Console-windows.cpp @@ -223,10 +223,7 @@ namespace DFHack { COORD pos = { (SHORT)x, (SHORT)y }; DWORD count = 0; - CONSOLE_SCREEN_BUFFER_INFO inf = { 0 }; - GetConsoleScreenBufferInfo(console_out, &inf); - SetConsoleCursorPosition(console_out, pos); - WriteConsoleA(console_out, str, len, &count, NULL); + WriteConsoleOutputCharacterA(console_out, str, len, pos, &count); } void prompt_refresh() @@ -237,9 +234,9 @@ namespace DFHack size_t len = raw_buffer.size(); int cooked_cursor = raw_cursor; - if (plen + cooked_cursor > cols) + if (plen + cooked_cursor > (cols-1)) { - int adj = std::min(plen + cooked_cursor - cols, len); + int adj = std::min(plen + cooked_cursor - (cols-1), len); buf += adj; len -= adj; cooked_cursor -= adj;