unsigned ellipsize_percent; /* 0 … 100, where to place the ellipsis when compression is needed */
unsigned align_percent; /* 0 … 100, where to pad with spaces when expanding is needed. 0: left-aligned, 100: right-aligned */
- bool uppercase; /* Uppercase string on display */
+ bool uppercase:1; /* Uppercase string on display */
+ bool underline:1;
+ bool rgap_underline:1;
const char *color; /* ANSI color string to use for this cell. When written to terminal should not move cursor. Will automatically be reset after the cell */
const char *rgap_color; /* The ANSI color to use for the gap right of this cell. Usually used to underline entire rows in a gapless fashion */
return false;
/* If a color/url is set, refuse to merge */
- if (d->color || d->rgap_color)
+ if (d->color || d->rgap_color || d->underline || d->rgap_underline)
return false;
if (d->url)
return false;
nd->color = od->color;
nd->rgap_color = od->rgap_color;
+ nd->underline = od->underline;
+ nd->rgap_underline = od->rgap_underline;
nd->url = TAKE_PTR(curl);
table_data_unref(od);
return 0;
}
+int table_set_underline(Table *t, TableCell *cell, bool b) {
+ TableData *d;
+ int r;
+
+ assert(t);
+ assert(cell);
+
+ r = table_dedup_cell(t, cell);
+ if (r < 0)
+ return r;
+
+ assert_se(d = table_get_data(t, cell));
+
+ if (d->underline == b)
+ return 0;
+
+ d->underline = b;
+ return 1;
+}
+
+int table_set_rgap_underline(Table *t, TableCell *cell, bool b) {
+ TableData *d;
+ int r;
+
+ assert(t);
+ assert(cell);
+
+ r = table_dedup_cell(t, cell);
+ if (r < 0)
+ return r;
+
+ assert_se(d = table_get_data(t, cell));
+
+ if (d->rgap_underline == b)
+ return 0;
+
+ d->rgap_underline = b;
+ return 1;
+}
+
int table_set_url(Table *t, TableCell *cell, const char *url) {
_cleanup_free_ char *copy = NULL;
int r;
nd->color = od->color;
nd->rgap_color = od->rgap_color;
+ nd->underline = od->underline;
+ nd->rgap_underline = od->rgap_underline;
nd->url = TAKE_PTR(curl);
table_data_unref(od);
goto check;
}
+ case TABLE_SET_UNDERLINE: {
+ int u = va_arg(ap, int);
+ r = table_set_underline(t, last_cell, u);
+ goto check;
+ }
+
+ case TABLE_SET_RGAP_UNDERLINE: {
+ int u = va_arg(ap, int);
+ r = table_set_rgap_underline(t, last_cell, u);
+ goto check;
+ }
+
+ case TABLE_SET_BOTH_UNDERLINES: {
+ int u = va_arg(ap, int);
+
+ r = table_set_underline(t, last_cell, u);
+ if (r < 0) {
+ va_end(ap);
+ return r;
+ }
+
+ r = table_set_rgap_underline(t, last_cell, u);
+ goto check;
+ }
+
case TABLE_SET_URL: {
const char *u = va_arg(ap, const char*);
r = table_set_url(t, last_cell, u);
if (d->type == TABLE_FIELD)
return ansi_bright_blue();
- if (d->type == TABLE_HEADER)
- return ansi_underline();
return NULL;
}
static const char* table_data_rgap_color(TableData *d) {
assert(d);
- if (d->rgap_color)
- return d->rgap_color;
+ return d->rgap_color ?: d->rgap_color;
+}
+
+static const char* table_data_underline(TableData *d) {
+ assert(d);
+
+ if (d->underline)
+ return /* cescape( */ansi_add_underline_grey()/* ) */;
if (d->type == TABLE_HEADER)
- return ansi_underline();
+ return ansi_add_underline();
+
+ return NULL;
+}
+
+static const char* table_data_rgap_underline(TableData *d) {
+ assert(d);
+
+ if (d->rgap_underline)
+ return ansi_add_underline_grey();
+
+ if (d->type == TABLE_HEADER)
+ return ansi_add_underline();
return NULL;
}
row = t->data + i * t->n_columns;
do {
- const char *gap_color = NULL;
+ const char *gap_color = NULL, *gap_underline = NULL;
more_sublines = false;
for (size_t j = 0; j < display_columns; j++) {
_cleanup_free_ char *buffer = NULL, *extracted = NULL;
bool lines_truncated = false;
- const char *field, *color = NULL;
+ const char *field, *color = NULL, *underline = NULL;
TableData *d;
size_t l;
/* Drop trailing white spaces of last column when no cosmetics is set. */
if (j == display_columns - 1 &&
(!colors_enabled() || !table_data_color(d)) &&
+ (!underline_enabled() || !table_data_underline(d)) &&
(!urlify_enabled() || !d->url))
delete_trailing_chars(aligned, NULL);
if (colors_enabled() && gap_color)
fputs(gap_color, f);
+ if (underline_enabled() && gap_underline)
+ fputs(gap_underline, f);
if (j > 0)
fputc(' ', f); /* column separator left of cell */
+ /* Undo gap color/underline */
+ if ((colors_enabled() && gap_color) ||
+ (underline_enabled() && gap_underline))
+ fputs(ANSI_NORMAL, f);
+
if (colors_enabled()) {
color = table_data_color(d);
-
- /* Undo gap color */
- if (gap_color)
- fputs(ANSI_NORMAL, f);
-
if (color)
fputs(color, f);
}
+ if (underline_enabled()) {
+ underline = table_data_underline(d);
+ if (underline)
+ fputs(underline, f);
+ }
+
fputs(field, f);
- if (colors_enabled() && color)
+ if (color || underline)
fputs(ANSI_NORMAL, f);
gap_color = table_data_rgap_color(d);
+ gap_underline = table_data_rgap_underline(d);
}
fputc('\n', f);