1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright (C) 2014 David Herrmann <dh.herrmann@gmail.com>
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
29 typedef struct term_color term_color;
30 typedef struct term_attr term_attr;
32 typedef struct term_utf8 term_utf8;
33 typedef struct term_seq term_seq;
34 typedef struct term_parser term_parser;
36 typedef struct term_screen term_screen;
42 typedef uint64_t term_age_t;
44 #define TERM_AGE_NULL 0
51 /* special color-codes */
52 TERM_CCODE_DEFAULT, /* default foreground/background color */
53 TERM_CCODE_256, /* 256color code */
54 TERM_CCODE_RGB, /* color is specified as RGB */
56 /* dark color-codes */
64 TERM_CCODE_WHITE, /* technically: light grey */
66 /* light color-codes */
67 TERM_CCODE_LIGHT_BLACK = TERM_CCODE_BLACK + 8, /* technically: dark grey */
68 TERM_CCODE_LIGHT_RED = TERM_CCODE_RED + 8,
69 TERM_CCODE_LIGHT_GREEN = TERM_CCODE_GREEN + 8,
70 TERM_CCODE_LIGHT_YELLOW = TERM_CCODE_YELLOW + 8,
71 TERM_CCODE_LIGHT_BLUE = TERM_CCODE_BLUE + 8,
72 TERM_CCODE_LIGHT_MAGENTA = TERM_CCODE_MAGENTA + 8,
73 TERM_CCODE_LIGHT_CYAN = TERM_CCODE_CYAN + 8,
74 TERM_CCODE_LIGHT_WHITE = TERM_CCODE_WHITE + 8,
88 term_color fg; /* foreground color */
89 term_color bg; /* background color */
91 unsigned int bold : 1; /* bold font */
92 unsigned int italic : 1; /* italic font */
93 unsigned int underline : 1; /* underline text */
94 unsigned int inverse : 1; /* inverse fg/bg */
95 unsigned int protect : 1; /* protect from erase */
96 unsigned int blink : 1; /* blink text */
97 unsigned int hidden : 1; /* hidden */
100 void term_attr_to_argb32(const term_attr *attr, uint32_t *fg, uint32_t *bg, const uint8_t *palette);
110 unsigned int i_bytes : 3;
111 unsigned int n_bytes : 3;
112 unsigned int valid : 1;
115 size_t term_utf8_decode(term_utf8 *p, uint32_t **out_buf, char c);
121 int term_parser_new(term_parser **out, bool host);
122 term_parser *term_parser_free(term_parser *parser);
123 int term_parser_feed(term_parser *parser, const term_seq **seq_out, uint32_t raw);
125 #define _term_parser_free_ _cleanup_(term_parser_freep)
126 DEFINE_TRIVIAL_CLEANUP_FUNC(term_parser*, term_parser_free);
133 TERM_KBDMOD_IDX_SHIFT,
134 TERM_KBDMOD_IDX_CTRL,
136 TERM_KBDMOD_IDX_LINUX,
137 TERM_KBDMOD_IDX_CAPS,
140 TERM_KBDMOD_SHIFT = 1 << TERM_KBDMOD_IDX_SHIFT,
141 TERM_KBDMOD_CTRL = 1 << TERM_KBDMOD_IDX_CTRL,
142 TERM_KBDMOD_ALT = 1 << TERM_KBDMOD_IDX_ALT,
143 TERM_KBDMOD_LINUX = 1 << TERM_KBDMOD_IDX_LINUX,
144 TERM_KBDMOD_CAPS = 1 << TERM_KBDMOD_IDX_CAPS,
147 typedef int (*term_screen_write_fn) (term_screen *screen, void *userdata, const void *buf, size_t size);
148 typedef int (*term_screen_cmd_fn) (term_screen *screen, void *userdata, unsigned int cmd, const term_seq *seq);
150 int term_screen_new(term_screen **out, term_screen_write_fn write_fn, void *write_fn_data, term_screen_cmd_fn cmd_fn, void *cmd_fn_data);
151 term_screen *term_screen_ref(term_screen *screen);
152 term_screen *term_screen_unref(term_screen *screen);
154 DEFINE_TRIVIAL_CLEANUP_FUNC(term_screen*, term_screen_unref);
156 unsigned int term_screen_get_width(term_screen *screen);
157 unsigned int term_screen_get_height(term_screen *screen);
158 uint64_t term_screen_get_age(term_screen *screen);
160 int term_screen_feed_text(term_screen *screen, const uint8_t *in, size_t size);
161 int term_screen_feed_keyboard(term_screen *screen,
162 const uint32_t *keysyms,
165 const uint32_t *ucs4,
167 int term_screen_resize(term_screen *screen, unsigned int width, unsigned int height);
168 void term_screen_soft_reset(term_screen *screen);
169 void term_screen_hard_reset(term_screen *screen);
171 int term_screen_set_answerback(term_screen *screen, const char *answerback);
173 int term_screen_draw(term_screen *screen,
174 int (*draw_fn) (term_screen *screen,
178 const term_attr *attr,
181 unsigned int ch_width),