{"id":15049441,"url":"https://github.com/untodesu/libvterm","last_synced_at":"2025-04-10T02:09:03.968Z","repository":{"id":111197418,"uuid":"439296836","full_name":"untodesu/libvterm","owner":"untodesu","description":"Make your terminal emulator colorful!","archived":false,"fork":false,"pushed_at":"2022-01-17T18:00:48.000Z","size":38,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-02T17:42:53.248Z","etag":null,"topics":["ansi-c","ansi-colors","ansi-escape-codes","c89","lib","library","terminal","vt100"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/untodesu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-12-17T10:36:58.000Z","updated_at":"2024-07-09T07:20:18.000Z","dependencies_parsed_at":"2023-08-21T09:48:48.673Z","dependency_job_id":null,"html_url":"https://github.com/untodesu/libvterm","commit_stats":null,"previous_names":["untodesu/libvterm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/untodesu%2Flibvterm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/untodesu%2Flibvterm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/untodesu%2Flibvterm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/untodesu%2Flibvterm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/untodesu","download_url":"https://codeload.github.com/untodesu/libvterm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239114235,"owners_count":19583985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansi-c","ansi-colors","ansi-escape-codes","c89","lib","library","terminal","vt100"],"created_at":"2024-09-24T21:20:30.037Z","updated_at":"2025-02-16T09:32:13.373Z","avatar_url":"https://github.com/untodesu.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libvterm\n\u003e Make your terminal emulator colorful!  \n\nLibVTerm is an embeddable ANSI C89 (C90) library for parsing ANSI escape sequences.  \nIt is constructed in such way it requires only `ctype.h`, `string.h`, `stddef.h` and at least a malloc-styled allocation API.  \n\n## Getting started\nThe library should be capable of compiling on virtually any C89-compliant C compiler so the repo doesn't contain any build scripts - you do it yourself!  \nThe way library communicates with the outer world is callbacks: libvterm has about 8 of them and 2 are required.  \n\n#### System requirements\n1. A reliable `void *malloc(size_t)`-ish function (libvterm doesn't check for `NULL` pointers upon allocation).\n2. A reliable `void free(void *)`-ish function.\n\n#### Callback descriptions\n1. `mem_alloc` - allocate a block of N bytes. Required.\n2. `mem_free` - free a previously allocated block. Required.\n3. `misc_sequence` - allows parsing custom escape sequences specific for certain implementations.\n4. `set_cursor` - updates the cursor position.\n5. `mode_change` - implementation-specific actions upon video mode changes.\n6. `draw_cell` - put a single cell to the screen.\n7. `response` - write a byte back as a terminal response.\n8. `ascii` - handle miscellaneous ASCII escape characters.\n\n## Minimal example\n~~This is taken from [Demos](https://github.com/undnull/demos) (from about [here](https://github.com/undnull/demos/blob/master/arch/x86_64/boot/tmvga.c))~~  \nThe above source file doesn't exist anymore :)\n\n#### Code\n```c\nstatic void on_misc_sequence(\n    const struct vterm *vt, int chr)\n{\n    /* TMVGA driver supports DEC VT-220 \"show/hide cursor\" private\n     * sequences because VGA CRTC can show and hide the hardware cursor */\n    /* Some x86 port i/o stuff is going on here... */\n}\n\nstatic void on_set_cursor(\n    const struct vterm *vt,\n    const struct vterm_cursor *cursor)\n{\n    /* Again, TMVGA supports moving the cursor because VGA CRTC\n     * has hardware cursor support so we don't need to emulate it. */\n    /* Some more x86 port i/o stuff is going on here... */\n}\n\nstatic void on_draw_cell(\n    const struct vterm *vt, int chr,\n    unsigned int x, unsigned int y,\n    const struct vterm_attrib *attrib)\n{\n    /* The colors in VGA text mode slightly differ from the colors\n     * defined by the ANSI standard so this function remaps the colors\n     * depending on the flags (like INVERT or BRIGHT) and writes the\n     * character directly to the video memory. It also would be worth\n     * noting that not all attributes may be supported by the implementation\n     * so you are free to check for whatever you want to check for here. */\n    /* Some x86 and VGA trickery is going on here... */\n}\n\nstatic struct vterm vt = { 0 };\n\nint init_tmvga(/* ... some bootloader stuff ... */)\n{\n    struct vterm_callbacks callbacks;\n    /* some unrelated code */\n    \n    /* Here we send the required memory allocation functions\n     * to the library. Without them vterm_init will fail. */\n    callbacks.mem_alloc = \u0026kmalloc;\n    callbacks.mem_free = \u0026kmfree;\n    \n    /* These are not required by the library but without, say\n     * draw_cell callback we won't be able to see anything! */\n    callbacks.misc_sequence = \u0026on_misc_sequence;\n    callbacks.set_cursor = \u0026on_set_cursor;\n    callbacks.draw_cell = \u0026on_draw_cell;\n    \n    vterm_init(\u0026vt, \u0026callbacks, NULL);\n    \n    /* some unrelated code */\n}\n\n```\n\n#### Action!\n![](example.jpg)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funtodesu%2Flibvterm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funtodesu%2Flibvterm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funtodesu%2Flibvterm/lists"}