summaryrefslogtreecommitdiffstats
path: root/examples/test1.c
blob: 6db7665a879743f1f27b4ba613c40c0ddda35c1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "vt100.h"

#define UNUSED(x) ((void)x)

int main(int argc, char *argv[])
{
    VT100Screen *vt;
    char buf[4096];
    size_t offset = 0;
    int i, j, skip;

    UNUSED(argc);
    UNUSED(argv);

    vt = vt100_screen_new(24, 80);
    // 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) {
            memmove(buf, buf + parsed, bytes + offset - parsed);
            offset = bytes + offset - 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", (int)cell->len, cell->contents);
            if (cell->is_wide)
                skip = 1;
        }
        printf("\n");
    }

    vt100_screen_delete(vt);

    return 0;
}