1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/* Copyright (C) 2022-2026 Mintsuki and contributors.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef FLANTERM_H
29#define FLANTERM_H 1
30
31#include <stddef.h>
32#include <stdint.h>
33#include <stdbool.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39#define FLANTERM_CB_DEC 10
40#define FLANTERM_CB_BELL 20
41#define FLANTERM_CB_PRIVATE_ID 30
42#define FLANTERM_CB_STATUS_REPORT 40
43#define FLANTERM_CB_POS_REPORT 50
44#define FLANTERM_CB_KBD_LEDS 60
45#define FLANTERM_CB_MODE 70
46#define FLANTERM_CB_LINUX 80
47#define FLANTERM_CB_OSC 90
48
49#ifdef FLANTERM_IN_FLANTERM
50
51#include "flanterm_private.h"
52
53#else
54
55struct flanterm_context;
56
57#endif
58
59void flanterm_write(struct flanterm_context *ctx, const char *buf, size_t count);
60void flanterm_flush(struct flanterm_context *ctx);
61void flanterm_full_refresh(struct flanterm_context *ctx);
62void flanterm_deinit(struct flanterm_context *ctx, void (*_free)(void *ptr, size_t size));
63
64void flanterm_get_dimensions(struct flanterm_context *ctx, size_t *cols, size_t *rows);
65void flanterm_set_autoflush(struct flanterm_context *ctx, bool state);
66void flanterm_set_callback(struct flanterm_context *ctx, void (*callback)(struct flanterm_context *, uint64_t, uint64_t, uint64_t, uint64_t));
67
68/**
69 * Get the current cursor position.
70 *
71 * The returned coordinates are zero-based.
72 *
73 * @param ctx Flanterm context to query.
74 * @param x Receives the cursor X position.
75 * @param y Receives the cursor Y position.
76 */
77void flanterm_get_cursor_pos(struct flanterm_context *ctx, size_t *x, size_t *y);
78
79/**
80 * Set the current cursor position.
81 *
82 * Coordinates are zero-based.
83 *
84 * @param ctx Flanterm context to update.
85 * @param x New cursor X position.
86 * @param y New cursor Y position.
87 */
88void flanterm_set_cursor_pos(struct flanterm_context *ctx, size_t x, size_t y);
89
90/**
91 * Set the current text foreground colour.
92 *
93 * The colour index uses the terminal's base 0-7 colour range. Brightness is
94 * controlled separately by the bright flag.
95 *
96 * @param ctx Flanterm context to update.
97 * @param colour Base foreground colour index.
98 * @param bright True for bright/intense output, false for normal intensity.
99 */
100void flanterm_set_text_fg(struct flanterm_context *ctx, size_t colour, bool bright);
101
102/**
103 * Set the current text background colour.
104 *
105 * The colour index uses the terminal's base 0-7 colour range. Brightness is
106 * controlled separately by the bright flag.
107 *
108 * @param ctx Flanterm context to update.
109 * @param colour Base background colour index.
110 * @param bright True for bright/intense output, false for normal intensity.
111 */
112void flanterm_set_text_bg(struct flanterm_context *ctx, size_t colour, bool bright);
113
114/**
115 * Reset the foreground colour to the current default.
116 *
117 * @param ctx Flanterm context to update.
118 */
119void flanterm_reset_text_fg(struct flanterm_context *ctx);
120
121/**
122 * Reset the background colour to the current default.
123 *
124 * @param ctx Flanterm context to update.
125 */
126void flanterm_reset_text_bg(struct flanterm_context *ctx);
127
128/**
129 * Clear the terminal contents.
130 *
131 * @param ctx Flanterm context to clear.
132 * @param move True to reposition the cursor as part of the clear.
133 */
134void flanterm_clear(struct flanterm_context *ctx, bool move);
135
136
137#ifdef __cplusplus
138}
139#endif
140
141#endif
142