git.y1.nz

rvis

Minimal terminal colorizer.
download: https://git.y1.nz/archives/rvis.tar.gz
README | Files | Log | Refs

vt.h

      1 /* This module is an independent implementation the        */
      2 /* terminal parser from vt100's fantastic spec for a DEC/  */
      3 /* ANSI terminal emulator. It attempts to be standalone    */
      4 /* and hackable, and is written in C99-compatible C. It    */
      5 /* tries to introduce as little runtime overhead as        */
      6 /* possible.                                               */
      7 /*                                                         */
      8 /* The exact specification which I used to implement this  */
      9 /* is included in this repository as a standalone webpage, */
     10 /* in the file "dec-parser.html".                          */
     11 /*                                                         */
     12 /*                        __n__n                           */
     13 /*                    @/      . .                          */
     14 /*                   (           @  < oink!                */
     15 /*                     \ __ _ _ /                          */
     16 /*                     / /    \ \                          */
     17 /*                                                         */
     18 /*    the new year pig of good luck wishes you well <3     */   
     19 /*                                                         */
     20 
     21 /* internal state of the parser */
     22 typedef struct _ps {
     23 	char current_char;
     24 	int node;
     25 
     26 	/* other parser state, accumulated strings, etc */
     27 	int intermediate_char_count;
     28 	const char *intermediate_chars;
     29 } ParserState;
     30 
     31 // TODO typedef the void(ParserState *state) callback type
     32 
     33 /* CallBackPoinTeR, macro to reduce repetition */
     34 typedef struct _pcbs {
     35 	void (*ignore)(ParserState *state);
     36 	void (*print)(ParserState *state);
     37 	void (*execute)(ParserState *state);
     38 	void (*clear)(ParserState *state);
     39 	void (*collect)(ParserState *state);
     40 	void (*param)(ParserState *state);
     41 	void (*esc_dispatch)(ParserState *state);
     42 	void (*csi_dispatch)(ParserState *state);
     43 	void (*hook)(ParserState *state);
     44 	void (*put)(ParserState *state);
     45 	void (*unhook)(ParserState *state);
     46 	void (*osc_start)(ParserState *state);
     47 	void (*osc_put)(ParserState *state);
     48 	void (*osc_end)(ParserState *state);
     49 	void (*unhandled)(ParserState *state);
     50 } ParserCallbacks;
     51 
     52 /* update the state machine and process a single character */
     53 void handle(ParserCallbacks *callbacks, ParserState *state, char ch);
     54 
     55 /* initialize structs */
     56 ParserState *init_parser_state();
     57 void free_parser_state(ParserState *state);
     58 void init_parser_callbacks(ParserCallbacks *cbs, void (*pass)(ParserState *));
     59 

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.