简体   繁体   中英

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. I need to get window size in program. User can be connected to the board by minicom or ssh . When I run my program while I'm using ssh all OK, I can get terminal window size. But when I run it while I'm using minicom I get only zeroes. 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? 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. 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. That only lasts for the current connection. You can see the effect using the stty command. In this example, my window is 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM