Add bt_common_get_term_size()
[babeltrace.git] / src / common / common.h
index 809c2e5063556a3ec500d60694794a9bf8264ce4..1b952913f3fa96e1f94f8be41d89b1de4eaca5bf 100644 (file)
@@ -331,6 +331,30 @@ size_t bt_common_get_page_size(int log_level);
 BT_HIDDEN
 void bt_common_sep_digits(char *str, unsigned int digits_per_group, char sep);
 
+/*
+ * This is similar to what the command `fold --spaces` does: it wraps
+ * the input lines of `str`, breaking at spaces, and indenting each line
+ * with `indent` spaces so that each line fits the total length
+ * `total_length`.
+ *
+ * If an original line in `str` contains a word which is >= the content
+ * length (`total_length - indent`), then the corresponding folded line
+ * is also larger than the content length. In other words, breaking at
+ * spaces is a best effort, but it might not be possible.
+ *
+ * The returned string, on success, is owned by the caller.
+ */
+BT_HIDDEN
+GString *bt_common_fold(const char *str, unsigned int total_length,
+               unsigned int indent);
+
+/*
+ * Writes the terminal's width to `*width`, its height to `*height`,
+ * and returns 0 on success, or returns -1 on error.
+ */
+BT_HIDDEN
+int bt_common_get_term_size(unsigned int *width, unsigned int *height);
+
 /*
  * Wraps read() function to handle EINTR and partial reads.
  * On success, it returns `count` received as parameter. On error, it returns a
This page took 0.023936 seconds and 4 git commands to generate.