scols_copy_table
scols_new_table
scols_ref_table
+scols_sort_table
scols_table_add_column
scols_table_add_line
scols_table_colors_wanted
scols_table_get_ncols
scols_table_get_nlines
scols_table_get_stream
+scols_table_get_termforce
+scols_table_get_termwidth
+scols_table_get_title
scols_table_is_ascii
scols_table_is_empty
scols_table_is_export
scols_table_set_name
scols_table_set_stream
scols_table_set_symbols
-scols_table_get_title
-scols_sort_table
+scols_table_set_termforce
+scols_table_set_termwidth
scols_unref_table
</SECTION>
extern int scols_sort_table(struct libscols_table *tb, struct libscols_column *cl);
+/*
+ *
+ */
+enum {
+ SCOLS_TERMFORCE_AUTO = 0,
+ SCOLS_TERMFORCE_NEVER,
+ SCOLS_TERMFORCE_ALWAYS
+};
+extern int scols_table_set_termforce(struct libscols_table *tb, int force);
+extern int scols_table_get_termforce(struct libscols_table *tb);
+extern int scols_table_set_termwidth(struct libscols_table *tb, size_t width);
+extern size_t scols_table_get_termwidth(struct libscols_table *tb);
+
+
/* table_print.c */
extern int scols_print_table(struct libscols_table *tb);
extern int scols_print_table_to_string(struct libscols_table *tb, char **data);
global:
scols_column_is_wrapnl;
scols_symbols_set_cell_padding;
+ scols_table_get_termforce;
+ scols_table_get_termwidth;
+ scols_table_set_termforce;
+ scols_table_set_termwidth;
} SMARTCOLS_2.28;
size_t nlines; /* number of lines */
size_t termwidth; /* terminal width */
size_t termreduce; /* extra blank space */
+ int termforce; /* SCOLS_TERMFORCE_* */
FILE *out; /* output stream */
char *colsep; /* column separator */
#include <ctype.h>
#include "nls.h"
+#include "ttyutils.h"
#include "smartcolsP.h"
#ifdef HAVE_WIDECHAR
list_sort(&tb->tb_lines, cells_cmp_wrapper, cl);
return 0;
}
+
+/**
+ * scols_table_set_termforce:
+ * @tb: table
+ * @force: SCOLS_TERMFORCE_{NEVER,ALWAYS,AUTO}
+ *
+ * Forces library to use stdout as terminal, non-terminal or use automatical
+ * detection (default).
+ *
+ * Returns: 0, a negative value in case of an error.
+ */
+int scols_table_set_termforce(struct libscols_table *tb, int force)
+{
+ if (!tb)
+ return -EINVAL;
+ tb->termforce = force;
+ return 0;
+}
+
+/**
+ * scols_table_get_termforce:
+ * @tb: table
+ *
+ * Returns: SCOLS_TERMFORCE_{NEVER,ALWAYS,AUTO} or a negative value in case of an error.
+ */
+int scols_table_get_termforce(struct libscols_table *tb)
+{
+ return tb->termforce;
+}
+
+/**
+ * scols_table_set_termwidth
+ * @tb: table
+ * @width: terminal width
+ *
+ * The library automatically detects terminal width or defaults to 80 chars if
+ * detections is unsuccessful. This function override this behaviour.
+ *
+ * Returns: 0, a negative value in case of an error.
+ */
+int scols_table_set_termwidth(struct libscols_table *tb, size_t width)
+{
+ tb->termwidth = width;
+ return 0;
+}
+
+/**
+ * scols_table_get_termwidth
+ * @tb: table
+ *
+ * Returns: terminal width or a negative value in case of an error.
+ */
+size_t scols_table_get_termwidth(struct libscols_table *tb)
+{
+ if (tb->termwidth == 0)
+ tb->termwidth = get_terminal_width(80);
+ return tb->termwidth;
+}
#include <ctype.h>
#include "mbsalign.h"
-#include "ttyutils.h"
#include "carefulputc.h"
#include "smartcolsP.h"
scols_table_set_symbols(tb, NULL); /* use default */
if (tb->format == SCOLS_FMT_HUMAN)
- tb->is_term = isatty(STDOUT_FILENO) ? 1 : 0;
+ tb->is_term = tb->termforce == SCOLS_TERMFORCE_NEVER ? 0 :
+ tb->termforce == SCOLS_TERMFORCE_ALWAYS ? 1 :
+ isatty(STDOUT_FILENO);
if (tb->is_term) {
- tb->termwidth = get_terminal_width(80);
- if (tb->termreduce > 0 && tb->termreduce < tb->termwidth)
- tb->termwidth -= tb->termreduce;
- bufsz = tb->termwidth;
+ size_t width = (size_t) scols_table_get_termwidth(tb);
+
+ if (tb->termreduce > 0 && tb->termreduce < width) {
+ width -= tb->termreduce;
+ scols_table_set_termwidth(tb, width);
+ }
+ bufsz = width;
} else
bufsz = BUFSIZ;