forked from aniani/vim
patch 8.0.1738: ":args" output is hard to read
Problem: ":args" output is hard to read. Solution: Make columns with the names if the output is more than one line.
This commit is contained in:
@@ -2751,17 +2751,18 @@ ex_args(exarg_T *eap)
|
|||||||
*/
|
*/
|
||||||
if (ARGCOUNT > 0)
|
if (ARGCOUNT > 0)
|
||||||
{
|
{
|
||||||
/* Overwrite the command, for a short list there is no scrolling
|
char **items = (char **)alloc(sizeof(char *) * ARGCOUNT);
|
||||||
* required and no wait_return(). */
|
|
||||||
gotocmdline(TRUE);
|
if (items != NULL)
|
||||||
for (i = 0; i < ARGCOUNT; ++i)
|
|
||||||
{
|
{
|
||||||
if (i == curwin->w_arg_idx)
|
/* Overwrite the command, for a short list there is no
|
||||||
msg_putchar('[');
|
* scrolling required and no wait_return(). */
|
||||||
msg_outtrans(alist_name(&ARGLIST[i]));
|
gotocmdline(TRUE);
|
||||||
if (i == curwin->w_arg_idx)
|
|
||||||
msg_putchar(']');
|
for (i = 0; i < ARGCOUNT; ++i)
|
||||||
msg_putchar(' ');
|
items[i] = (char *)alist_name(&ARGLIST[i]);
|
||||||
|
list_in_columns(items, ARGCOUNT, curwin->w_arg_idx);
|
||||||
|
vim_free(items);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ void make_version(void);
|
|||||||
int highest_patch(void);
|
int highest_patch(void);
|
||||||
int has_patch(int n);
|
int has_patch(int n);
|
||||||
void ex_version(exarg_T *eap);
|
void ex_version(exarg_T *eap);
|
||||||
|
void list_in_columns(char_u **items, int size, int current);
|
||||||
void list_version(void);
|
void list_version(void);
|
||||||
void maybe_intro_message(void);
|
void maybe_intro_message(void);
|
||||||
void intro_message(int colon);
|
void intro_message(int colon);
|
||||||
|
@@ -122,9 +122,9 @@ func Test_argument()
|
|||||||
call assert_equal(['d', 'c', 'b', 'a', 'c'], g:buffers)
|
call assert_equal(['d', 'c', 'b', 'a', 'c'], g:buffers)
|
||||||
|
|
||||||
redir => result
|
redir => result
|
||||||
ar
|
args
|
||||||
redir END
|
redir END
|
||||||
call assert_true(result =~# 'a b \[c] d')
|
call assert_equal('a b [c] d', trim(result))
|
||||||
|
|
||||||
.argd
|
.argd
|
||||||
call assert_equal(['a', 'b', 'd'], argv())
|
call assert_equal(['a', 'b', 'd'], argv())
|
||||||
@@ -170,6 +170,34 @@ func Test_argument()
|
|||||||
call assert_fails('argument', 'E163:')
|
call assert_fails('argument', 'E163:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_list_arguments()
|
||||||
|
" Clean the argument list
|
||||||
|
arga a | %argd
|
||||||
|
|
||||||
|
" four args half the screen width makes two lines with two columns
|
||||||
|
let aarg = repeat('a', &columns / 2 - 4)
|
||||||
|
let barg = repeat('b', &columns / 2 - 4)
|
||||||
|
let carg = repeat('c', &columns / 2 - 4)
|
||||||
|
let darg = repeat('d', &columns / 2 - 4)
|
||||||
|
exe 'argadd ' aarg barg carg darg
|
||||||
|
|
||||||
|
redir => result
|
||||||
|
args
|
||||||
|
redir END
|
||||||
|
call assert_match('\[' . aarg . '] \+' . carg . '\n' . barg . ' \+' . darg, trim(result))
|
||||||
|
|
||||||
|
" if one arg is longer than half the screen make one column
|
||||||
|
exe 'argdel' aarg
|
||||||
|
let aarg = repeat('a', &columns / 2 + 2)
|
||||||
|
exe '0argadd' aarg
|
||||||
|
redir => result
|
||||||
|
args
|
||||||
|
redir END
|
||||||
|
call assert_match(aarg . '\n\[' . barg . ']\n' . carg . '\n' . darg, trim(result))
|
||||||
|
|
||||||
|
%argdelete
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Test for 0argadd and 0argedit
|
" Test for 0argadd and 0argedit
|
||||||
" Ported from the test_argument_0count.in test script
|
" Ported from the test_argument_0count.in test script
|
||||||
func Test_zero_argadd()
|
func Test_zero_argadd()
|
||||||
|
@@ -57,7 +57,6 @@ char *longVersion = VIM_VERSION_LONG;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void list_features(void);
|
static void list_features(void);
|
||||||
static void version_msg(char *s);
|
|
||||||
|
|
||||||
static char *(features[]) =
|
static char *(features[]) =
|
||||||
{
|
{
|
||||||
@@ -762,6 +761,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 */
|
||||||
|
/**/
|
||||||
|
1738,
|
||||||
/**/
|
/**/
|
||||||
1737,
|
1737,
|
||||||
/**/
|
/**/
|
||||||
@@ -4294,36 +4295,76 @@ ex_version(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output a string for the version message. If it's going to wrap, output a
|
||||||
|
* newline, unless the message is too long to fit on the screen anyway.
|
||||||
|
* When "wrap" is TRUE wrap the string in [].
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
version_msg_wrap(char_u *s, int wrap)
|
||||||
|
{
|
||||||
|
int len = (int)vim_strsize(s) + (wrap ? 2 : 0);
|
||||||
|
|
||||||
|
if (!got_int && len < (int)Columns && msg_col + len >= (int)Columns
|
||||||
|
&& *s != '\n')
|
||||||
|
msg_putchar('\n');
|
||||||
|
if (!got_int)
|
||||||
|
{
|
||||||
|
if (wrap)
|
||||||
|
MSG_PUTS("[");
|
||||||
|
MSG_PUTS(s);
|
||||||
|
if (wrap)
|
||||||
|
MSG_PUTS("]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
version_msg(char *s)
|
||||||
|
{
|
||||||
|
version_msg_wrap((char_u *)s, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* List all features aligned in columns, dictionary style.
|
* List all features aligned in columns, dictionary style.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
list_features(void)
|
list_features(void)
|
||||||
|
{
|
||||||
|
list_in_columns((char_u **)features, -1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* List string items nicely aligned in columns.
|
||||||
|
* When "size" is < 0 then the last entry is marked with NULL.
|
||||||
|
* The entry with index "current" is inclosed in [].
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
list_in_columns(char_u **items, int size, int current)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int ncol;
|
int ncol;
|
||||||
int nrow;
|
int nrow;
|
||||||
int nfeat = 0;
|
int item_count = 0;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
|
|
||||||
/* Find the length of the longest feature name, use that + 1 as the column
|
/* Find the length of the longest item, use that + 1 as the column
|
||||||
* width */
|
* width. */
|
||||||
for (i = 0; features[i] != NULL; ++i)
|
for (i = 0; size < 0 ? items[i] != NULL : i < size; ++i)
|
||||||
{
|
{
|
||||||
int l = (int)STRLEN(features[i]);
|
int l = (int)vim_strsize(items[i]) + (i == current ? 2 : 0);
|
||||||
|
|
||||||
if (l > width)
|
if (l > width)
|
||||||
width = l;
|
width = l;
|
||||||
++nfeat;
|
++item_count;
|
||||||
}
|
}
|
||||||
width += 1;
|
width += 1;
|
||||||
|
|
||||||
if (Columns < width)
|
if (Columns < width)
|
||||||
{
|
{
|
||||||
/* Not enough screen columns - show one per line */
|
/* Not enough screen columns - show one per line */
|
||||||
for (i = 0; features[i] != NULL; ++i)
|
for (i = 0; items[i] != NULL; ++i)
|
||||||
{
|
{
|
||||||
version_msg(features[i]);
|
version_msg_wrap(items[i], i == current);
|
||||||
if (msg_col > 0)
|
if (msg_col > 0)
|
||||||
msg_putchar('\n');
|
msg_putchar('\n');
|
||||||
}
|
}
|
||||||
@@ -4333,18 +4374,22 @@ list_features(void)
|
|||||||
/* The rightmost column doesn't need a separator.
|
/* The rightmost column doesn't need a separator.
|
||||||
* Sacrifice it to fit in one more column if possible. */
|
* Sacrifice it to fit in one more column if possible. */
|
||||||
ncol = (int) (Columns + 1) / width;
|
ncol = (int) (Columns + 1) / width;
|
||||||
nrow = nfeat / ncol + (nfeat % ncol ? 1 : 0);
|
nrow = item_count / ncol + (item_count % ncol ? 1 : 0);
|
||||||
|
|
||||||
/* i counts columns then rows. idx counts rows then columns. */
|
/* i counts columns then rows. idx counts rows then columns. */
|
||||||
for (i = 0; !got_int && i < nrow * ncol; ++i)
|
for (i = 0; !got_int && i < nrow * ncol; ++i)
|
||||||
{
|
{
|
||||||
int idx = (i / ncol) + (i % ncol) * nrow;
|
int idx = (i / ncol) + (i % ncol) * nrow;
|
||||||
|
|
||||||
if (idx < nfeat)
|
if (idx < item_count)
|
||||||
{
|
{
|
||||||
int last_col = (i + 1) % ncol == 0;
|
int last_col = (i + 1) % ncol == 0;
|
||||||
|
|
||||||
msg_puts((char_u *)features[idx]);
|
if (idx == current)
|
||||||
|
msg_putchar('[');
|
||||||
|
msg_puts(items[idx]);
|
||||||
|
if (idx == current)
|
||||||
|
msg_putchar(']');
|
||||||
if (last_col)
|
if (last_col)
|
||||||
{
|
{
|
||||||
if (msg_col > 0)
|
if (msg_col > 0)
|
||||||
@@ -4636,22 +4681,6 @@ list_version(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Output a string for the version message. If it's going to wrap, output a
|
|
||||||
* newline, unless the message is too long to fit on the screen anyway.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
version_msg(char *s)
|
|
||||||
{
|
|
||||||
int len = (int)STRLEN(s);
|
|
||||||
|
|
||||||
if (!got_int && len < (int)Columns && msg_col + len >= (int)Columns
|
|
||||||
&& *s != '\n')
|
|
||||||
msg_putchar('\n');
|
|
||||||
if (!got_int)
|
|
||||||
MSG_PUTS(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void do_intro_line(int row, char_u *mesg, int add_version, int attr);
|
static void do_intro_line(int row, char_u *mesg, int add_version, int attr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user