Skip to content

Commit 4a69634

Browse files
committed
patch 8.0.1662: showing dump diff doesn't mention both file names
Problem: Showing dump diff doesn't mention both file names. Solution: Add the file name in the separator line.
1 parent 878c96d commit 4a69634

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

src/terminal.c

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* - Add a way to set the 16 ANSI colors, to be used for 'termguicolors' and in
4242
* the GUI.
4343
* - Win32: Make terminal used for :!cmd in the GUI work better. Allow for
44-
* redirection.
44+
* redirection. Probably in call to channel_set_pipes().
4545
* - implement term_setsize()
4646
* - Copy text in the vterm to the Vim buffer once in a while, so that
4747
* completion works.
@@ -3916,6 +3916,57 @@ read_dump_file(FILE *fd, VTermPos *cursor_pos)
39163916
return max_cells;
39173917
}
39183918

3919+
/*
3920+
* Return an allocated string with at least "text_width" "=" characters and
3921+
* "fname" inserted in the middle.
3922+
*/
3923+
static char_u *
3924+
get_separator(int text_width, char_u *fname)
3925+
{
3926+
int width = MAX(text_width, curwin->w_width);
3927+
char_u *textline;
3928+
int fname_size;
3929+
char_u *p = fname;
3930+
int i;
3931+
int off;
3932+
3933+
textline = alloc(width + STRLEN(fname) + 1);
3934+
if (textline == NULL)
3935+
return NULL;
3936+
3937+
fname_size = vim_strsize(fname);
3938+
if (fname_size < width - 8)
3939+
{
3940+
/* enough room, don't use the full window width */
3941+
width = MAX(text_width, fname_size + 8);
3942+
}
3943+
else if (fname_size > width - 8)
3944+
{
3945+
/* full name doesn't fit, use only the tail */
3946+
p = gettail(fname);
3947+
fname_size = vim_strsize(p);
3948+
}
3949+
/* skip characters until the name fits */
3950+
while (fname_size > width - 8)
3951+
{
3952+
p += (*mb_ptr2len)(p);
3953+
fname_size = vim_strsize(p);
3954+
}
3955+
3956+
for (i = 0; i < (width - fname_size) / 2 - 1; ++i)
3957+
textline[i] = '=';
3958+
textline[i++] = ' ';
3959+
3960+
STRCPY(textline + i, p);
3961+
off = STRLEN(textline);
3962+
textline[off] = ' ';
3963+
for (i = 1; i < (width - fname_size) / 2; ++i)
3964+
textline[off + i] = '=';
3965+
textline[off + i] = NUL;
3966+
3967+
return textline;
3968+
}
3969+
39193970
/*
39203971
* Common for "term_dumpdiff()" and "term_dumpload()".
39213972
*/
@@ -4013,16 +4064,19 @@ term_load_dump(typval_T *argvars, typval_T *rettv, int do_diff)
40134064

40144065
term->tl_top_diff_rows = curbuf->b_ml.ml_line_count;
40154066

4016-
textline = alloc(width + 1);
4067+
textline = get_separator(width, fname1);
40174068
if (textline == NULL)
40184069
goto theend;
4019-
for (i = 0; i < width; ++i)
4020-
textline[i] = '=';
4021-
textline[width] = NUL;
40224070
if (add_empty_scrollback(term, &term->tl_default_color, 0) == OK)
40234071
ml_append(curbuf->b_ml.ml_line_count, textline, 0, FALSE);
4072+
vim_free(textline);
4073+
4074+
textline = get_separator(width, fname2);
4075+
if (textline == NULL)
4076+
goto theend;
40244077
if (add_empty_scrollback(term, &term->tl_default_color, 0) == OK)
40254078
ml_append(curbuf->b_ml.ml_line_count, textline, 0, FALSE);
4079+
textline[width] = NUL;
40264080

40274081
bot_lnum = curbuf->b_ml.ml_line_count;
40284082
width2 = read_dump_file(fd2, &cursor_pos2);
@@ -4143,6 +4197,9 @@ term_load_dump(typval_T *argvars, typval_T *rettv, int do_diff)
41434197
}
41444198

41454199
term->tl_cols = width;
4200+
4201+
/* looks better without wrapping */
4202+
curwin->w_p_wrap = 0;
41464203
}
41474204

41484205
theend:

src/version.c

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

763763
static int included_patches[] =
764764
{ /* Add new patch number below this line */
765+
/**/
766+
1662,
765767
/**/
766768
1661,
767769
/**/

0 commit comments

Comments
 (0)