Merge #3048 'tui: resize terminal'

This commit is contained in:
Justin M. Keyes 2015-07-21 23:57:11 -04:00
commit 8cbe5265ef
3 changed files with 31 additions and 11 deletions

View File

@ -68,12 +68,16 @@
* They may have different values when the screen wasn't (re)allocated yet * They may have different values when the screen wasn't (re)allocated yet
* after setting Rows or Columns (e.g., when starting up). * after setting Rows or Columns (e.g., when starting up).
*/ */
#define DFLT_COLS 80 /* default value for 'columns' */
#define DFLT_ROWS 24 /* default value for 'lines' */
EXTERN long Rows /* nr of rows in the screen */ EXTERN long Rows /* nr of rows in the screen */
#ifdef DO_INIT #ifdef DO_INIT
= 24L = DFLT_ROWS
#endif #endif
; ;
EXTERN long Columns INIT(= 80); /* nr of columns in the screen */ EXTERN long Columns INIT(= DFLT_COLS); /* nr of columns in the screen */
/* /*
* The characters and attributes cached for the screen. * The characters and attributes cached for the screen.

View File

@ -537,7 +537,7 @@ static vimoption_T
{(char_u *)"", (char_u *)0L} SCRIPTID_INIT}, {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
{"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR, {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
(char_u *)&Columns, PV_NONE, (char_u *)&Columns, PV_NONE,
{(char_u *)80L, (char_u *)0L} SCRIPTID_INIT}, {(char_u *)DFLT_COLS, (char_u *)0L} SCRIPTID_INIT},
{"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP| {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP|
P_CURSWANT, P_CURSWANT,
(char_u *)&p_com, PV_COM, (char_u *)&p_com, PV_COM,
@ -1025,7 +1025,7 @@ static vimoption_T
{"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR, {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
(char_u *)&Rows, PV_NONE, (char_u *)&Rows, PV_NONE,
{ {
(char_u *)24L, (char_u *)DFLT_ROWS,
(char_u *)0L (char_u *)0L
} SCRIPTID_INIT}, } SCRIPTID_INIT},
{"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR, {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,

View File

@ -1,6 +1,7 @@
#include <assert.h> #include <assert.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <limits.h>
#include <uv.h> #include <uv.h>
#include <unibilium.h> #include <unibilium.h>
@ -350,6 +351,11 @@ static void tui_resize(UI *ui, int width, int height)
data->scroll_region.left = 0; data->scroll_region.left = 0;
data->scroll_region.right = width - 1; data->scroll_region.right = width - 1;
data->row = data->col = 0; data->row = data->col = 0;
// try to resize the terminal window
char r[16]; // enough for 9999x9999
snprintf(r, sizeof(r), "\x1b[8;%d;%dt", height, width);
out(ui, r, strlen(r));
} }
static void tui_clear(UI *ui) static void tui_clear(UI *ui)
@ -641,12 +647,22 @@ static void update_size(UI *ui)
{ {
TUIData *data = ui->data; TUIData *data = ui->data;
int width = 0, height = 0; int width = 0, height = 0;
// 1 - try from a system call(ioctl/TIOCGWINSZ on unix)
// 1 - look for non-default 'columns' and 'lines' options during startup
if (starting != 0 && (Columns != DFLT_COLS || Rows != DFLT_ROWS)) {
assert(Columns >= INT_MIN && Columns <= INT_MAX);
assert(Rows >= INT_MIN && Rows <= INT_MAX);
width = (int)Columns;
height = (int)Rows;
goto end;
}
// 2 - try from a system call(ioctl/TIOCGWINSZ on unix)
if (!uv_tty_get_winsize(&data->output_handle, &width, &height)) { if (!uv_tty_get_winsize(&data->output_handle, &width, &height)) {
goto end; goto end;
} }
// 2 - use $LINES/$COLUMNS if available // 3 - use $LINES/$COLUMNS if available
const char *val; const char *val;
int advance; int advance;
if ((val = os_getenv("LINES")) if ((val = os_getenv("LINES"))
@ -656,15 +672,15 @@ static void update_size(UI *ui)
goto end; goto end;
} }
// 3- read from terminfo if available // 4 - read from terminfo if available
height = unibi_get_num(data->ut, unibi_lines); height = unibi_get_num(data->ut, unibi_lines);
width = unibi_get_num(data->ut, unibi_columns); width = unibi_get_num(data->ut, unibi_columns);
end: end:
if (width <= 0 || height <= 0) { if (width <= 0 || height <= 0) {
// use a default of 80x24 // use the defaults
width = 80; width = DFLT_COLS;
height = 24; height = DFLT_ROWS;
} }
ui->width = width; ui->width = width;