Note that items with (!) have high priority.
-libsmartcols
-------------
- - (!) add libscols_column->json_type and scols_column_set_jsontype()
- to generate proper JSON output. Now the library uses quotes (= all is
- string) for everything. See for example SIZE in "lsblk --json --bytes"
- output.
-
cal
---
- add option to print calendar in vertical way
scols_column_get_color
scols_column_get_flags
scols_column_get_header
+scols_column_get_json_type
scols_column_get_safechars
scols_column_get_table
scols_column_get_whint
scols_column_set_cmpfunc
scols_column_set_color
scols_column_set_flags
+scols_column_set_json_type
scols_column_set_safechars
scols_column_set_whint
scols_column_set_wrapfunc
return 0;
}
+/**
+ * scols_column_set_json_type:
+ * @cl: a pointer to a struct libscols_column instance
+ * @type: SCOLS_JSON_* type
+ *
+ * Sets the type used for JSON formatting, the default is SCOLS_JSON_STRING.
+ *
+ * Returns: 0, a negative value in case of an error.
+ *
+ * Since: 2.33
+ */
+int scols_column_set_json_type(struct libscols_column *cl, int type)
+{
+ if (!cl)
+ return -EINVAL;
+
+ cl->json_type = type;
+ return 0;
+
+}
+
+/**
+ * scols_column_get_json_type:
+ * @cl: a pointer to a struct libscols_column instance
+ *
+ * Note that SCOLS_JSON_BOOLEAN interprets NULL, empty strings, '0', 'N' and
+ * 'n' as "false"; and everything else as "true".
+ *
+ * Returns: JSON type used for formatting or a negative value in case of an error.
+ *
+ * Since: 2.33
+ */
+int scols_column_get_json_type(const struct libscols_column *cl)
+{
+ return cl ? cl->json_type : -EINVAL;
+}
+
+
/**
* scols_column_get_table:
* @cl: a pointer to a struct libscols_column instance
SCOLS_FL_WRAP = (1 << 6) /* wrap long lines to multi-line cells */
};
+/*
+ * Column JSON types
+ */
+enum {
+ SCOLS_JSON_STRING = 0, /* default */
+ SCOLS_JSON_NUMBER = 1,
+ SCOLS_JSON_BOOLEAN = 2
+};
+
/*
* Cell flags, see scols_cell_set_flags() before use
*/
extern int scols_column_set_safechars(struct libscols_column *cl, const char *safe);
extern const char *scols_column_get_safechars(const struct libscols_column *cl);
+extern int scols_column_set_json_type(struct libscols_column *cl, int type);
+extern int scols_column_get_json_type(const struct libscols_column *cl);
+
extern int scols_column_set_flags(struct libscols_column *cl, int flags);
extern int scols_column_get_flags(const struct libscols_column *cl);
extern struct libscols_column *scols_new_column(void);
scols_table_enable_noencoding;
scols_table_is_noencoding;
} SMARTCOLS_2.30;
+
+
+SMARTCOLS_2.33 {
+ scols_column_set_json_type;
+ scols_column_get_json_type;
+} SMARTCOLS_2.31;
size_t width_treeart; /* size of the tree ascii art */
double width_hint; /* hint (N < 1 is in percent of termwidth) */
+ int json_type; /* SCOLS_JSON_* */
+
int flags;
int is_extreme;
char *color; /* default column color */
case SCOLS_FMT_JSON:
fputs_quoted_json_lower(scols_cell_get_data(&cl->header), tb->out);
- fputs(": ", tb->out);
+ fputs(":", tb->out);
if (!*data)
fputs("null", tb->out);
- else
- fputs_quoted_json(data, tb->out);
+ else switch (cl->json_type) {
+ case SCOLS_JSON_STRING:
+ fputs_quoted_json(data, tb->out);
+ break;
+ case SCOLS_JSON_NUMBER:
+ fputs(data, tb->out);
+ break;
+ case SCOLS_JSON_BOOLEAN:
+ fputs(!*data ? "false" :
+ *data == '0' ? "false" :
+ *data == 'N' || *data == 'n' ? "false" : "true",
+ tb->out);
+ break;
+ }
if (!is_last)
fputs(", ", tb->out);
return 0;