I am working on embedded system using C
and linux
. User can connect to the device via SSH or a console serial cable. He can do this through PuTTY or Tera Term. My question is, after he is connected, how can I know his window's width? I have tried different approaches, they work if I simulate my system on a linux pc, but none of them work on the device:
ioctl()
struct winsize ws;
ioctl(..., TIOCGWINSZ, &ws);
This method works on pc, but it always returns 0 on the device.
tgetnum()
setupterm((char *)0, 1, (int *)0);
CGR_INT columns = tgetnum("co");
This method works on pc, but it always returns 80x24 on the device.
getmaxyx()
CGR_INT xdim;
CGR_INT ydim;
initscr();
refresh();
getmaxyx(stdscr, ydim, xdim);
This method works on pc, but it always returns 0 on the device
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…