summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
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;
+}