1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

format-table: trivial cleanups (#35572)

This commit is contained in:
Yu Watanabe 2024-12-12 06:12:07 +09:00 committed by GitHub
commit 4899255aa2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 17 deletions

View File

@ -170,7 +170,7 @@ Table *table_new_raw(size_t n_columns) {
if (!t)
return NULL;
*t = (struct Table) {
*t = (Table) {
.n_columns = n_columns,
.header = true,
.width = SIZE_MAX,
@ -1348,7 +1348,7 @@ int table_hide_column_from_display_internal(Table *t, ...) {
return r;
}
for (size_t i = 0; i < t->n_display_map; i++) {
FOREACH_ARRAY(i, t->display_map, t->n_display_map) {
bool listed = false;
va_list ap;
@ -1359,7 +1359,7 @@ int table_hide_column_from_display_internal(Table *t, ...) {
column = va_arg(ap, size_t);
if (column == SIZE_MAX)
break;
if (column == t->display_map[i]) {
if (column == *i) {
listed = true;
break;
}
@ -1369,7 +1369,7 @@ int table_hide_column_from_display_internal(Table *t, ...) {
if (listed)
continue;
t->display_map[cur++] = t->display_map[i];
t->display_map[cur++] = *i;
}
t->n_display_map = cur;
@ -2190,7 +2190,7 @@ static char *align_string_mem(const char *str, const char *url, size_t new_lengt
return ret;
}
static bool table_data_isempty(TableData *d) {
static bool table_data_isempty(const TableData *d) {
assert(d);
if (d->type == TABLE_EMPTY)
@ -2204,7 +2204,7 @@ static bool table_data_isempty(TableData *d) {
return false;
}
static const char* table_data_color(TableData *d) {
static const char* table_data_color(const TableData *d) {
assert(d);
if (d->color)
@ -2220,17 +2220,11 @@ static const char* table_data_color(TableData *d) {
return NULL;
}
static const char* table_data_rgap_color(TableData *d) {
assert(d);
return d->rgap_color ?: d->rgap_color;
}
static const char* table_data_underline(TableData *d) {
static const char* table_data_underline(const TableData *d) {
assert(d);
if (d->underline)
return /* cescape( */ansi_add_underline_grey()/* ) */;
return ansi_add_underline_grey();
if (d->type == TABLE_HEADER)
return ansi_add_underline();
@ -2238,7 +2232,7 @@ static const char* table_data_underline(TableData *d) {
return NULL;
}
static const char* table_data_rgap_underline(TableData *d) {
static const char* table_data_rgap_underline(const TableData *d) {
assert(d);
if (d->rgap_underline)
@ -2642,7 +2636,7 @@ int table_print(Table *t, FILE *f) {
if (color || underline)
fputs(ANSI_NORMAL, f);
gap_color = table_data_rgap_color(d);
gap_color = d->rgap_color;
gap_underline = table_data_rgap_underline(d);
}

View File

@ -1035,7 +1035,7 @@ static int display_services(int argc, char *argv[], void *userdata) {
r = table_add_many(t,
TABLE_STRING, de->d_name,
TABLE_STRING, no ?: "yes",
TABLE_SET_COLOR, no ? ansi_highlight_red() : ansi_highlight_green());
TABLE_SET_COLOR, ansi_highlight_green_red(!no));
if (r < 0)
return table_log_add_error(r);
}