trivial_rdline: use the pager in this example
authorOlivier Matz <zer0@droids-corp.org>
Fri, 11 Mar 2011 19:41:19 +0000 (20:41 +0100)
committerOlivier Matz <zer0@droids-corp.org>
Sun, 13 Mar 2011 10:09:25 +0000 (11:09 +0100)
Signed-off-by: Olivier Matz <zer0@droids-corp.org>
src/trivial_rdline/main.c

index a44150a..23f7f20 100644 (file)
 #include <cmdline_socket.h>
 #include <cmdline.h>
 
+static void
+validate_buffer(struct rdline *rdl, const char *buf,
+               __attribute__((unused)) unsigned int size)
+{
+       int i;
+
+       printf("Buffer is <%s> (read from callback)\n", buf);
+       for (i = 0; i < 100; i++) {
+               rdline_asyncpager_printf(rdl, "foo%d\n", i);
+       }
+}
+
 int main(void)
 {
        struct termios oldterm, term;
@@ -55,9 +67,11 @@ int main(void)
        tcsetattr(0, TCSANOW, &term);
        setbuf(stdin, NULL);
 
-       rdline_init(&rdl, 0, 1, NULL, NULL, NULL);
-       while (rdline(&rdl, "prompt> ") == RDLINE_RES_VALIDATED)
-               printf("Buffer is <%s>\n", rdline_get_buffer(&rdl));
+       rdline_init(&rdl, 0, 1, validate_buffer, NULL, NULL);
+       while (rdline(&rdl, "prompt> ") == RDLINE_RES_VALIDATED) {
+               printf("Buffer is <%s> (read from main loop)\n",
+                      rdline_get_buffer(&rdl));
+       }
 
        tcsetattr(0, TCSANOW, &oldterm);
        return 0;