Skip to content

Commit 7f7b3da

Browse files
improved graphics and text rendering
1 parent 0356422 commit 7f7b3da

8 files changed

Lines changed: 613 additions & 137 deletions

File tree

include/flanterm.h

Lines changed: 264 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,104 @@
2323
* POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
#ifndef FLANTERM_H
27-
#define FLANTERM_H 1
26+
/*
27+
* Retro Rocket fork notice
28+
*
29+
* This file is part of the Retro Rocket operating system and contains a
30+
* maintained fork of the flanterm terminal implementation originally
31+
* written by mintsuki.
32+
*
33+
* Modified portions (C) Craig Edwards, 2025-2026
34+
*
35+
* Purpose of fork:
36+
* Integration with the Retro Rocket graphics and terminal subsystem.
37+
* This fork introduces additional functionality required by the Retro
38+
* Rocket console environment, including:
39+
*
40+
* - native cursor and colour control interfaces
41+
* - scroll callbacks for synchronising text and graphics
42+
* - dirty region tracking for framebuffer updates
43+
* - glyph redefinition handling
44+
*
45+
* Because of these extensions, this implementation is not drop-in compatible
46+
* with upstream flanterm and should not be replaced with an upstream version
47+
* without adapting the Retro Rocket specific interfaces.
48+
*/
49+
50+
#pragma once
2851

2952
#include <stddef.h>
3053
#include <stdint.h>
3154
#include <stdbool.h>
3255

33-
#ifdef __cplusplus
34-
extern "C" {
35-
#endif
36-
56+
/**
57+
* Callback type for DEC private control sequences.
58+
*
59+
* This is triggered when the terminal receives a DEC private sequence
60+
* requiring backend handling.
61+
*/
3762
#define FLANTERM_CB_DEC 10
63+
64+
/**
65+
* Callback type for terminal bell requests.
66+
*
67+
* This is triggered when the BEL control character is received.
68+
*/
3869
#define FLANTERM_CB_BELL 20
70+
71+
/**
72+
* Callback type for terminal identification requests.
73+
*
74+
* This is triggered when a private device identification sequence
75+
* is processed.
76+
*/
3977
#define FLANTERM_CB_PRIVATE_ID 30
78+
79+
/**
80+
* Callback type for terminal status report requests.
81+
*
82+
* This is triggered when the terminal receives a device status query.
83+
*/
4084
#define FLANTERM_CB_STATUS_REPORT 40
85+
86+
/**
87+
* Callback type for cursor position reports.
88+
*
89+
* This is triggered when the terminal processes a request to report
90+
* the current cursor position.
91+
*/
4192
#define FLANTERM_CB_POS_REPORT 50
93+
94+
/**
95+
* Callback type for keyboard LED state updates.
96+
*
97+
* This is triggered when a sequence attempts to update keyboard LED
98+
* indicators such as Caps Lock, Num Lock, or Scroll Lock.
99+
*/
42100
#define FLANTERM_CB_KBD_LEDS 60
101+
102+
/**
103+
* Callback type for terminal mode changes.
104+
*
105+
* This is triggered when the terminal receives a sequence that modifies
106+
* terminal operating modes.
107+
*/
43108
#define FLANTERM_CB_MODE 70
109+
110+
/**
111+
* Callback type for Linux-specific control sequences.
112+
*
113+
* This is triggered when Linux console private escape sequences are
114+
* processed.
115+
*/
44116
#define FLANTERM_CB_LINUX 80
117+
118+
/**
119+
* Callback type for terminal scroll events.
120+
*
121+
* This is a Retro Rocket fork extension triggered when the terminal
122+
* scrolls its text region.
123+
*/
45124
#define FLANTERM_CB_SCROLL 90
46125

47126
#define FLANTERM_OOB_OUTPUT_OCRNL (1 << 0)
@@ -63,24 +142,197 @@ struct flanterm_context;
63142

64143
#endif
65144

145+
/**
146+
* Write a buffer of terminal data to the flanterm context.
147+
*
148+
* The buffer is parsed as terminal input and may contain printable text,
149+
* control characters, or escape sequences.
150+
*
151+
* @param ctx Flanterm context to write to.
152+
* @param buf Buffer containing terminal data.
153+
* @param count Number of bytes to write from the buffer.
154+
*/
66155
void flanterm_write(struct flanterm_context *ctx, const char *buf, size_t count);
156+
157+
/**
158+
* Flush any pending terminal output to the backing surface.
159+
*
160+
* This commits any buffered rendering work for the current context.
161+
*
162+
* @param ctx Flanterm context to flush.
163+
*/
67164
void flanterm_flush(struct flanterm_context *ctx);
165+
166+
/**
167+
* Force a full redraw of the terminal surface.
168+
*
169+
* This refreshes the entire terminal output rather than only changed regions.
170+
*
171+
* @param ctx Flanterm context to refresh.
172+
*/
68173
void flanterm_full_refresh(struct flanterm_context *ctx);
174+
175+
/**
176+
* Deinitialise a flanterm context and release any resources it owns.
177+
*
178+
* The supplied free callback is used to release allocations associated with
179+
* the context.
180+
*
181+
* @param ctx Flanterm context to destroy.
182+
* @param _free Allocator-compatible free function.
183+
*/
69184
void flanterm_deinit(struct flanterm_context *ctx, void (*_free)(void *ptr, size_t size));
70185

186+
/**
187+
* Get the terminal dimensions in character cells.
188+
*
189+
* @param ctx Flanterm context to query.
190+
* @param cols Receives the number of text columns.
191+
* @param rows Receives the number of text rows.
192+
*/
71193
void flanterm_get_dimensions(struct flanterm_context *ctx, size_t *cols, size_t *rows);
194+
195+
/**
196+
* Enable or disable automatic flushing after writes.
197+
*
198+
* When enabled, writes are flushed automatically. When disabled, callers
199+
* must flush explicitly.
200+
*
201+
* @param ctx Flanterm context to update.
202+
* @param state New autoflush state.
203+
*/
72204
void flanterm_set_autoflush(struct flanterm_context *ctx, bool state);
205+
206+
/**
207+
* Set the callback used for terminal events.
208+
*
209+
* The callback receives terminal notifications such as bell requests,
210+
* reports, and any fork-specific callback extensions.
211+
*
212+
* @param ctx Flanterm context to update.
213+
* @param callback Callback function, or NULL to clear it.
214+
*/
73215
void flanterm_set_callback(struct flanterm_context *ctx, void (*callback)(struct flanterm_context *, uint64_t, uint64_t, uint64_t, uint64_t));
216+
217+
/**
218+
* Get the current out-of-band output mode flags.
219+
*
220+
* @param ctx Flanterm context to query.
221+
*
222+
* @return Current out-of-band output flags.
223+
*/
74224
uint64_t flanterm_get_oob_output(struct flanterm_context *ctx);
225+
226+
/**
227+
* Set the out-of-band output mode flags.
228+
*
229+
* @param ctx Flanterm context to update.
230+
* @param oob_output New out-of-band output flags.
231+
*/
75232
void flanterm_set_oob_output(struct flanterm_context *ctx, uint64_t oob_output);
76233

77-
int64_t flanterm_ex_get_bounding_min_y();
78-
int64_t flanterm_ex_get_bounding_max_y();
234+
/**
235+
* Get the minimum Y position touched by the most recent rendering work.
236+
*
237+
* This is a Retro Rocket fork extension used for dirty-region tracking.
238+
*
239+
* @return Minimum modified Y coordinate.
240+
*/
241+
int64_t flanterm_ex_get_bounding_min_y(void);
242+
243+
/**
244+
* Get the maximum Y position touched by the most recent rendering work.
245+
*
246+
* This is a Retro Rocket fork extension used for dirty-region tracking.
247+
*
248+
* @return Maximum modified Y coordinate.
249+
*/
250+
int64_t flanterm_ex_get_bounding_max_y(void);
79251

252+
/**
253+
* Mark a single-byte character as having a redefined glyph.
254+
*
255+
* Redefined bytes are treated as literal single-byte glyphs rather than
256+
* as possible UTF-8 lead or continuation bytes.
257+
*
258+
* @param c Character byte whose glyph has been redefined.
259+
*/
80260
void ft_mark_redefined(uint8_t c);
81261

82-
#ifdef __cplusplus
83-
}
84-
#endif
262+
/**
263+
* Get the current cursor position.
264+
*
265+
* The returned coordinates are zero-based.
266+
*
267+
* @param ctx Flanterm context to query.
268+
* @param x Receives the cursor X position.
269+
* @param y Receives the cursor Y position.
270+
*/
271+
void flanterm_get_cursor_pos(struct flanterm_context *ctx, size_t *x, size_t *y);
272+
273+
/**
274+
* Set the current cursor position.
275+
*
276+
* Coordinates are zero-based.
277+
*
278+
* @param ctx Flanterm context to update.
279+
* @param x New cursor X position.
280+
* @param y New cursor Y position.
281+
*/
282+
void flanterm_set_cursor_pos(struct flanterm_context *ctx, size_t x, size_t y);
283+
284+
/**
285+
* Set the current text foreground colour.
286+
*
287+
* The colour index uses the terminal's base 0-7 colour range. Brightness is
288+
* controlled separately by the bright flag.
289+
*
290+
* @param ctx Flanterm context to update.
291+
* @param colour Base foreground colour index.
292+
* @param bright True for bright/intense output, false for normal intensity.
293+
*/
294+
void flanterm_set_text_fg(struct flanterm_context *ctx, size_t colour, bool bright);
295+
296+
/**
297+
* Set the current text background colour.
298+
*
299+
* The colour index uses the terminal's base 0-7 colour range. Brightness is
300+
* controlled separately by the bright flag.
301+
*
302+
* @param ctx Flanterm context to update.
303+
* @param colour Base background colour index.
304+
* @param bright True for bright/intense output, false for normal intensity.
305+
*/
306+
void flanterm_set_text_bg(struct flanterm_context *ctx, size_t colour, bool bright);
307+
308+
/**
309+
* Reset the foreground colour to the current default.
310+
*
311+
* This preserves the terminal's internal attribute model and applies the
312+
* appropriate default foreground for the current state.
313+
*
314+
* @param ctx Flanterm context to update.
315+
*/
316+
void flanterm_reset_text_fg(struct flanterm_context *ctx);
317+
318+
/**
319+
* Reset the background colour to the current default.
320+
*
321+
* This preserves the terminal's internal attribute model and applies the
322+
* appropriate default background for the current state.
323+
*
324+
* @param ctx Flanterm context to update.
325+
*/
326+
void flanterm_reset_text_bg(struct flanterm_context *ctx);
327+
328+
/**
329+
* Clear the terminal contents.
330+
*
331+
* When move is true, the cursor is also repositioned according to the
332+
* backend clear implementation.
333+
*
334+
* @param ctx Flanterm context to clear.
335+
* @param move True to reposition the cursor as part of the clear.
336+
*/
337+
void flanterm_clear(struct flanterm_context *ctx, bool move);
85338

86-
#endif

include/flanterm/fb.h

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,40 @@
2323
* POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
#ifndef FLANTERM_FB_H
27-
#define FLANTERM_FB_H 1
26+
/*
27+
* Retro Rocket fork notice
28+
*
29+
* This file is part of the Retro Rocket operating system and contains a
30+
* maintained fork of the flanterm terminal implementation originally
31+
* written by mintsuki.
32+
*
33+
* Modified portions (C) Craig Edwards, 2025-2026
34+
*
35+
* Purpose of fork:
36+
* Integration with the Retro Rocket graphics and terminal subsystem.
37+
* This fork introduces additional functionality required by the Retro
38+
* Rocket console environment, including:
39+
*
40+
* - native cursor and colour control interfaces
41+
* - scroll callbacks for synchronising text and graphics
42+
* - dirty region tracking for framebuffer updates
43+
* - glyph redefinition handling
44+
*
45+
* Because of these extensions, this implementation is not drop-in compatible
46+
* with upstream flanterm and should not be replaced with an upstream version
47+
* without adapting the Retro Rocket specific interfaces.
48+
*/
49+
50+
51+
#pragma once
2852

2953
#include <stdint.h>
3054
#include <stddef.h>
3155
#include <stdbool.h>
32-
33-
#ifdef __cplusplus
34-
extern "C" {
35-
#endif
36-
3756
#include "../flanterm.h"
3857

3958
#ifdef FLANTERM_IN_FLANTERM
40-
4159
#include "fb_private.h"
42-
4360
#endif
4461

4562
/**
@@ -151,8 +168,3 @@ void flanterm_fb_update_font(struct flanterm_context *_ctx, int glyph, const uin
151168
*/
152169
void flanterm_fb_draw_text_px(struct flanterm_context *_ctx, const char *s, int32_t px, int32_t py, uint32_t fg_rgb, uint32_t bg_rgb, bool transparent_bg);
153170

154-
#ifdef __cplusplus
155-
}
156-
#endif
157-
158-
#endif

0 commit comments

Comments
 (0)