Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ncurses terminal size

Tags:

c

ncurses

How do I find the terminal width & height of an ncurses application?

like image 858
DylanJ Avatar asked Nov 28 '09 08:11

DylanJ


3 Answers

void getmaxyx(WINDOW *win, int y, int x); i believe...

also, this may help...

Getting terminal width in C?

like image 50
mtvee Avatar answered Oct 17 '22 12:10

mtvee


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:

like image 16
Thomas Dickey Avatar answered Oct 17 '22 12:10

Thomas Dickey


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);
like image 3
qknight Avatar answered Oct 17 '22 12:10

qknight