From: Olivier Matz Date: Fri, 11 Mar 2011 19:41:19 +0000 (+0100) Subject: trivial_rdline: use the pager in this example X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=90045b8f65d5bb46e6377203b6231139483bbf1a;p=libcmdline.git trivial_rdline: use the pager in this example Signed-off-by: Olivier Matz --- diff --git a/src/trivial_rdline/main.c b/src/trivial_rdline/main.c index a44150a..23f7f20 100644 --- a/src/trivial_rdline/main.c +++ b/src/trivial_rdline/main.c @@ -44,6 +44,18 @@ #include #include +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;