Skip to content

Commit

Permalink
Work around WT issue in ReadConsoleOutputCharacterW.
Browse files Browse the repository at this point in the history
See issue #574.  An API in Windows Terminal behaves differently than in
legacy conhost.

1. It fails, but should succeed.
2. It fails, but returns that it succeeded.
3. It claims to have succeeded, but returns that the length was 0.

This detects the failure based on the 0 length and treats it as having
failed, despite the API claiming to have succeeded.

So, at least Clink and Lua scripts can be aware that it failed, instead
of thinking it succeeded.

Since Clink's Lua API strips trailing spaces, callers have no way to
deduce failure, since the returned string is empty, which is consistent
with a line that was full of spaces.
  • Loading branch information
chrisant996 committed Mar 14, 2024
1 parent ec90abb commit 46d0ea1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion clink/terminal/src/win_screen_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ bool win_screen_buffer::get_line_text(int32 line, str_base& out) const

COORD coord = { 0, short(line) };
DWORD len = 0;
if (!ReadConsoleOutputCharacterW(m_handle, m_chars, csbi.dwSize.X, coord, &len))
if (!ReadConsoleOutputCharacterW(m_handle, m_chars, csbi.dwSize.X, coord, &len) || !len)
return false;

while (len > 0 && iswspace(m_chars[len - 1]))
Expand Down

0 comments on commit 46d0ea1

Please sign in to comment.