简体   繁体   中英

ncurses terminal size

如何找到ncurses应用程序的终端宽度和高度?

ncurses applications normally handle SIGWINCH and use the ioctl with TIOCGWINSZ to obtain the system's notion of the screensize. That may be overridden by the environment variables LINES and COLUMNS (see use_env ).

Given that, the ncurses global variables LINES and COLS are updated as a side-effect when wgetch returns KEY_RESIZE (in response to a SIGWINCH ) to give the size of stdscr (the standard screen representing the whole terminal).

You can of course use getmaxx , getmaxy and getmaxyx to get one or both of the limits for the x- and y-ordinates of a window. Only the last is standard (and portable).

Further reading:

i'm using this code:

struct winsize size;
if (ioctl(0, TIOCGWINSZ, (char *) &size) < 0)
    printf("TIOCGWINSZ error");
printf("%d rows, %d columns\n", size.ws_row, size.ws_col);

那么使用SCR_HSCR_W呢?

the variables COLS, LINES are initialized to the screen sizes after initscr().

Source: NCURSES Programming HOWTO

I'm not sure if they get updated on resize though.

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