- Notifications
You must be signed in to change notification settings - Fork3
A minimal ANSI escape sequence parser, written in C.
License
64/cansid
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This repository contains a simple C ANSI escape sequence parser. It is intended for use in my own hobby operating system, but can be adapted for different uses.
First, call the functioncansid_init(void)
which returns astruct cansid_state
:
structcansid_statestate=cansid_init();
Then, whenever you receive a char that you want to run through the parser, hand it tocansid_process(struct cansid_state *, char)
. This returns astruct color_char
.
charc='x';// Whatever you want to parsestructcolor_charch=cansid_process(&state,c);
The returned struct indicates how you should print the character. It contains two fields:style
, andascii
. Thestyle
field is arranged inthis format. Theascii
field is simply the character which should be printed. Ifascii
is the NUL byte (i.e0x00
or\0
), then the character should not be outputted to the screen (and therefore thestyle
field should be ignored too).
To add CANSID to your repository, simply place the filescansid.c
andcansid.h
in the appropriate locations. There are no dependencies and can even be compiled in a freestanding environment.
Running tests can be done withmake test
.
Feel free to open an issue or a pull request if you would like to contribute or ask a question.