Browse Source
A couple of commands learn --column option to produce columnar output. By Nguyễn Thái Ngọc Duy (9) and Zbigniew Jędrzejewski-Szmek (1) * nd/columns: tag: add --column column: support piping stdout to external git-column process status: add --column branch: add --column help: reuse print_columns() for help -a column: add dense layout support t9002: work around shells that are unable to set COLUMNS to 1 column: add columnar layout Stop starting pager recursively Add column layout skeleton and git-columnmaint

27 changed files with 1105 additions and 48 deletions
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
git-column(1) |
||||
============= |
||||
|
||||
NAME |
||||
---- |
||||
git-column - Display data in columns |
||||
|
||||
SYNOPSIS |
||||
-------- |
||||
[verse] |
||||
'git column' [--command=<name>] [--[raw-]mode=<mode>] [--width=<width>] |
||||
[--indent=<string>] [--nl=<string>] [--pading=<n>] |
||||
|
||||
DESCRIPTION |
||||
----------- |
||||
This command formats its input into multiple columns. |
||||
|
||||
OPTIONS |
||||
------- |
||||
--command=<name>:: |
||||
Look up layout mode using configuration variable column.<name> and |
||||
column.ui. |
||||
|
||||
--mode=<mode>:: |
||||
Specify layout mode. See configuration variable column.ui for option |
||||
syntax. |
||||
|
||||
--raw-mode=<n>:: |
||||
Same as --mode but take mode encoded as a number. This is mainly used |
||||
by other commands that have already parsed layout mode. |
||||
|
||||
--width=<width>:: |
||||
Specify the terminal width. By default 'git column' will detect the |
||||
terminal width, or fall back to 80 if it is unable to do so. |
||||
|
||||
--indent=<string>:: |
||||
String to be printed at the beginning of each line. |
||||
|
||||
--nl=<N>:: |
||||
String to be printed at the end of each line, |
||||
including newline character. |
||||
|
||||
--padding=<N>:: |
||||
The number of spaces between columns. One space by default. |
||||
|
||||
|
||||
Author |
||||
------ |
||||
Written by Nguyen Thai Ngoc Duy <pclouds@gmail.com> |
||||
|
||||
GIT |
||||
--- |
||||
Part of the linkgit:git[1] suite |
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
#include "builtin.h" |
||||
#include "cache.h" |
||||
#include "strbuf.h" |
||||
#include "parse-options.h" |
||||
#include "string-list.h" |
||||
#include "column.h" |
||||
|
||||
static const char * const builtin_column_usage[] = { |
||||
"git column [options]", |
||||
NULL |
||||
}; |
||||
static unsigned int colopts; |
||||
|
||||
static int column_config(const char *var, const char *value, void *cb) |
||||
{ |
||||
return git_column_config(var, value, cb, &colopts); |
||||
} |
||||
|
||||
int cmd_column(int argc, const char **argv, const char *prefix) |
||||
{ |
||||
struct string_list list = STRING_LIST_INIT_DUP; |
||||
struct strbuf sb = STRBUF_INIT; |
||||
struct column_options copts; |
||||
const char *command = NULL, *real_command = NULL; |
||||
struct option options[] = { |
||||
OPT_STRING(0, "command", &real_command, "name", "lookup config vars"), |
||||
OPT_COLUMN(0, "mode", &colopts, "layout to use"), |
||||
OPT_INTEGER(0, "raw-mode", &colopts, "layout to use"), |
||||
OPT_INTEGER(0, "width", &copts.width, "Maximum width"), |
||||
OPT_STRING(0, "indent", &copts.indent, "string", "Padding space on left border"), |
||||
OPT_INTEGER(0, "nl", &copts.nl, "Padding space on right border"), |
||||
OPT_INTEGER(0, "padding", &copts.padding, "Padding space between columns"), |
||||
OPT_END() |
||||
}; |
||||
|
||||
/* This one is special and must be the first one */ |
||||
if (argc > 1 && !prefixcmp(argv[1], "--command=")) { |
||||
command = argv[1] + 10; |
||||
git_config(column_config, (void *)command); |
||||
} else |
||||
git_config(column_config, NULL); |
||||
|
||||
memset(&copts, 0, sizeof(copts)); |
||||
copts.width = term_columns(); |
||||
copts.padding = 1; |
||||
argc = parse_options(argc, argv, "", options, builtin_column_usage, 0); |
||||
if (argc) |
||||
usage_with_options(builtin_column_usage, options); |
||||
if (real_command || command) { |
||||
if (!real_command || !command || strcmp(real_command, command)) |
||||
die(_("--command must be the first argument")); |
||||
} |
||||
finalize_colopts(&colopts, -1); |
||||
while (!strbuf_getline(&sb, stdin, '\n')) |
||||
string_list_append(&list, sb.buf); |
||||
|
||||
print_columns(&list, colopts, &copts); |
||||
return 0; |
||||
} |
@ -0,0 +1,434 @@
@@ -0,0 +1,434 @@
|
||||
#include "cache.h" |
||||
#include "column.h" |
||||
#include "string-list.h" |
||||
#include "parse-options.h" |
||||
#include "run-command.h" |
||||
#include "utf8.h" |
||||
|
||||
#define XY2LINEAR(d, x, y) (COL_LAYOUT((d)->colopts) == COL_COLUMN ? \ |
||||
(x) * (d)->rows + (y) : \ |
||||
(y) * (d)->cols + (x)) |
||||
|
||||
struct column_data { |
||||
const struct string_list *list; |
||||
unsigned int colopts; |
||||
struct column_options opts; |
||||
|
||||
int rows, cols; |
||||
int *len; /* cell length */ |
||||
int *width; /* index to the longest row in column */ |
||||
}; |
||||
|
||||
/* return length of 's' in letters, ANSI escapes stripped */ |
||||
static int item_length(unsigned int colopts, const char *s) |
||||
{ |
||||
int len, i = 0; |
||||
struct strbuf str = STRBUF_INIT; |
||||
|
||||
strbuf_addstr(&str, s); |
||||
while ((s = strstr(str.buf + i, "\033[")) != NULL) { |
||||
int len = strspn(s + 2, "0123456789;"); |
||||
i = s - str.buf; |
||||
strbuf_remove(&str, i, len + 3); /* \033[<len><func char> */ |
||||
} |
||||
len = utf8_strwidth(str.buf); |
||||
strbuf_release(&str); |
||||
return len; |
||||
} |
||||
|
||||
/* |
||||
* Calculate cell width, rows and cols for a table of equal cells, given |
||||
* table width and how many spaces between cells. |
||||
*/ |
||||
static void layout(struct column_data *data, int *width) |
||||
{ |
||||
int i; |
||||
|
||||
*width = 0; |
||||
for (i = 0; i < data->list->nr; i++) |
||||
if (*width < data->len[i]) |
||||
*width = data->len[i]; |
||||
|
||||
*width += data->opts.padding; |
||||
|
||||
data->cols = (data->opts.width - strlen(data->opts.indent)) / *width; |
||||
if (data->cols == 0) |
||||
data->cols = 1; |
||||
|
||||
data->rows = DIV_ROUND_UP(data->list->nr, data->cols); |
||||
} |
||||
|
||||
static void compute_column_width(struct column_data *data) |
||||
{ |
||||
int i, x, y; |
||||
for (x = 0; x < data->cols; x++) { |
||||
data->width[x] = XY2LINEAR(data, x, 0); |
||||
for (y = 0; y < data->rows; y++) { |
||||
i = XY2LINEAR(data, x, y); |
||||
if (i < data->list->nr && |
||||
data->len[data->width[x]] < data->len[i]) |
||||
data->width[x] = i; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* Shrink all columns by shortening them one row each time (and adding |
||||
* more columns along the way). Hopefully the longest cell will be |
||||
* moved to the next column, column is shrunk so we have more space |
||||
* for new columns. The process ends when the whole thing no longer |
||||
* fits in data->total_width. |
||||
*/ |
||||
static void shrink_columns(struct column_data *data) |
||||
{ |
||||
data->width = xrealloc(data->width, |
||||
sizeof(*data->width) * data->cols); |
||||
while (data->rows > 1) { |
||||
int x, total_width, cols, rows; |
||||
rows = data->rows; |
||||
cols = data->cols; |
||||
|
||||
data->rows--; |
||||
data->cols = DIV_ROUND_UP(data->list->nr, data->rows); |
||||
if (data->cols != cols) |
||||
data->width = xrealloc(data->width, |
||||
sizeof(*data->width) * data->cols); |
||||
compute_column_width(data); |
||||
|
||||
total_width = strlen(data->opts.indent); |
||||
for (x = 0; x < data->cols; x++) { |
||||
total_width += data->len[data->width[x]]; |
||||
total_width += data->opts.padding; |
||||
} |
||||
if (total_width > data->opts.width) { |
||||
data->rows = rows; |
||||
data->cols = cols; |
||||
break; |
||||
} |
||||
} |
||||
compute_column_width(data); |
||||
} |
||||
|
||||
/* Display without layout when not enabled */ |
||||
static void display_plain(const struct string_list *list, |
||||
const char *indent, const char *nl) |
||||
{ |
||||
int i; |
||||
|
||||
for (i = 0; i < list->nr; i++) |
||||
printf("%s%s%s", indent, list->items[i].string, nl); |
||||
} |
||||
|
||||
/* Print a cell to stdout with all necessary leading/traling space */ |
||||
static int display_cell(struct column_data *data, int initial_width, |
||||
const char *empty_cell, int x, int y) |
||||
{ |
||||
int i, len, newline; |
||||
|
||||
i = XY2LINEAR(data, x, y); |
||||
if (i >= data->list->nr) |
||||
return -1; |
||||
|
||||
len = data->len[i]; |
||||
if (data->width && data->len[data->width[x]] < initial_width) { |
||||
/* |
||||
* empty_cell has initial_width chars, if real column |
||||
* is narrower, increase len a bit so we fill less |
||||
* space. |
||||
*/ |
||||
len += initial_width - data->len[data->width[x]]; |
||||
len -= data->opts.padding; |
||||
} |
||||
|
||||
if (COL_LAYOUT(data->colopts) == COL_COLUMN) |
||||
newline = i + data->rows >= data->list->nr; |
||||
else |
||||
newline = x == data->cols - 1 || i == data->list->nr - 1; |
||||
|
||||
printf("%s%s%s", |
||||
x == 0 ? data->opts.indent : "", |
||||
data->list->items[i].string, |
||||
newline ? data->opts.nl : empty_cell + len); |
||||
return 0; |
||||
} |
||||
|
||||
/* Display COL_COLUMN or COL_ROW */ |
||||
static void display_table(const struct string_list *list, |
||||
unsigned int colopts, |
||||
const struct column_options *opts) |
||||
{ |
||||
struct column_data data; |
||||
int x, y, i, initial_width; |
||||
char *empty_cell; |
||||
|
||||
memset(&data, 0, sizeof(data)); |
||||
data.list = list; |
||||
data.colopts = colopts; |
||||
data.opts = *opts; |
||||
|
||||
data.len = xmalloc(sizeof(*data.len) * list->nr); |
||||
for (i = 0; i < list->nr; i++) |
||||
data.len[i] = item_length(colopts, list->items[i].string); |
||||
|
||||
layout(&data, &initial_width); |
||||
|
||||
if (colopts & COL_DENSE) |
||||
shrink_columns(&data); |
||||
|
||||
empty_cell = xmalloc(initial_width + 1); |
||||
memset(empty_cell, ' ', initial_width); |
||||
empty_cell[initial_width] = '\0'; |
||||
for (y = 0; y < data.rows; y++) { |
||||
for (x = 0; x < data.cols; x++) |
||||
if (display_cell(&data, initial_width, empty_cell, x, y)) |
||||
break; |
||||
} |
||||
|
||||
free(data.len); |
||||
free(data.width); |
||||
free(empty_cell); |
||||
} |
||||
|
||||
void print_columns(const struct string_list *list, unsigned int colopts, |
||||
const struct column_options *opts) |
||||
{ |
||||
struct column_options nopts; |
||||
|
||||
if (!list->nr) |
||||
return; |
||||
assert((colopts & COL_ENABLE_MASK) != COL_AUTO); |
||||
|
||||
memset(&nopts, 0, sizeof(nopts)); |
||||
nopts.indent = opts && opts->indent ? opts->indent : ""; |
||||
nopts.nl = opts && opts->nl ? opts->nl : "\n"; |
||||
nopts.padding = opts ? opts->padding : 1; |
||||
nopts.width = opts && opts->width ? opts->width : term_columns() - 1; |
||||
if (!column_active(colopts)) { |
||||
display_plain(list, "", "\n"); |
||||
return; |
||||
} |
||||
switch (COL_LAYOUT(colopts)) { |
||||
case COL_PLAIN: |
||||
display_plain(list, nopts.indent, nopts.nl); |
||||
break; |
||||
case COL_ROW: |
||||
case COL_COLUMN: |
||||
display_table(list, colopts, &nopts); |
||||
break; |
||||
default: |
||||
die("BUG: invalid layout mode %d", COL_LAYOUT(colopts)); |
||||
} |
||||
} |
||||
|
||||
int finalize_colopts(unsigned int *colopts, int stdout_is_tty) |
||||
{ |
||||
if ((*colopts & COL_ENABLE_MASK) == COL_AUTO) { |
||||
if (stdout_is_tty < 0) |
||||
stdout_is_tty = isatty(1); |
||||
*colopts &= ~COL_ENABLE_MASK; |
||||
if (stdout_is_tty) |
||||
*colopts |= COL_ENABLED; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
struct colopt { |
||||
const char *name; |
||||
unsigned int value; |
||||
unsigned int mask; |
||||
}; |
||||
|
||||
#define LAYOUT_SET 1 |
||||
#define ENABLE_SET 2 |
||||
|
||||
static int parse_option(const char *arg, int len, unsigned int *colopts, |
||||
int *group_set) |
||||
{ |
||||
struct colopt opts[] = { |
||||
{ "always", COL_ENABLED, COL_ENABLE_MASK }, |
||||
{ "never", COL_DISABLED, COL_ENABLE_MASK }, |
||||
{ "auto", COL_AUTO, COL_ENABLE_MASK }, |
||||
{ "plain", COL_PLAIN, COL_LAYOUT_MASK }, |
||||
{ "column", COL_COLUMN, COL_LAYOUT_MASK }, |
||||
{ "row", COL_ROW, COL_LAYOUT_MASK }, |
||||
{ "dense", COL_DENSE, 0 }, |
||||
}; |
||||
int i; |
||||
|
||||
for (i = 0; i < ARRAY_SIZE(opts); i++) { |
||||
int set = 1, arg_len = len, name_len; |
||||
const char *arg_str = arg; |
||||
|
||||
if (!opts[i].mask) { |
||||
if (arg_len > 2 && !strncmp(arg_str, "no", 2)) { |
||||
arg_str += 2; |
||||
arg_len -= 2; |
||||
set = 0; |
||||
} |
||||
} |
||||
|
||||
name_len = strlen(opts[i].name); |
||||
if (arg_len != name_len || |
||||
strncmp(arg_str, opts[i].name, name_len)) |
||||
continue; |
||||
|
||||
switch (opts[i].mask) { |
||||
case COL_ENABLE_MASK: |
||||
*group_set |= ENABLE_SET; |
||||
break; |
||||
case COL_LAYOUT_MASK: |
||||
*group_set |= LAYOUT_SET; |
||||
break; |
||||
} |
||||
|
||||
if (opts[i].mask) |
||||
*colopts = (*colopts & ~opts[i].mask) | opts[i].value; |
||||
else { |
||||
if (set) |
||||
*colopts |= opts[i].value; |
||||
else |
||||
*colopts &= ~opts[i].value; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
return error("unsupported option '%s'", arg); |
||||
} |
||||
|
||||
static int parse_config(unsigned int *colopts, const char *value) |
||||
{ |
||||
const char *sep = " ,"; |
||||
int group_set = 0; |
||||
|
||||
while (*value) { |
||||
int len = strcspn(value, sep); |
||||
if (len) { |
||||
if (parse_option(value, len, colopts, &group_set)) |
||||
return -1; |
||||
|
||||
value += len; |
||||
} |
||||
value += strspn(value, sep); |
||||
} |
||||
/* |
||||
* Setting layout implies "always" if neither always, never |
||||
* nor auto is specified. |
||||
* |
||||
* Current value in COL_ENABLE_MASK is disregarded. This means if |
||||
* you set column.ui = auto and pass --column=row, then "auto" |
||||
* will become "always". |
||||
*/ |
||||
if ((group_set & LAYOUT_SET) && !(group_set & ENABLE_SET)) |
||||
*colopts = (*colopts & ~COL_ENABLE_MASK) | COL_ENABLED; |
||||
return 0; |
||||
} |
||||
|
||||
static int column_config(const char *var, const char *value, |
||||
const char *key, unsigned int *colopts) |
||||
{ |
||||
if (!value) |
||||
return config_error_nonbool(var); |
||||
if (parse_config(colopts, value)) |
||||
return error("invalid column.%s mode %s", key, value); |
||||
return 0; |
||||
} |
||||
|
||||
int git_column_config(const char *var, const char *value, |
||||
const char *command, unsigned int *colopts) |
||||
{ |
||||
const char *it = skip_prefix(var, "column."); |
||||
if (!it) |
||||
return 0; |
||||
|
||||
if (!strcmp(it, "ui")) |
||||
return column_config(var, value, "ui", colopts); |
||||
|
||||
if (command && !strcmp(it, command)) |
||||
return column_config(var, value, it, colopts); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
int parseopt_column_callback(const struct option *opt, |
||||
const char *arg, int unset) |
||||
{ |
||||
unsigned int *colopts = opt->value; |
||||
*colopts |= COL_PARSEOPT; |
||||
*colopts &= ~COL_ENABLE_MASK; |
||||
if (unset) /* --no-column == never */ |
||||
return 0; |
||||
/* --column == always unless "arg" states otherwise */ |
||||
*colopts |= COL_ENABLED; |
||||
if (arg) |
||||
return parse_config(colopts, arg); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int fd_out = -1; |
||||
static struct child_process column_process; |
||||
|
||||
int run_column_filter(int colopts, const struct column_options *opts) |
||||
{ |
||||
const char *av[10]; |
||||
int ret, ac = 0; |
||||
struct strbuf sb_colopt = STRBUF_INIT; |
||||
struct strbuf sb_width = STRBUF_INIT; |
||||
struct strbuf sb_padding = STRBUF_INIT; |
||||
|
||||
if (fd_out != -1) |
||||
return -1; |
||||
|
||||
av[ac++] = "column"; |
||||
strbuf_addf(&sb_colopt, "--raw-mode=%d", colopts); |
||||
av[ac++] = sb_colopt.buf; |
||||
if (opts && opts->width) { |
||||
strbuf_addf(&sb_width, "--width=%d", opts->width); |
||||
av[ac++] = sb_width.buf; |
||||
} |
||||
if (opts && opts->indent) { |
||||
av[ac++] = "--indent"; |
||||
av[ac++] = opts->indent; |
||||
} |
||||
if (opts && opts->padding) { |
||||
strbuf_addf(&sb_padding, "--padding=%d", opts->padding); |
||||
av[ac++] = sb_padding.buf; |
||||
} |
||||
av[ac] = NULL; |
||||
|
||||
fflush(stdout); |
||||
memset(&column_process, 0, sizeof(column_process)); |
||||
column_process.in = -1; |
||||
column_process.out = dup(1); |
||||
column_process.git_cmd = 1; |
||||
column_process.argv = av; |
||||
|
||||
ret = start_command(&column_process); |
||||
|
||||
strbuf_release(&sb_colopt); |
||||
strbuf_release(&sb_width); |
||||
strbuf_release(&sb_padding); |
||||
|
||||
if (ret) |
||||
return -2; |
||||
|
||||
fd_out = dup(1); |
||||
close(1); |
||||
dup2(column_process.in, 1); |
||||
close(column_process.in); |
||||
return 0; |
||||
} |
||||
|
||||
int stop_column_filter(void) |
||||
{ |
||||
if (fd_out == -1) |
||||
return -1; |
||||
|
||||
fflush(stdout); |
||||
close(1); |
||||
finish_command(&column_process); |
||||
dup2(fd_out, 1); |
||||
close(fd_out); |
||||
fd_out = -1; |
||||
return 0; |
||||
} |
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
#ifndef COLUMN_H |
||||
#define COLUMN_H |
||||
|
||||
#define COL_LAYOUT_MASK 0x000F |
||||
#define COL_ENABLE_MASK 0x0030 /* always, never or auto */ |
||||
#define COL_PARSEOPT 0x0040 /* --column is given from cmdline */ |
||||
#define COL_DENSE 0x0080 /* Shrink columns when possible, |
||||
making space for more columns */ |
||||
|
||||
#define COL_DISABLED 0x0000 /* must be zero */ |
||||
#define COL_ENABLED 0x0010 |
||||
#define COL_AUTO 0x0020 |
||||
|
||||
#define COL_LAYOUT(c) ((c) & COL_LAYOUT_MASK) |
||||
#define COL_COLUMN 0 /* Fill columns before rows */ |
||||
#define COL_ROW 1 /* Fill rows before columns */ |
||||
#define COL_PLAIN 15 /* one column */ |
||||
|
||||
#define explicitly_enable_column(c) \ |
||||
(((c) & COL_PARSEOPT) && column_active(c)) |
||||
|
||||
struct column_options { |
||||
int width; |
||||
int padding; |
||||
const char *indent; |
||||
const char *nl; |
||||
}; |
||||
|
||||
struct option; |
||||
extern int parseopt_column_callback(const struct option *, const char *, int); |
||||
extern int git_column_config(const char *var, const char *value, |
||||
const char *command, unsigned int *colopts); |
||||
extern int finalize_colopts(unsigned int *colopts, int stdout_is_tty); |
||||
static inline int column_active(unsigned int colopts) |
||||
{ |
||||
return (colopts & COL_ENABLE_MASK) == COL_ENABLED; |
||||
} |
||||
|
||||
extern void print_columns(const struct string_list *list, unsigned int colopts, |
||||
const struct column_options *opts); |
||||
|
||||
extern int run_column_filter(int colopts, const struct column_options *); |
||||
extern int stop_column_filter(void); |
||||
|
||||
#endif |
@ -0,0 +1,180 @@
@@ -0,0 +1,180 @@
|
||||
#!/bin/sh |
||||
|
||||
test_description='git column' |
||||
. ./test-lib.sh |
||||
|
||||
test_expect_success 'setup' ' |
||||
cat >lista <<\EOF |
||||
one |
||||
two |
||||
three |
||||
four |
||||
five |
||||
six |
||||
seven |
||||
eight |
||||
nine |
||||
ten |
||||
eleven |
||||
EOF |
||||
' |
||||
|
||||
test_expect_success 'never' ' |
||||
git column --indent=Z --mode=never <lista >actual && |
||||
test_cmp lista actual |
||||
' |
||||
|
||||
test_expect_success 'always' ' |
||||
cat >expected <<\EOF && |
||||
Zone |
||||
Ztwo |
||||
Zthree |
||||
Zfour |
||||
Zfive |
||||
Zsix |
||||
Zseven |
||||
Zeight |
||||
Znine |
||||
Zten |
||||
Zeleven |
||||
EOF |
||||
git column --indent=Z --mode=plain <lista >actual && |
||||
test_cmp expected actual |
||||
' |
||||
|
||||
test_expect_success '80 columns' ' |
||||
cat >expected <<\EOF && |
||||
one two three four five six seven eight nine ten eleven |
||||
EOF |
||||
COLUMNS=80 git column --mode=column <lista >actual && |
||||
test_cmp expected actual |
||||
' |
||||
|
||||
cat >expected <<\EOF |
||||
one |
||||
two |
||||
three |
||||
four |
||||
five |
||||
six |
||||
seven |
||||
eight |
||||
nine |
||||
ten |
||||
eleven |
||||
EOF |
||||
|
||||
test_expect_success COLUMNS_CAN_BE_1 'COLUMNS = 1' ' |
||||
COLUMNS=1 git column --mode=column <lista >actual && |
||||
test_cmp expected actual |
||||
' |
||||
|
||||
test_expect_success 'width = 1' ' |
||||
git column --mode=column --width=1 <lista >actual && |
||||
test_cmp expected actual |
||||
' |
||||
|
||||
COLUMNS=20 |
||||
export COLUMNS |
||||
|
||||
test_expect_success '20 columns' ' |
||||
cat >expected <<\EOF && |
||||
one seven |
||||
two eight |
||||
three nine |
||||
four ten |
||||
five eleven |
||||
six |
||||
EOF |
||||
git column --mode=column <lista >actual && |
||||
test_cmp expected actual |
||||
' |
||||
|
||||
test_expect_success '20 columns, nodense' ' |
||||
cat >expected <<\EOF && |
||||
one seven |
||||
two eight |
||||
three nine |
||||
four ten |
||||
five eleven |
||||
six |
||||
EOF |
||||
git column --mode=column,nodense < lista > actual && |
||||
test_cmp expected actual |
||||
' |
||||
|
||||
test_expect_success '20 columns, dense' ' |
||||
cat >expected <<\EOF && |
||||
one five nine |
||||
two six ten |
||||
three seven eleven |
||||
four eight |
||||
EOF |
||||
git column --mode=column,dense < lista > actual && |
||||
test_cmp expected actual |
||||
' |
||||
|
||||
test_expect_success '20 columns, padding 2' ' |
||||
cat >expected <<\EOF && |
||||
one seven |
||||
two eight |
||||
three nine |
||||
four ten |
||||
five eleven |
||||
six |
||||
EOF |
||||
git column --mode=column --padding 2 <lista >actual && |
||||
test_cmp expected actual |
||||
' |
||||
|
||||
test_expect_success '20 columns, indented' ' |
||||
cat >expected <<\EOF && |
||||
one seven |
||||
two eight |
||||
three nine |
||||
four ten |
||||
five eleven |
||||
six |
||||
EOF |
||||
git column --mode=column --indent=" " <lista >actual && |
||||
test_cmp expected actual |
||||
' |
||||
|
||||
test_expect_success '20 columns, row first' ' |
||||
cat >expected <<\EOF && |
||||
one two |
||||
three four |
||||
five six |
||||
seven eight |
||||
nine ten |
||||
eleven |
||||
EOF |
||||
git column --mode=row <lista >actual && |
||||
test_cmp expected actual |
||||
' |
||||
|
||||
test_expect_success '20 columns, row first, nodense' ' |
||||
cat >expected <<\EOF && |
||||
one two |
||||
three four |
||||
five six |
||||
seven eight |
||||
nine ten |
||||
eleven |
||||
EOF |
||||
git column --mode=row,nodense <lista >actual && |
||||
test_cmp expected actual |
||||
' |
||||
|
||||
test_expect_success '20 columns, row first, dense' ' |
||||
cat >expected <<\EOF && |
||||
one two three |
||||
four five six |
||||
seven eight nine |
||||
ten eleven |
||||
EOF |
||||
git column --mode=row,dense <lista >actual && |
||||
test_cmp expected actual |
||||
' |
||||
|
||||
test_done |
Loading…
Reference in new issue