-
Notifications
You must be signed in to change notification settings - Fork 335
terminal:handle zero dimensions from tcgetwinsize #1007
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
This commit adds default (ANSI terminal) values in case when 'tcgetwinsize' returns 'Ok' with columns or rows equal to 0. In practice, Ok((0,0)) often results in crashes (frequently) or rendering issues (more rarely) when running applications over a serial line. Meanwhile, applications like 'vi' and 'vim' work well in the same environment. The reason is they rely on multiple sources to determine the terminal size: tcgetwinsize, environment variables, terminfo, fallbacks to defaults, and more. They use an enhanced and layered mechanism for detecting the terminal dimensions. Since implementing such a mechanism could take quite some time, I'd prefer to provide only default values for now: - they can serve as a starting point for discussing the problem and solutions - they can help prevent crashes and issues in existing applications - they are simple and predictable Some links on issues / PRs caused by Ok with zero columns/rows: - Helix - helix-editor/helix#14050 - Helix - helix-editor/helix#14101 - aichat - sigoden/aichat#1366 Some links on vi / vim: - getting terminal size in vim: https://github.com/vim/vim/blob/b88f9e4a04ce9fb70abb7cdae17688aa4f49c8c9/src/os_unix.c#L4299 - using defaults in vi: https://github.com/mirror/busybox/blob/371fe9f71d445d18be28c82a2a6d82115c8af19d/editors/vi.c#L4814
|
I think |
|
Agree. Returning |
|
It seems we lose the zero-dimensions checks here: #790 @benjajaja Hi! I understand it might be difficult to remember changes from two years ago 😄 But could you please remind me why the zero-value checks were dropped? I see some discussions here. But I didn't find the answer @markus-bauer Hi! Feel free to join the conversation 😄 |
|
@alexs-sh mhh, hard to reconstruct, but I think the thought probably was: the new On another note, I am not using |
|
@benjajaja Thanks
|
|
Seems the hardest part is that three levels may be responsible for handling it.
|
|
@alexs-sh I think it's straightforward: just return Would also be worth looking into what |
|
@benjajaja OK, thanks. For me,
Here is a brief example in C. Running the app in a "regular" terminal session will provide correct cols/rows values. However, running the example over a serial connection often results in (0,0) without an explicit error. #include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <pty.h>
int main(int argv, const char *argc[]) {
const char *file_name = (argv > 1) ? argc[1] : "/dev/tty";
const int file = open(file_name, O_RDWR);
printf("Open '%s' with result:%d\n", file_name, file);
struct winsize window_size;
const int result = ioctl(file, TIOCGWINSZ, &window_size);
printf("Read terminal size with result:%d\n", result);
printf("Errno:%d\n", errno);
printf("Cols:%d\n", window_size.ws_col);
printf("Rows:%d\n", window_size.ws_row);
return 0;
}When I run the example in a "regular" session (SSH, desktop), I see the valid sizes:
Running over serial (Qemu, RPI, Orange,...) provides zeroes without an explicit error.
|
|
Closing in favor of #1011 |




Hello,
This PR adds default (ANSI terminal) values in case when
tcgetwinsizereturnsOkwith columns or rows equal to 0. In practice, Ok((0,0)) often results in crashes (frequently) or rendering issues (more rarely) when running applications over a serial line.Meanwhile, applications like
viandvimwork well in the same environment. The reason is they rely on multiple sources to determine the terminal size: tcgetwinsize, environment variables, terminfo, fallbacks to defaults, and more. They use an enhanced and layered mechanism for detecting the terminal dimensions.Since implementing such a mechanism could take quite some time, I'd prefer to provide only default values for now:
Some links on issues / PRs caused by Ok with zero columns/rows:
Some links on vi / vim:
Note
This PR is mostly to demonstrate the problem, provide a quick (though likely not perfect) workaround, and help us find a correct and acceptable solution for everyone. It seems we should be careful here, as this kind of change could affect existing applications.
Example
A small proof. Helix before the change:
Helix with the change:

Please let me know if any additional info, test, information are needed.
Thank you