summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-09-13 15:05:57 -0400
committerJesse Luehrs <doy@tozt.net>2014-09-13 15:05:57 -0400
commitaef24a4d43598bd1f65951611e6338a597fc7bc0 (patch)
tree58503f655597e21b7a61f6daaf9b1808e4852fac /examples
parentcb0744e81c4577cf2a3e4ff41e431a053bb12b57 (diff)
downloadlibvt100-aef24a4d43598bd1f65951611e6338a597fc7bc0.tar.gz
libvt100-aef24a4d43598bd1f65951611e6338a597fc7bc0.zip
example program to make sure the library works
Diffstat (limited to 'examples')
-rw-r--r--examples/test1.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/examples/test1.c b/examples/test1.c
new file mode 100644
index 0000000..bad0023
--- /dev/null
+++ b/examples/test1.c
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "vt100.h"
+
+int main(int argc, char *argv[])
+{
+ VT100Screen vt;
+ char buf[4096];
+ size_t offset = 0;
+ int i, j, skip;
+
+ memset(&vt, 0, sizeof(VT100Screen));
+ vt100_screen_init(&vt);
+ vt100_screen_set_window_size(&vt);
+
+ for (;;) {
+ size_t bytes, parsed;
+
+ bytes = fread(buf + offset, 1, 4096 - offset, stdin);
+ if (bytes < 1)
+ break;
+
+ parsed = vt100_screen_process_string(&vt, buf, bytes + offset);
+ if (parsed < bytes + offset) {
+ memcpy(buf, buf + parsed, bytes - parsed);
+ offset = bytes - parsed;
+ }
+ }
+
+ skip = 0;
+ for (i = vt.grid->row_top; i < vt.grid->row_top + vt.grid->max.row; ++i) {
+ for (j = 0; j < vt.grid->max.col; ++j) {
+ if (skip) {
+ skip = 0;
+ continue;
+ }
+ struct vt100_cell *cell = &vt.grid->rows[i].cells[j];
+ printf("%*s", cell->len, cell->contents);
+ if (cell->is_wide)
+ skip = 1;
+ }
+ printf("\n");
+ }
+
+ vt100_screen_cleanup(&vt);
+
+ return 0;
+}