return fflush_and_check(f);
}
+
+int table_print_with_pager(
+ Table *t,
+ JsonFormatFlags json_format_flags,
+ PagerFlags pager_flags,
+ bool show_header) {
+
+ bool saved_header;
+ int r;
+
+ assert(t);
+
+ /* A all-in-one solution for showing tables, and turning on a pager first. Also optionally suppresses
+ * the table header and logs about any error. */
+
+ if (json_format_flags & (JSON_FORMAT_OFF|JSON_FORMAT_PRETTY|JSON_FORMAT_PRETTY_AUTO))
+ (void) pager_open(pager_flags);
+
+ saved_header = t->header;
+ t->header = show_header;
+ r = table_print_json(t, stdout, json_format_flags);
+ t->header = saved_header;
+ if (r < 0)
+ return table_log_print_error(r);
+
+ return 0;
+}
#include "json.h"
#include "macro.h"
+#include "pager.h"
typedef enum TableDataType {
TABLE_EMPTY,
int table_to_json(Table *t, JsonVariant **ret);
int table_print_json(Table *t, FILE *f, JsonFormatFlags json_flags);
+int table_print_with_pager(Table *t, JsonFormatFlags json_format_flags, PagerFlags pager_flags, bool show_header);
+
#define table_log_add_error(r) \
log_error_errno(r, "Failed to add cell(s) to table: %m")