From 75c1674eca61c35e758a0bd716f63e2cb58fc206 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 1 Oct 2025 15:37:31 +0200 Subject: [PATCH] libsmartcols: small uri and annotation cleanup - use scols_column_get_uri() and scols_cell_get_uri() - don't read annotation or URI when unnecessary Signed-off-by: Karel Zak --- libsmartcols/src/print.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/libsmartcols/src/print.c b/libsmartcols/src/print.c index fffbe6a7f..a2c736cca 100644 --- a/libsmartcols/src/print.c +++ b/libsmartcols/src/print.c @@ -321,18 +321,18 @@ static const char *mk_cell_uri(struct libscols_column *cl, struct libscols_cell *ce, struct ul_buffer *buf) { - char *path; + const char *path; /* URI disabled at all */ if (ce->no_uri) return NULL; - /* No column prefix, return cell URI (or NULL if undefined) */ - if (!cl->uri) - return ce->uri; + /* No column prefix, return cell's URI (or NULL if undefined) */ + if (!scols_column_get_uri(cl)) + return scols_cell_get_uri(ce); - /* Compose URI from column-uri + path. The path is ce->uri or cell data. */ - path = ce->uri; + /* Compose URI from column's URI + path. The path is cell's URI or cell data. */ + path = scols_cell_get_uri(ce); if (!path && buf) { /* The buffer may already contain tree data, so we need to skip it. */ @@ -470,7 +470,7 @@ static int print_pending_data(struct libscols_table *tb, struct ul_buffer *buf) DBG(COL, ul_debugobj(cl, "printing pending data")); - if (cl->uri || ce->uri) + if (scols_column_get_uri(cl) || scols_cell_get_uri(ce)) uri = mk_cell_uri(cl, ce, buf); if (scols_table_is_noencoding(tb)) @@ -638,11 +638,14 @@ static int print_data(struct libscols_table *tb, struct ul_buffer *buf) break; /* continue below */ } - if (cl->uri || ce->uri) + if (!ln) { + /* column header */ + annot = scols_column_get_annotation(cl); + } else if (scols_column_get_uri(cl) || scols_cell_get_uri(ce)) { + /* column data */ uri = mk_cell_uri(cl, ce, buf); + } - if (cl->annotation) - annot = scols_column_get_annotation(cl); /* Encode. Note that 'len' and 'width' are number of glyphs not bytes. */ @@ -703,8 +706,8 @@ static int print_data(struct libscols_table *tb, struct ul_buffer *buf) fputc(data[i], tb->out); } ul_fputs_hyperlink(uri, link, tb->out); - } else if (!ln && annot && *annot) { - /* Printing the header with a column annotation as tooltip */ + + } else if (annot && *annot) { ul_fputs_hyperlink(annot, data, tb->out); } else { fputs(data, tb->out); @@ -1063,7 +1066,7 @@ int __scols_print_header(struct libscols_table *tb, struct ul_buffer *buf) continue; ul_buffer_reset_data(buf); - if (cl->uri) + if (scols_column_get_uri(cl)) scols_cell_disable_uri(&cl->header, 1); scols_table_set_cursor(tb, NULL, cl, &cl->header); -- 2.47.3