1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

Get the terminal size at startup with ioctl() and use it. Fixes at least

NetBSD.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2616 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2002-03-14 23:46:48 +00:00 committed by cras
parent 85a1b122cd
commit 6a89217d6a
3 changed files with 37 additions and 22 deletions

View File

@ -78,6 +78,7 @@ static int redraw_timeout(void)
int term_init(void) int term_init(void)
{ {
struct sigaction act; struct sigaction act;
int width, height;
last_fg = last_bg = -1; last_fg = last_bg = -1;
last_attrs = 0; last_attrs = 0;
@ -89,6 +90,11 @@ int term_init(void)
if (current_term == NULL) if (current_term == NULL)
return FALSE; return FALSE;
if (term_get_size(&width, &height)) {
current_term->width = width;
current_term->height = height;
}
/* grab CONT signal */ /* grab CONT signal */
sigemptyset(&act.sa_mask); sigemptyset(&act.sa_mask);
act.sa_flags = 0; act.sa_flags = 0;

View File

@ -47,12 +47,31 @@ int term_type;
static int force_colors; static int force_colors;
static int resize_dirty; static int resize_dirty;
/* Resize the terminal if needed */ int term_get_size(int *width, int *height)
void term_resize_dirty(void)
{ {
#ifdef TIOCGWINSZ #ifdef TIOCGWINSZ
struct winsize ws; struct winsize ws;
/* Get new window size */
if (ioctl(0, TIOCGWINSZ, &ws) < 0)
return FALSE;
*width = ws.ws_col;
*height = ws.ws_row;
if (*width < MIN_SCREEN_WIDTH)
*width = MIN_SCREEN_WIDTH;
if (*height < 1)
*height = 1;
return TRUE;
#else
return FALSE;
#endif #endif
}
/* Resize the terminal if needed */
void term_resize_dirty(void)
{
int width, height; int width, height;
if (!resize_dirty) if (!resize_dirty)
@ -60,28 +79,15 @@ void term_resize_dirty(void)
resize_dirty = FALSE; resize_dirty = FALSE;
#ifdef TIOCGWINSZ if (!term_get_size(&width, &height))
/* Get new window size */
if (ioctl(0, TIOCGWINSZ, &ws) < 0)
return;
if (ws.ws_row == term_height && ws.ws_col == term_width) {
/* Same size, abort. */
return;
}
if (ws.ws_col < MIN_SCREEN_WIDTH)
ws.ws_col = MIN_SCREEN_WIDTH;
width = ws.ws_col;
height = ws.ws_row;
#else
width = height = -1; width = height = -1;
#endif
if (height != term_height || width != term_width) {
term_resize(width, height); term_resize(width, height);
mainwindows_resize(term_width, term_height); mainwindows_resize(term_width, term_height);
term_resize_final(width, height); term_resize_final(width, height);
} }
}
#ifdef SIGWINCH #ifdef SIGWINCH
static void sig_winch(int p) static void sig_winch(int p)

View File

@ -30,6 +30,9 @@ extern int term_use_colors, term_type, term_detached;
int term_init(void); int term_init(void);
void term_deinit(void); void term_deinit(void);
/* Gets the current terminal size, returns TRUE if ok. */
int term_get_size(int *width, int *height);
/* Resize terminal - if width or height is negative, /* Resize terminal - if width or height is negative,
the new size is unknown and should be figured out somehow */ the new size is unknown and should be figured out somehow */
void term_resize(int width, int height); void term_resize(int width, int height);