From 6048e95f33161420f9d863a2ce5ccf9464df2dba Mon Sep 17 00:00:00 2001 From: Felipe Morales Date: Sat, 18 Jul 2015 17:13:01 -0300 Subject: [PATCH 1/3] tui: send resize sequences to the terminal Neither setting the 'columns' and 'lines' options nor using the `:winsize` command resized the terminal window, which caused display glitches. Re: #2863 --- src/nvim/tui/tui.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 1deab23b05..c8565a1e5a 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -350,6 +350,11 @@ static void tui_resize(UI *ui, int width, int height) data->scroll_region.left = 0; data->scroll_region.right = width - 1; 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) From 5732340c203572715f3ef68d573f68a38447132c Mon Sep 17 00:00:00 2001 From: Felipe Morales Date: Sat, 18 Jul 2015 20:37:10 -0300 Subject: [PATCH 2/3] tui: respect the 'co' and 'lines' options on startup `nvim --cmd "set co=... lines="` didn't work as expected, and forced to set those options on VimEnter or afterwards. --- src/nvim/tui/tui.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index c8565a1e5a..ae9e70e2e0 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -646,12 +646,20 @@ static void update_size(UI *ui) { TUIData *data = ui->data; 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 && (Columns != 80 || Rows != 24)) { + 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)) { goto end; } - // 2 - use $LINES/$COLUMNS if available + // 3 - use $LINES/$COLUMNS if available const char *val; int advance; if ((val = os_getenv("LINES")) @@ -661,7 +669,7 @@ static void update_size(UI *ui) goto end; } - // 3- read from terminfo if available + // 4 - read from terminfo if available height = unibi_get_num(data->ut, unibi_lines); width = unibi_get_num(data->ut, unibi_columns); From a95a5ba8398193cfe0bd3e198a013447769b64ff Mon Sep 17 00:00:00 2001 From: Felipe Morales Date: Mon, 20 Jul 2015 21:30:42 -0300 Subject: [PATCH 3/3] options,tui: don't hardcode default terminal size also, include some checks. --- src/nvim/globals.h | 10 +++++++--- src/nvim/option.c | 4 ++-- src/nvim/tui/tui.c | 11 +++++++---- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/nvim/globals.h b/src/nvim/globals.h index c7164ef1f1..9c4f9e3642 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -59,7 +59,7 @@ /* Values for "starting" */ #define NO_SCREEN 2 /* no screen updating yet */ #define NO_BUFFERS 1 /* not all buffers loaded yet */ -/* 0 not starting anymore */ +/* 0 not starting anymore */ /* * Number of Rows and Columns in the screen. @@ -68,12 +68,16 @@ * They may have different values when the screen wasn't (re)allocated yet * 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 */ #ifdef DO_INIT - = 24L + = DFLT_ROWS #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. diff --git a/src/nvim/option.c b/src/nvim/option.c index e880e9aadd..94b935fe52 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -537,7 +537,7 @@ static vimoption_T {(char_u *)"", (char_u *)0L} SCRIPTID_INIT}, {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR, (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| P_CURSWANT, (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, (char_u *)&Rows, PV_NONE, { - (char_u *)24L, + (char_u *)DFLT_ROWS, (char_u *)0L } SCRIPTID_INIT}, {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR, diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index ae9e70e2e0..a1f56d2695 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -648,7 +649,9 @@ static void update_size(UI *ui) int width = 0, height = 0; // 1 - look for non-default 'columns' and 'lines' options during startup - if (starting && (Columns != 80 || Rows != 24)) { + 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; @@ -675,9 +678,9 @@ static void update_size(UI *ui) end: if (width <= 0 || height <= 0) { - // use a default of 80x24 - width = 80; - height = 24; + // use the defaults + width = DFLT_COLS; + height = DFLT_ROWS; } ui->width = width;