scols_table_enable_json
scols_table_enable_maxout
scols_table_enable_noheadings
+scols_table_enable_nolinesep
scols_table_enable_nowrap
scols_table_enable_raw
scols_table_get_column
* @ce: a pointer to a struct libscols_cell instance
* @str: data (used for scols_print_table())
*
- * Stores a copy of the @str in @ce.
+ * Stores a copy of the @str in @ce, the old data are deallocated by free().
*
* Returns: 0, a negative value in case of an error.
*/
extern int scols_table_enable_export(struct libscols_table *tb, int enable);
extern int scols_table_enable_maxout(struct libscols_table *tb, int enable);
extern int scols_table_enable_nowrap(struct libscols_table *tb, int enable);
+extern int scols_table_enable_nolinesep(struct libscols_table *tb, int enable);
extern int scols_table_set_column_separator(struct libscols_table *tb, const char *sep);
extern int scols_table_set_line_separator(struct libscols_table *tb, const char *sep);
scols_cell_get_flags;
scols_cell_set_flags;
scols_table_print_range;
+ scols_table_enable_nolinesep;
} SMARTCOLS_2.27;
colors_wanted :1, /* enable colors */
is_term :1, /* isatty() */
maxout :1, /* maximalize output */
+ header_printed :1, /* header already printed */
no_headings :1, /* don't print header */
+ no_linesep :1, /* don't print line separator */
no_wrap :1; /* never wrap lines */
};
return 0;
}
+/**
+ * scols_table_enable_nolinesep
+ * @tb: table
+ * @enable: 1 or 0
+ *
+ * Enable/disable line separator printing. This is usefull if you want to
+ * re-printing the same line more than once (e.g. progress bar). Don't use it
+ * if you're not sure.
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+int scols_table_enable_nolinesep(struct libscols_table *tb, int enable)
+{
+ if (!tb)
+ return -EINVAL;
+
+ DBG(TAB, ul_debugobj(tb, "nolinesep: %s", enable ? "ENABLE" : "DISABLE"));
+ tb->no_linesep = enable;
+ return 0;
+}
+
/**
* scols_table_enable_colors:
* @tb: table
fput_indent(tb);
fputs(last ? "}" : "},", tb->out);
}
- fputs(linesep(tb), tb->out);
+ if (!tb->no_linesep)
+ fputs(linesep(tb), tb->out);
tb->indent_last_sep = 1;
}
assert(tb);
- if (scols_table_is_noheadings(tb) ||
+ if (tb->header_printed == 1 ||
+ scols_table_is_noheadings(tb) ||
scols_table_is_export(tb) ||
scols_table_is_json(tb) ||
list_empty(&tb->tb_lines))
if (rc == 0)
fputs(linesep(tb), tb->out);
+
+ tb->header_printed = 1;
return rc;
}
* @start: first printed line or NULL to print from the beggin of the table
* @end: last printed line or NULL to print all from start.
*
+ * If the start is the first line in the table than prints table header too.
+ * The header is printed only once.
+ *
* Returns: 0, a negative value in case of an error.
*/
int scols_table_print_range( struct libscols_table *tb,
} else
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
- rc = print_range(tb, buf, &itr, end);
+ if (itr.p == tb->tb_lines.next) {
+ rc = print_header(tb, buf);
+ if (rc)
+ goto done;
+ }
+ rc = print_range(tb, buf, &itr, end);
+done:
free_buffer(buf);
- return 0;
+ return rc;
}
/**
return 0;
}
+ tb->header_printed = 0;
rc = initialize_printting(tb, &buf);
if (rc)
return rc;