rdline: add a pager that can be used by user-defined commands
[libcmdline.git] / src / lib / cmdline_rdline.h
index cee438a..23b8cb6 100644 (file)
@@ -147,6 +147,13 @@ struct rdline {
 
        /* opaque pointer */
        void *opaque;
+
+#ifndef NO_PAGER
+       char *pager_buf; /* buffer used to store paged data */
+       int pager_len; /* total len of buffer */
+       int pager_off; /* offset of next data */
+       int pager_lines; /* number of lines displayed */
+#endif
 };
 
 /**
@@ -351,4 +358,26 @@ void rdline_clear_history(struct rdline *rdl);
  */
 char *rdline_get_history_item(struct rdline *rdl, unsigned int i);
 
+#ifndef NO_PAGER
+/**
+ * Print data asynchronously (using pager if needed)
+ *
+ * If there is enough place to print data on the current page, it is
+ * printed synchronously. Else, a temporary buffer is allocated and
+ * the data is stored in it. When the main rdline is called again, the
+ * pager is flushed before parsing any other commands.
+ *
+ * @param rdl
+ *   The rdline descriptor
+ * @param fmt
+ *   The format strings
+ * @return
+ *   Upon successful return, these functions return the number of
+ *   characters printed (not including the trailing '\0' used to end
+ *   output to strings). On error, a negative value is returned.
+ */
+int rdline_asyncpager_printf(struct rdline *rdl, const char *fmt, ...);
+#endif
+
+
 #endif /* _RDLINE_H_ */