[英]Why do I can't get window size in Linux C program while I'm using minicom?
I have some board with Linux on it.我有一些带有 Linux 的板子。 I need to get window size in program.我需要在程序中获取窗口大小。 User can be connected to the board by minicom
or ssh
.用户可以通过minicom
或ssh
连接到开发板。 When I run my program while I'm using ssh
all OK, I can get terminal window size.当我在使用ssh
时运行我的程序一切正常,我可以获得终端窗口大小。 But when I run it while I'm using minicom
I get only zeroes.但是当我在使用minicom
时运行它时,我只得到零。 Why does it happens and how can I get a terminal window size in both cases?为什么会发生这种情况以及如何在两种情况下获得终端窗口大小?
Here is my code:这是我的代码:
struct winsize win;
ioctl(STDIN_FILENO, TIOCGWINSZ, &win);
printf("lines %d\n", win.ws_row);
printf("columns %d\n", win.ws_col);
As noted by @Ruslan, one of the answers to How to get terminal window width?正如@Ruslan 所指出的, 如何获得终端窗口宽度的答案之一? mentions that the usual way to get the screensize via a system call does not work over a serial line.提到通过系统调用获取屏幕大小的常用方法不适用于串行线路。
If minicom
supported the VT100 cursor-position report , then you could use resize
on the remote shell command-line to set the size.如果minicom
支持 VT100 cursor-position report ,那么您可以在远程 shell 命令行上使用resize
来设置大小。 resize
uses the cursor-position report to determine the actual size of the screen, prints the result and (the point of this question) updates the terminal settings which tell other applications what the screen size is. resize
使用光标位置报告来确定屏幕的实际大小,打印结果并(这个问题的重点)更新终端设置,告诉其他应用程序屏幕大小是什么。 That only lasts for the current connection.这仅适用于当前连接。 You can see the effect using the stty
command.您可以使用stty
命令查看效果。 In this example, my window is 40x80:在这个例子中,我的窗口是 40x80:
$ resize;stty -a
set noglob;
setenv COLUMNS '80';
setenv LINES '40';
unset noglob;
speed 38400 baud; rows 40; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany -imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke -flusho -extproc
The question is unclear (there are several copies of minicom), at least the Debian source for it seems to support that (look for 'n'
as a start).问题不清楚(有几个 minicom 副本),至少它的Debian 源代码似乎支持这一点(以'n'
作为开头)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.