]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: add function to set/get header colors
authorKarel Zak <kzak@redhat.com>
Tue, 15 Jul 2025 13:37:56 +0000 (15:37 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 15 Jul 2025 13:37:56 +0000 (15:37 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/docs/libsmartcols-sections.txt
libsmartcols/src/column.c
libsmartcols/src/libsmartcols.h.in
libsmartcols/src/libsmartcols.sym

index e7fe4b75d5d940b9dd61404f44872ff3089a14f9..da4b8c8f42abfd11c7641a588aa4e5beb8047c90 100644 (file)
@@ -28,6 +28,7 @@ scols_column_get_color
 scols_column_get_data_type
 scols_column_get_flags
 scols_column_get_header
+scols_column_get_headercolor
 scols_column_get_json_type
 scols_column_get_name
 scols_column_get_name_as_shellvar
@@ -51,6 +52,7 @@ scols_column_set_color
 scols_column_set_data_func
 scols_column_set_data_type
 scols_column_set_flags
+scols_column_set_headercolor
 scols_column_set_json_type
 scols_column_set_name
 scols_column_set_properties
index e83d297fc5ea9e2b358d83517e93a78f5ef43707..5d5cb0aa6c9b5d16e0987db2d9c890ea3110642b 100644 (file)
@@ -319,6 +319,44 @@ const char *scols_column_get_name(struct libscols_column *cl)
        return scols_cell_get_data(&cl->header);
 }
 
+/**
+ * scols_column_set_headercolor:
+ * @cl: a pointer to a struct libscols_column instance
+ * @color: color name or ESC sequence
+ *
+ * The set header color.
+ *
+ * Returns: 0, a negative value in case of an error.
+ *
+ * Since: 2.42
+ */
+int scols_column_set_headercolor(struct libscols_column *cl, const char *color)
+{
+       struct libscols_cell *hdr = scols_column_get_header(cl);
+
+       if (!hdr)
+               return -EINVAL;
+
+       return scols_cell_set_color(hdr, color);
+}
+
+/**
+ * scols_column_get_headercolor:
+ * @cl: a pointer to a struct libscols_column instance
+ *
+ * Returns: The current color setting of the column header or NULL.
+ *
+ * Since: 2.42
+ */
+const char *scols_column_get_headercolor(struct libscols_column *cl)
+{
+       struct libscols_cell *hdr = scols_column_get_header(cl);
+
+       if (hdr)
+               return scols_cell_get_color(hdr);
+       return NULL;
+}
+
 /**
  * scols_shellvar_name:
  * @name: raw (column) name
@@ -404,7 +442,7 @@ const char *scols_column_get_name_as_shellvar(struct libscols_column *cl)
  * The default color for data cells and column header.
  *
  * If you want to set header specific color then use scols_column_get_header()
- * and scols_cell_set_color().
+ * and scols_cell_set_color() or scols_column_set_headercolor() since v2.42.
  *
  * If you want to set data cell specific color the use scols_line_get_cell() +
  * scols_cell_set_color().
@@ -877,8 +915,10 @@ int scols_column_is_customwrap(const struct libscols_column *cl)
  * @cl: a pointer to a struct libscols_column instance
  * @opts: options string
  *
- * Set properties from string, the string is comma separated list, like
- * "trunc,right,json=number", ...
+ * Set properties from string, the string is comma separated list. Supported
+ * properties are: trunc, tree, right, strictwidth, noextremes, hidden, wrap,
+ * wrapnl, wrapzero,json={string,number,float,array-string,array-number,boolean},
+ * width=, color=, headercolor= and name=.
  *
  * Returns: 0 on success, <0 on error
  *
@@ -964,6 +1004,14 @@ int scols_column_set_properties(struct libscols_column *cl, const char *opts)
                                free(x);
                        }
 
+               } else if (value && strncmp(name, "headercolor", namesz) == 0) {
+
+                       char *x = strndup(value, valuesz);
+                       if (x) {
+                               scols_column_set_headercolor(cl, x);
+                               free(x);
+                       }
+
                } else if (value && strncmp(name, "name", namesz) == 0) {
 
                        char *x = strndup(value, valuesz);
index abb9cdd6c1c9bfc57cfd1cce0d647b6dd2b6571d..3fbe668d3f0666752b5d3bdd152570115fa64788 100644 (file)
@@ -250,7 +250,11 @@ extern void scols_unref_column(struct libscols_column *cl);
 extern struct libscols_column *scols_copy_column(const struct libscols_column *cl);
 extern int scols_column_set_whint(struct libscols_column *cl, double whint);
 extern double scols_column_get_whint(const struct libscols_column *cl);
+
 extern struct libscols_cell *scols_column_get_header(struct libscols_column *cl);
+extern int scols_column_set_headercolor(struct libscols_column *cl, const char *color);
+extern const char *scols_column_get_headercolor(struct libscols_column *cl);
+
 extern int scols_column_set_color(struct libscols_column *cl, const char *color);
 extern const char *scols_column_get_color(const struct libscols_column *cl);
 extern struct libscols_table *scols_column_get_table(const struct libscols_column *cl);
index 6fe8f618790f4b7d4e3fffe879333ed011987e87..1f782fdc6c55272c95494607ebeda1fd68d2e0ff 100644 (file)
@@ -259,5 +259,7 @@ SMARTCOLS_2.41 {
 
 SMARTCOLS_2.42 {
        scols_filter_has_holder;
+       scols_column_set_headercolor;
+       scols_column_get_headercolor;
 } SMARTCOLS_2.41;