Skip to content

Commit 68e11ca

Browse files
committed
Avoid resizing console during a lot of VT commands are issued
ReadConsoleInput() API might report resize event suddenly while a lot of VT commands are issued. So resize request to TTY Resizer should be issued after all of events are processed at least.
1 parent c237820 commit 68e11ca

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

SimpleCom/SerialConnection.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ bool SimpleCom::SerialConnection::StdInRedirector(const HANDLE hSerial, const HA
212212

213213
try {
214214
HANDLE waiters[] = { _hStdIn, hTermEvent };
215+
COORD newConsoleSize;
216+
bool isConsoleSizeUpdated = false;
217+
215218
while (true) {
216219
DWORD result = WaitForMultipleObjects(sizeof(waiters) / sizeof(HANDLE), waiters, FALSE, INFINITE);
217220
if (result == WAIT_OBJECT_0) { // hStdIn
@@ -241,9 +244,18 @@ bool SimpleCom::SerialConnection::StdInRedirector(const HANDLE hSerial, const HA
241244
ProcessKeyEvents(inputs[idx].Event.KeyEvent, writer);
242245
}
243246
else if ((inputs[idx].EventType == WINDOW_BUFFER_SIZE_EVENT) && _useTTYResizer) {
244-
char buf[RINGBUF_SZ];
245-
int len = snprintf(buf, sizeof(buf), "%c%d" RESIZER_SEPARATOR "%d%c", RESIZER_START_MARKER, inputs[idx].Event.WindowBufferSizeEvent.dwSize.Y, inputs[idx].Event.WindowBufferSizeEvent.dwSize.X, RESIZER_END_MARKER);
246-
writer.PutData(buf, len);
247+
CopyMemory(&newConsoleSize, &inputs[idx].Event.WindowBufferSizeEvent, sizeof(COORD));
248+
isConsoleSizeUpdated = true;
249+
}
250+
251+
if (isConsoleSizeUpdated) {
252+
DWORD numOfEvents;
253+
if (GetNumberOfConsoleInputEvents(_hStdIn, &numOfEvents) && (numOfEvents == 0)) {
254+
char buf[RINGBUF_SZ];
255+
int len = snprintf(buf, sizeof(buf), "%c%d" RESIZER_SEPARATOR "%d%c", RESIZER_START_MARKER, newConsoleSize.Y, newConsoleSize.X, RESIZER_END_MARKER);
256+
writer.PutData(buf, len);
257+
isConsoleSizeUpdated = false;
258+
}
247259
}
248260
}
249261

tty-resizer/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,5 @@ Some strings for resizing might be shown on your serial console in earlier phase
105105
You should wait few seconds if you start tty-resizer from `tty-resizer.service` when you encounter this problem.
106106

107107
This might be caused that `ioctl` to TTY is failed. So `tty-resizer.service` in this source would restart when the issue happens to avoid it. Then it will work fine.
108+
109+
And also TTY Resizer wouldn't work file with full-screen application like Vim. Noisy chars (for Vim) might be input, and TTY Resizer cannot set resized console size.

0 commit comments

Comments
 (0)