Fast and reasonably complete (framebuffer) terminal emulator (Zig fork)
1/* Copyright (C) 2022-2025 mintsuki and contributors. 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are met: 5 * 6 * 1. Redistributions of source code must retain the above copyright notice, 7 * this list of conditions and the following disclaimer. 8 * 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 * and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 17 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 23 * POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#ifndef FLANTERM_PRIVATE_H 27#define FLANTERM_PRIVATE_H 1 28 29#ifndef FLANTERM_IN_FLANTERM 30#error "Do not use flanterm_private.h. Use interfaces defined in flanterm.h only." 31#endif 32 33#include <stddef.h> 34#include <stdint.h> 35#include <stdbool.h> 36 37#ifdef __cplusplus 38extern "C" { 39#endif 40 41#define FLANTERM_MAX_ESC_VALUES 16 42 43struct flanterm_context { 44 /* internal use */ 45 46 size_t tab_size; 47 bool autoflush; 48 bool cursor_enabled; 49 bool scroll_enabled; 50 bool control_sequence; 51 bool escape; 52 bool osc; 53 bool osc_escape; 54 bool rrr; 55 bool discard_next; 56 bool bold; 57 bool bg_bold; 58 bool reverse_video; 59 bool dec_private; 60 bool insert_mode; 61 uint64_t code_point; 62 size_t unicode_remaining; 63 uint8_t g_select; 64 uint8_t charsets[2]; 65 size_t current_charset; 66 size_t escape_offset; 67 size_t esc_values_i; 68 size_t saved_cursor_x; 69 size_t saved_cursor_y; 70 size_t current_primary; 71 size_t current_bg; 72 size_t scroll_top_margin; 73 size_t scroll_bottom_margin; 74 uint32_t esc_values[FLANTERM_MAX_ESC_VALUES]; 75 uint64_t oob_output; 76 bool saved_state_bold; 77 bool saved_state_bg_bold; 78 bool saved_state_reverse_video; 79 size_t saved_state_current_charset; 80 size_t saved_state_current_primary; 81 size_t saved_state_current_bg; 82 83 /* to be set by backend */ 84 85 size_t rows, cols; 86 87 void (*raw_putchar)(struct flanterm_context *, uint8_t c); 88 void (*clear)(struct flanterm_context *, bool move); 89 void (*set_cursor_pos)(struct flanterm_context *, size_t x, size_t y); 90 void (*get_cursor_pos)(struct flanterm_context *, size_t *x, size_t *y); 91 void (*set_text_fg)(struct flanterm_context *, size_t fg); 92 void (*set_text_bg)(struct flanterm_context *, size_t bg); 93 void (*set_text_fg_bright)(struct flanterm_context *, size_t fg); 94 void (*set_text_bg_bright)(struct flanterm_context *, size_t bg); 95 void (*set_text_fg_rgb)(struct flanterm_context *, uint32_t fg); 96 void (*set_text_bg_rgb)(struct flanterm_context *, uint32_t bg); 97 void (*set_text_fg_default)(struct flanterm_context *); 98 void (*set_text_bg_default)(struct flanterm_context *); 99 void (*set_text_fg_default_bright)(struct flanterm_context *); 100 void (*set_text_bg_default_bright)(struct flanterm_context *); 101 void (*move_character)(struct flanterm_context *, size_t new_x, size_t new_y, size_t old_x, size_t old_y); 102 void (*scroll)(struct flanterm_context *); 103 void (*revscroll)(struct flanterm_context *); 104 void (*swap_palette)(struct flanterm_context *); 105 void (*save_state)(struct flanterm_context *); 106 void (*restore_state)(struct flanterm_context *); 107 void (*double_buffer_flush)(struct flanterm_context *); 108 void (*full_refresh)(struct flanterm_context *); 109 void (*deinit)(struct flanterm_context *, void (*)(void *, size_t)); 110 111 /* to be set by client */ 112 113 void (*callback)(struct flanterm_context *, uint64_t, uint64_t, uint64_t, uint64_t); 114}; 115 116#ifdef __cplusplus 117} 118#endif 119 120#endif