summaryrefslogblamecommitdiffstats
path: root/examples/test1.c
blob: 6db7665a879743f1f27b4ba613c40c0ddda35c1b (plain) (tree)
1
2
3
4
5
6
7
8
9
10





                   

                           

                                
                    



                      


                 

                                        







                                                             
                                                                      
                                      

                                                                



             

                                                                                 



                         
                                                                  
                                                          





                              
                            


             
#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;
}