summaryrefslogtreecommitdiffstats
path: root/libsmartcols/src/table.c
diff options
context:
space:
mode:
authorKarel Zak2016-09-13 14:06:01 +0200
committerKarel Zak2016-09-13 14:06:01 +0200
commit19055a25ed2a28d005460ee41627d2595ae7ad34 (patch)
treeff37d6bd2ff5f214d74d305723bad0b83fe15319 /libsmartcols/src/table.c
parentlibsmartcols: add application to test library features (diff)
downloadkernel-qcow2-util-linux-19055a25ed2a28d005460ee41627d2595ae7ad34.tar.gz
kernel-qcow2-util-linux-19055a25ed2a28d005460ee41627d2595ae7ad34.tar.xz
kernel-qcow2-util-linux-19055a25ed2a28d005460ee41627d2595ae7ad34.zip
libsmartcols: add functions to control terminal usage
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols/src/table.c')
-rw-r--r--libsmartcols/src/table.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c
index 10320f0be..32c991e49 100644
--- a/libsmartcols/src/table.c
+++ b/libsmartcols/src/table.c
@@ -25,6 +25,7 @@
#include <ctype.h>
#include "nls.h"
+#include "ttyutils.h"
#include "smartcolsP.h"
#ifdef HAVE_WIDECHAR
@@ -1104,3 +1105,61 @@ int scols_sort_table(struct libscols_table *tb, struct libscols_column *cl)
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;
+}