forked from aniani/vim
patch 8.0.0739: terminal resizing doesn't work well.
Problem: Terminal resizing doesn't work well. Solution: Resize the terminal to the Vim window and the other way around. Avoid mapping typed keys. Set the environment properly.
This commit is contained in:
@@ -4054,37 +4054,47 @@ mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc)
|
|||||||
|
|
||||||
#if !defined(USE_SYSTEM) || defined(FEAT_JOB_CHANNEL)
|
#if !defined(USE_SYSTEM) || defined(FEAT_JOB_CHANNEL)
|
||||||
static void
|
static void
|
||||||
set_child_environment(void)
|
set_child_environment(long rows, long columns, char *term)
|
||||||
{
|
{
|
||||||
# ifdef HAVE_SETENV
|
# ifdef HAVE_SETENV
|
||||||
char envbuf[50];
|
char envbuf[50];
|
||||||
# else
|
# else
|
||||||
|
static char envbuf_TERM[30];
|
||||||
static char envbuf_Rows[20];
|
static char envbuf_Rows[20];
|
||||||
|
static char envbuf_Lines[20];
|
||||||
static char envbuf_Columns[20];
|
static char envbuf_Columns[20];
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
/* Simulate to have a dumb terminal (for now) */
|
/* Simulate to have a dumb terminal (for now) */
|
||||||
# ifdef HAVE_SETENV
|
# ifdef HAVE_SETENV
|
||||||
setenv("TERM", "dumb", 1);
|
setenv("TERM", term, 1);
|
||||||
sprintf((char *)envbuf, "%ld", Rows);
|
sprintf((char *)envbuf, "%ld", rows);
|
||||||
setenv("ROWS", (char *)envbuf, 1);
|
setenv("ROWS", (char *)envbuf, 1);
|
||||||
sprintf((char *)envbuf, "%ld", Rows);
|
sprintf((char *)envbuf, "%ld", rows);
|
||||||
setenv("LINES", (char *)envbuf, 1);
|
setenv("LINES", (char *)envbuf, 1);
|
||||||
sprintf((char *)envbuf, "%ld", Columns);
|
sprintf((char *)envbuf, "%ld", columns);
|
||||||
setenv("COLUMNS", (char *)envbuf, 1);
|
setenv("COLUMNS", (char *)envbuf, 1);
|
||||||
# else
|
# else
|
||||||
/*
|
/*
|
||||||
* Putenv does not copy the string, it has to remain valid.
|
* Putenv does not copy the string, it has to remain valid.
|
||||||
* Use a static array to avoid losing allocated memory.
|
* Use a static array to avoid losing allocated memory.
|
||||||
*/
|
*/
|
||||||
putenv("TERM=dumb");
|
vim_snprintf(envbuf_Term, sizeof(envbuf_Term), "TERM=%s", term);
|
||||||
sprintf(envbuf_Rows, "ROWS=%ld", Rows);
|
putenv(envbuf_Term);
|
||||||
|
vim_snprintf(envbuf_Rows, sizeof(envbuf_Rows), "ROWS=%ld", rows);
|
||||||
putenv(envbuf_Rows);
|
putenv(envbuf_Rows);
|
||||||
sprintf(envbuf_Rows, "LINES=%ld", Rows);
|
vim_snprintf(envbuf_Lines, sizeof(envbuf_Lines), "LINES=%ld", rows);
|
||||||
putenv(envbuf_Rows);
|
putenv(envbuf_Lines);
|
||||||
sprintf(envbuf_Columns, "COLUMNS=%ld", Columns);
|
vim_snprintf(envbuf_Columns, sizeof(envbuf_Columns),
|
||||||
|
"COLUMNS=%ld", columns);
|
||||||
putenv(envbuf_Columns);
|
putenv(envbuf_Columns);
|
||||||
# endif
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_default_child_environment(void)
|
||||||
|
{
|
||||||
|
set_child_environment(Rows, Columns, "dumb");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -4417,7 +4427,7 @@ mch_call_shell(
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
set_child_environment();
|
set_default_child_environment();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* stderr is only redirected when using the GUI, so that a
|
* stderr is only redirected when using the GUI, so that a
|
||||||
@@ -5090,7 +5100,7 @@ error:
|
|||||||
|
|
||||||
#if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
|
#if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
|
||||||
void
|
void
|
||||||
mch_start_job(char **argv, job_T *job, jobopt_T *options UNUSED)
|
mch_start_job(char **argv, job_T *job, jobopt_T *options)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int fd_in[2]; /* for stdin */
|
int fd_in[2]; /* for stdin */
|
||||||
@@ -5200,7 +5210,15 @@ mch_start_job(char **argv, job_T *job, jobopt_T *options UNUSED)
|
|||||||
(void)setsid();
|
(void)setsid();
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
set_child_environment();
|
# ifdef FEAT_TERMINAL
|
||||||
|
if (options->jo_term_rows > 0)
|
||||||
|
set_child_environment(
|
||||||
|
(long)options->jo_term_rows,
|
||||||
|
(long)options->jo_term_cols,
|
||||||
|
"xterm");
|
||||||
|
else
|
||||||
|
# endif
|
||||||
|
set_default_child_environment();
|
||||||
|
|
||||||
if (use_null_for_in || use_null_for_out || use_null_for_err)
|
if (use_null_for_in || use_null_for_out || use_null_for_err)
|
||||||
null_fd = open("/dev/null", O_RDWR | O_EXTRA, 0);
|
null_fd = open("/dev/null", O_RDWR | O_EXTRA, 0);
|
||||||
|
@@ -1732,6 +1732,12 @@ typedef struct
|
|||||||
int jo_id;
|
int jo_id;
|
||||||
char_u jo_soe_buf[NUMBUFLEN];
|
char_u jo_soe_buf[NUMBUFLEN];
|
||||||
char_u *jo_stoponexit;
|
char_u *jo_stoponexit;
|
||||||
|
|
||||||
|
#ifdef FEAT_TERMINAL
|
||||||
|
/* when non-zero run the job in a terminal window of this size */
|
||||||
|
int jo_term_rows;
|
||||||
|
int jo_term_cols;
|
||||||
|
#endif
|
||||||
} jobopt_T;
|
} jobopt_T;
|
||||||
|
|
||||||
|
|
||||||
|
@@ -184,6 +184,8 @@ ex_terminal(exarg_T *eap)
|
|||||||
opt.jo_io_buf[PART_OUT] = curbuf->b_fnum;
|
opt.jo_io_buf[PART_OUT] = curbuf->b_fnum;
|
||||||
opt.jo_io_buf[PART_ERR] = curbuf->b_fnum;
|
opt.jo_io_buf[PART_ERR] = curbuf->b_fnum;
|
||||||
opt.jo_set |= JO_OUT_BUF + (JO_OUT_BUF << (PART_ERR - PART_OUT));
|
opt.jo_set |= JO_OUT_BUF + (JO_OUT_BUF << (PART_ERR - PART_OUT));
|
||||||
|
opt.jo_term_rows = rows;
|
||||||
|
opt.jo_term_cols = cols;
|
||||||
|
|
||||||
term->tl_job = job_start(argvars, &opt);
|
term->tl_job = job_start(argvars, &opt);
|
||||||
}
|
}
|
||||||
@@ -267,7 +269,11 @@ terminal_loop(void)
|
|||||||
update_screen(0);
|
update_screen(0);
|
||||||
setcursor();
|
setcursor();
|
||||||
out_flush();
|
out_flush();
|
||||||
|
++no_mapping;
|
||||||
|
++allow_keys;
|
||||||
c = vgetc();
|
c = vgetc();
|
||||||
|
--no_mapping;
|
||||||
|
--allow_keys;
|
||||||
|
|
||||||
/* Catch keys that need to be handled as in Normal mode. */
|
/* Catch keys that need to be handled as in Normal mode. */
|
||||||
switch (c)
|
switch (c)
|
||||||
@@ -331,6 +337,13 @@ term_update_window(win_T *wp)
|
|||||||
term_update_lines(wp);
|
term_update_lines(wp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
position_cursor(win_T *wp, VTermPos *pos)
|
||||||
|
{
|
||||||
|
wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1));
|
||||||
|
wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WIN3264
|
#ifdef WIN3264
|
||||||
|
|
||||||
/**************************************
|
/**************************************
|
||||||
@@ -486,7 +499,7 @@ handle_damage(VTermRect rect, void *user)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
handle_moverect(VTermRect dest, VTermRect src, void *user)
|
handle_moverect(VTermRect dest UNUSED, VTermRect src UNUSED, void *user)
|
||||||
{
|
{
|
||||||
term_T *term = (term_T *)user;
|
term_T *term = (term_T *)user;
|
||||||
|
|
||||||
@@ -496,7 +509,11 @@ handle_moverect(VTermRect dest, VTermRect src, void *user)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
handle_movecursor(VTermPos pos, VTermPos oldpos, int visible, void *user)
|
handle_movecursor(
|
||||||
|
VTermPos pos,
|
||||||
|
VTermPos oldpos UNUSED,
|
||||||
|
int visible UNUSED,
|
||||||
|
void *user)
|
||||||
{
|
{
|
||||||
term_T *term = (term_T *)user;
|
term_T *term = (term_T *)user;
|
||||||
win_T *wp;
|
win_T *wp;
|
||||||
@@ -506,9 +523,7 @@ handle_movecursor(VTermPos pos, VTermPos oldpos, int visible, void *user)
|
|||||||
{
|
{
|
||||||
if (wp->w_buffer == term->tl_buffer)
|
if (wp->w_buffer == term->tl_buffer)
|
||||||
{
|
{
|
||||||
/* TODO: limit to window size? */
|
position_cursor(wp, &pos);
|
||||||
wp->w_wrow = pos.row;
|
|
||||||
wp->w_wcol = pos.col;
|
|
||||||
if (wp == curwin)
|
if (wp == curwin)
|
||||||
is_current = TRUE;
|
is_current = TRUE;
|
||||||
}
|
}
|
||||||
@@ -527,8 +542,17 @@ handle_movecursor(VTermPos pos, VTermPos oldpos, int visible, void *user)
|
|||||||
handle_resize(int rows, int cols, void *user)
|
handle_resize(int rows, int cols, void *user)
|
||||||
{
|
{
|
||||||
term_T *term = (term_T *)user;
|
term_T *term = (term_T *)user;
|
||||||
|
win_T *wp;
|
||||||
|
|
||||||
|
FOR_ALL_WINDOWS(wp)
|
||||||
|
{
|
||||||
|
if (wp->w_buffer == term->tl_buffer)
|
||||||
|
{
|
||||||
|
win_setheight_win(rows, wp);
|
||||||
|
win_setwidth_win(cols, wp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO: handle terminal resize. */
|
|
||||||
redraw_buf_later(term->tl_buffer, NOT_VALID);
|
redraw_buf_later(term->tl_buffer, NOT_VALID);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -648,10 +672,23 @@ term_update_lines(win_T *wp)
|
|||||||
int vterm_cols;
|
int vterm_cols;
|
||||||
VTerm *vterm = wp->w_buffer->b_term->tl_vterm;
|
VTerm *vterm = wp->w_buffer->b_term->tl_vterm;
|
||||||
VTermScreen *screen = vterm_obtain_screen(vterm);
|
VTermScreen *screen = vterm_obtain_screen(vterm);
|
||||||
|
VTermState *state = vterm_obtain_state(vterm);
|
||||||
VTermPos pos;
|
VTermPos pos;
|
||||||
|
|
||||||
vterm_get_size(vterm, &vterm_rows, &vterm_cols);
|
vterm_get_size(vterm, &vterm_rows, &vterm_cols);
|
||||||
|
|
||||||
|
if (*wp->w_p_tms == NUL
|
||||||
|
&& (vterm_rows != wp->w_height || vterm_cols != wp->w_width))
|
||||||
|
{
|
||||||
|
vterm_set_size(vterm, wp->w_height, wp->w_width);
|
||||||
|
/* Get the size again, in case setting the didn't work. */
|
||||||
|
vterm_get_size(vterm, &vterm_rows, &vterm_cols);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The cursor may have been moved when resizing. */
|
||||||
|
vterm_state_get_cursorpos(state, &pos);
|
||||||
|
position_cursor(wp, &pos);
|
||||||
|
|
||||||
/* TODO: Only redraw what changed. */
|
/* TODO: Only redraw what changed. */
|
||||||
for (pos.row = 0; pos.row < wp->w_height; ++pos.row)
|
for (pos.row = 0; pos.row < wp->w_height; ++pos.row)
|
||||||
{
|
{
|
||||||
|
@@ -769,6 +769,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
739,
|
||||||
/**/
|
/**/
|
||||||
738,
|
738,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user