format-table: add table_update() to update existing entries
This commit is contained in:
parent
a2c73e2d38
commit
27e730e6d0
|
@ -574,6 +574,46 @@ int table_set_url(Table *t, TableCell *cell, const char *url) {
|
|||
return free_and_replace(table_get_data(t, cell)->url, copy);
|
||||
}
|
||||
|
||||
int table_update(Table *t, TableCell *cell, TableDataType type, const void *data) {
|
||||
_cleanup_free_ char *curl = NULL;
|
||||
TableData *nd, *od;
|
||||
size_t i;
|
||||
|
||||
assert(t);
|
||||
assert(cell);
|
||||
|
||||
i = TABLE_CELL_TO_INDEX(cell);
|
||||
if (i >= t->n_cells)
|
||||
return -ENXIO;
|
||||
|
||||
assert_se(od = t->data[i]);
|
||||
|
||||
if (od->url) {
|
||||
curl = strdup(od->url);
|
||||
if (!curl)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
nd = table_data_new(
|
||||
type,
|
||||
data,
|
||||
od->minimum_width,
|
||||
od->maximum_width,
|
||||
od->weight,
|
||||
od->align_percent,
|
||||
od->ellipsize_percent);
|
||||
if (!nd)
|
||||
return -ENOMEM;
|
||||
|
||||
nd->color = od->color;
|
||||
nd->url = TAKE_PTR(curl);
|
||||
|
||||
table_data_unref(od);
|
||||
t->data[i] = nd;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int table_add_many_internal(Table *t, TableDataType first_type, ...) {
|
||||
TableDataType type;
|
||||
va_list ap;
|
||||
|
|
|
@ -46,6 +46,8 @@ int table_set_ellipsize_percent(Table *t, TableCell *cell, unsigned percent);
|
|||
int table_set_color(Table *t, TableCell *cell, const char *color);
|
||||
int table_set_url(Table *t, TableCell *cell, const char *color);
|
||||
|
||||
int table_update(Table *t, TableCell *cell, TableDataType type, const void *data);
|
||||
|
||||
int table_add_many_internal(Table *t, TableDataType first_type, ...);
|
||||
#define table_add_many(t, ...) table_add_many_internal(t, __VA_ARGS__, _TABLE_DATA_TYPE_MAX)
|
||||
|
||||
|
|
Loading…
Reference in New Issue