Skip to content

Commit 15cd15a

Browse files
committed
updated for version 7.3.1288
Problem: The first ":echo 'hello'" command output doesn't show. Mapping for <S-F3> gets triggered during startup. Solution: Add debugging code for the termresponse. When receiving the "Co" entry and when setting 'ambiwidth' redraw right away if possible. Add redraw_asap(). Don't set 'ambiwidth' if it already had the right value. Do the 'ambiwidth' check in the second row to avoid confusion with <S-F3>.
1 parent 05c1e99 commit 15cd15a

File tree

4 files changed

+246
-9
lines changed

4 files changed

+246
-9
lines changed

src/proto/screen.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ void redraw_later_clear __ARGS((void));
55
void redraw_all_later __ARGS((int type));
66
void redraw_curbuf_later __ARGS((int type));
77
void redraw_buf_later __ARGS((buf_T *buf, int type));
8+
int redraw_asap __ARGS((int type));
89
void redrawWinline __ARGS((linenr_T lnum, int invalid));
910
void update_curbuf __ARGS((int type));
1011
void update_screen __ARGS((int type));

src/screen.c

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,147 @@ redraw_buf_later(buf, type)
267267
}
268268
}
269269

270+
/*
271+
* Redraw as soon as possible. When the command line is not scrolled redraw
272+
* right away and restore what was on the command line.
273+
* Return a code indicating what happened.
274+
*/
275+
int
276+
redraw_asap(type)
277+
int type;
278+
{
279+
int rows;
280+
int r;
281+
int ret = 0;
282+
schar_T *screenline; /* copy from ScreenLines[] */
283+
sattr_T *screenattr; /* copy from ScreenAttrs[] */
284+
#ifdef FEAT_MBYTE
285+
int i;
286+
u8char_T *screenlineUC; /* copy from ScreenLinesUC[] */
287+
u8char_T *screenlineC[MAX_MCO]; /* copy from ScreenLinesC[][] */
288+
schar_T *screenline2; /* copy from ScreenLines2[] */
289+
#endif
290+
291+
redraw_later(type);
292+
if (msg_scrolled || (State != NORMAL && State != NORMAL_BUSY))
293+
return ret;
294+
295+
/* Allocate space to save the text displayed in the command line area. */
296+
rows = Rows - cmdline_row;
297+
screenline = (schar_T *)lalloc(
298+
(long_u)(rows * Columns * sizeof(schar_T)), FALSE);
299+
screenattr = (sattr_T *)lalloc(
300+
(long_u)(rows * Columns * sizeof(sattr_T)), FALSE);
301+
if (screenline == NULL || screenattr == NULL)
302+
ret = 2;
303+
#ifdef FEAT_MBYTE
304+
if (enc_utf8)
305+
{
306+
screenlineUC = (u8char_T *)lalloc(
307+
(long_u)(rows * Columns * sizeof(u8char_T)), FALSE);
308+
if (screenlineUC == NULL)
309+
ret = 2;
310+
for (i = 0; i < p_mco; ++i)
311+
{
312+
screenlineC[i] = (u8char_T *)lalloc(
313+
(long_u)(rows * Columns * sizeof(u8char_T)), FALSE);
314+
if (screenlineC[i] == NULL)
315+
ret = 2;
316+
}
317+
}
318+
if (enc_dbcs == DBCS_JPNU)
319+
{
320+
screenline2 = (schar_T *)lalloc(
321+
(long_u)(rows * Columns * sizeof(schar_T)), FALSE);
322+
if (screenline2 == NULL)
323+
ret = 2;
324+
}
325+
#endif
326+
327+
if (ret != 2)
328+
{
329+
/* Save the text displayed in the command line area. */
330+
for (r = 0; r < rows; ++r)
331+
{
332+
mch_memmove(screenline + r * Columns,
333+
ScreenLines + LineOffset[cmdline_row + r],
334+
(size_t)Columns * sizeof(schar_T));
335+
mch_memmove(screenattr + r * Columns,
336+
ScreenAttrs + LineOffset[cmdline_row + r],
337+
(size_t)Columns * sizeof(sattr_T));
338+
#ifdef FEAT_MBYTE
339+
if (enc_utf8)
340+
{
341+
mch_memmove(screenlineUC + r * Columns,
342+
ScreenLinesUC + LineOffset[cmdline_row + r],
343+
(size_t)Columns * sizeof(u8char_T));
344+
for (i = 0; i < p_mco; ++i)
345+
mch_memmove(screenlineC[i] + r * Columns,
346+
ScreenLinesC[r] + LineOffset[cmdline_row + r],
347+
(size_t)Columns * sizeof(u8char_T));
348+
}
349+
if (enc_dbcs == DBCS_JPNU)
350+
mch_memmove(screenline2 + r * Columns,
351+
ScreenLines2 + LineOffset[cmdline_row + r],
352+
(size_t)Columns * sizeof(schar_T));
353+
#endif
354+
}
355+
356+
update_screen(0);
357+
ret = 3;
358+
359+
if (must_redraw == 0)
360+
{
361+
int off = (int)(current_ScreenLine - ScreenLines);
362+
363+
/* Restore the text displayed in the command line area. */
364+
for (r = 0; r < rows; ++r)
365+
{
366+
mch_memmove(current_ScreenLine,
367+
screenline + r * Columns,
368+
(size_t)Columns * sizeof(schar_T));
369+
mch_memmove(ScreenAttrs + off,
370+
screenattr + r * Columns,
371+
(size_t)Columns * sizeof(sattr_T));
372+
#ifdef FEAT_MBYTE
373+
if (enc_utf8)
374+
{
375+
mch_memmove(ScreenLinesUC + off,
376+
screenlineUC + r * Columns,
377+
(size_t)Columns * sizeof(u8char_T));
378+
for (i = 0; i < p_mco; ++i)
379+
mch_memmove(ScreenLinesC[i] + off,
380+
screenlineC[i] + r * Columns,
381+
(size_t)Columns * sizeof(u8char_T));
382+
}
383+
if (enc_dbcs == DBCS_JPNU)
384+
mch_memmove(ScreenLines2 + off,
385+
screenline2 + r * Columns,
386+
(size_t)Columns * sizeof(schar_T));
387+
#endif
388+
SCREEN_LINE(cmdline_row + r, 0, Columns, Columns, FALSE);
389+
}
390+
ret = 4;
391+
}
392+
setcursor();
393+
}
394+
395+
vim_free(screenline);
396+
vim_free(screenattr);
397+
#ifdef FEAT_MBYTE
398+
if (enc_utf8)
399+
{
400+
vim_free(screenlineUC);
401+
for (i = 0; i < p_mco; ++i)
402+
vim_free(screenlineC[i]);
403+
}
404+
if (enc_dbcs == DBCS_JPNU)
405+
vim_free(screenline2);
406+
#endif
407+
408+
return ret;
409+
}
410+
270411
/*
271412
* Changed something in the current window, at buffer line "lnum", that
272413
* requires that line and possibly other lines to be redrawn.

src/term.c

Lines changed: 102 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ static char_u *tgetent_error __ARGS((char_u *, char_u *));
106106
char *tgetstr __ARGS((char *, char **));
107107

108108
# ifdef FEAT_TERMRESPONSE
109+
/* Change this to "if 1" to debug what happens with termresponse. */
110+
# if 0
111+
# define DEBUG_TERMRESPONSE
112+
static void log_tr(char *msg);
113+
# define LOG_TR(msg) log_tr(msg)
114+
# else
115+
# define LOG_TR(msg)
116+
# endif
109117
/* Request Terminal Version status: */
110118
# define CRV_GET 1 /* send T_CRV when switched to RAW mode */
111119
# define CRV_SENT 2 /* did send T_CRV, waiting for answer */
@@ -1936,6 +1944,7 @@ set_termname(term)
19361944
full_screen = TRUE; /* we can use termcap codes from now on */
19371945
set_term_defaults(); /* use current values as defaults */
19381946
#ifdef FEAT_TERMRESPONSE
1947+
LOG_TR("setting crv_status to CRV_GET");
19391948
crv_status = CRV_GET; /* Get terminal version later */
19401949
#endif
19411950

@@ -3326,6 +3335,7 @@ may_req_termresponse()
33263335
# endif
33273336
&& *T_CRV != NUL)
33283337
{
3338+
LOG_TR("Sending CRV");
33293339
out_str(T_CRV);
33303340
crv_status = CRV_SENT;
33313341
/* check for the characters now, otherwise they might be eaten by
@@ -3338,10 +3348,10 @@ may_req_termresponse()
33383348
# if defined(FEAT_MBYTE) || defined(PROTO)
33393349
/*
33403350
* Check how the terminal treats ambiguous character width (UAX #11).
3341-
* First, we move the cursor to (0, 0) and print a test ambiguous character
3351+
* First, we move the cursor to (1, 0) and print a test ambiguous character
33423352
* \u25bd (WHITE DOWN-POINTING TRIANGLE) and query current cursor position.
3343-
* If the terminal treats \u25bd as single width, the position is (0, 1),
3344-
* or if it is treated as double width, that will be (0, 2).
3353+
* If the terminal treats \u25bd as single width, the position is (1, 1),
3354+
* or if it is treated as double width, that will be (1, 2).
33453355
* This function has the side effect that changes cursor position, so
33463356
* it must be called immediately after entering termcap mode.
33473357
*/
@@ -3361,7 +3371,10 @@ may_req_ambiguous_character_width()
33613371
{
33623372
char_u buf[16];
33633373

3364-
term_windgoto(0, 0);
3374+
LOG_TR("Sending U7 request");
3375+
/* Do this in the second row. In the first row the returned sequence
3376+
* may be CSI 1;2R, which is the same as <S-F3>. */
3377+
term_windgoto(1, 0);
33653378
buf[mb_char2bytes(0x25bd, buf)] = 0;
33663379
out_str(buf);
33673380
out_str(T_U7);
@@ -3376,6 +3389,29 @@ may_req_ambiguous_character_width()
33763389
}
33773390
}
33783391
# endif
3392+
3393+
# ifdef DEBUG_TERMRESPONSE
3394+
static void
3395+
log_tr(char *msg)
3396+
{
3397+
static FILE *fd_tr = NULL;
3398+
static proftime_T start;
3399+
proftime_T now;
3400+
3401+
if (fd_tr == NULL)
3402+
{
3403+
fd_tr = fopen("termresponse.log", "w");
3404+
profile_start(&start);
3405+
}
3406+
now = start;
3407+
profile_end(&now);
3408+
fprintf(fd_tr, "%s: %s %s\n",
3409+
profile_msg(&now),
3410+
must_redraw == NOT_VALID ? "NV"
3411+
: must_redraw == CLEAR ? "CL" : " ",
3412+
msg);
3413+
}
3414+
# endif
33793415
#endif
33803416

33813417
/*
@@ -3847,6 +3883,7 @@ switch_to_8bit()
38473883
need_gather = TRUE; /* need to fill termleader[] */
38483884
}
38493885
detected_8bit = TRUE;
3886+
LOG_TR("Switching to 8 bit");
38503887
}
38513888
#endif
38523889

@@ -4156,14 +4193,20 @@ check_termcode(max_offset, buf, bufsize, buflen)
41564193
if (tp[i] == ';' && ++j == 1)
41574194
extra = i + 1;
41584195
if (i == len)
4159-
return -1; /* not enough characters */
4196+
{
4197+
LOG_TR("Not enough characters for CRV");
4198+
return -1;
4199+
}
41604200

41614201
#ifdef FEAT_MBYTE
4162-
/* eat it when it has 2 arguments and ends in 'R' */
4163-
if (j == 1 && tp[i] == 'R')
4202+
/* Eat it when it has 2 arguments and ends in 'R'. Ignore it
4203+
* when u7_status is not "sent", <S-F3> sends something
4204+
* similar. */
4205+
if (j == 1 && tp[i] == 'R' && u7_status == U7_SENT)
41644206
{
41654207
char *aw = NULL;
41664208

4209+
LOG_TR("Received U7 status");
41674210
u7_status = U7_GOT;
41684211
# ifdef FEAT_AUTOCMD
41694212
did_cursorhold = TRUE;
@@ -4174,8 +4217,24 @@ check_termcode(max_offset, buf, bufsize, buflen)
41744217
aw = "single";
41754218
else if (extra == 3)
41764219
aw = "double";
4177-
if (aw != NULL)
4220+
if (aw != NULL && STRCMP(aw, p_ambw) != 0)
4221+
{
4222+
/* Setting the option causes a screen redraw. Do that
4223+
* right away if possible, keeping any messages. */
41784224
set_option_value((char_u *)"ambw", 0L, (char_u *)aw, 0);
4225+
#ifdef DEBUG_TERMRESPONSE
4226+
{
4227+
char buf[100];
4228+
int r = redraw_asap(CLEAR);
4229+
4230+
sprintf(buf, "set 'ambiwidth', redraw_asap(): %d",
4231+
r);
4232+
log_tr(buf);
4233+
}
4234+
#else
4235+
redraw_asap(CLEAR);
4236+
#endif
4237+
}
41794238
key_name[0] = (int)KS_EXTRA;
41804239
key_name[1] = (int)KE_IGNORE;
41814240
slen = i + 1;
@@ -4185,6 +4244,7 @@ check_termcode(max_offset, buf, bufsize, buflen)
41854244
/* eat it when at least one digit and ending in 'c' */
41864245
if (*T_CRV != NUL && i > 2 + (tp[0] != CSI) && tp[i] == 'c')
41874246
{
4247+
LOG_TR("Received CRV");
41884248
crv_status = CRV_GOT;
41894249
# ifdef FEAT_AUTOCMD
41904250
did_cursorhold = TRUE;
@@ -4224,6 +4284,7 @@ check_termcode(max_offset, buf, bufsize, buflen)
42244284
/* if xterm version >= 141 try to get termcap codes */
42254285
if (extra >= 141)
42264286
{
4287+
LOG_TR("Enable checking for XT codes");
42274288
check_for_codes = TRUE;
42284289
need_gather = TRUE;
42294290
req_codes_from_term();
@@ -4262,7 +4323,10 @@ check_termcode(max_offset, buf, bufsize, buflen)
42624323
}
42634324

42644325
if (i == len)
4326+
{
4327+
LOG_TR("not enough characters for XT");
42654328
return -1; /* not enough characters */
4329+
}
42664330
}
42674331
}
42684332
#endif
@@ -5207,6 +5271,10 @@ check_termcode(max_offset, buf, bufsize, buflen)
52075271
return retval == 0 ? (len + extra + offset) : retval;
52085272
}
52095273

5274+
#ifdef FEAT_TERMRESPONSE
5275+
LOG_TR("normal character");
5276+
#endif
5277+
52105278
return 0; /* no match found */
52115279
}
52125280

@@ -5661,6 +5729,13 @@ req_more_codes_from_term()
56615729
* many, there can be a buffer overflow somewhere. */
56625730
while (xt_index_out < xt_index_in + 10 && key_names[xt_index_out] != NULL)
56635731
{
5732+
# ifdef DEBUG_TERMRESPONSE
5733+
char dbuf[100];
5734+
5735+
sprintf(dbuf, "Requesting XT %d: %s",
5736+
xt_index_out, key_names[xt_index_out]);
5737+
log_tr(dbuf);
5738+
# endif
56645739
sprintf(buf, "\033P+q%02x%02x\033\\",
56655740
key_names[xt_index_out][0], key_names[xt_index_out][1]);
56665741
out_str_nf((char_u *)buf);
@@ -5707,6 +5782,14 @@ got_code_from_term(code, len)
57075782
break;
57085783
}
57095784
}
5785+
# ifdef DEBUG_TERMRESPONSE
5786+
{
5787+
char buf[100];
5788+
5789+
sprintf(buf, "Received XT %d: %s", xt_index_in, (char *)name);
5790+
log_tr(buf);
5791+
}
5792+
# endif
57105793
if (key_names[i] != NULL)
57115794
{
57125795
for (i = 8; (c = hexhex2nr(code + i)) >= 0; i += 2)
@@ -5725,7 +5808,17 @@ got_code_from_term(code, len)
57255808
set_keep_msg_from_hist();
57265809
set_color_count(i);
57275810
init_highlight(TRUE, FALSE);
5728-
redraw_later(CLEAR);
5811+
#ifdef DEBUG_TERMRESPONSE
5812+
{
5813+
char buf[100];
5814+
int r = redraw_asap(CLEAR);
5815+
5816+
sprintf(buf, "Received t_Co, redraw_asap(): %d", r);
5817+
log_tr(buf);
5818+
}
5819+
#else
5820+
redraw_asap(CLEAR);
5821+
#endif
57295822
}
57305823
}
57315824
else

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@ static char *(features[]) =
728728

729729
static int included_patches[] =
730730
{ /* Add new patch number below this line */
731+
/**/
732+
1288,
731733
/**/
732734
1287,
733735
/**/

0 commit comments

Comments
 (0)