Skip to content

Commit c041c67

Browse files
committed
refactor(terminfo): spell out capability flag bits
Rename TERMINFO_AM/XENL/BCE to TERMINFO_AUTO_RIGHT_MARGIN, TERMINFO_EAT_NEWLINE_GLITCH, and TERMINFO_BACK_COLOR_ERASE (and the FLAG_* mirrors in terminfo.ts), matching the full ncurses names now used for the parser's capability indices.
1 parent 482f880 commit c041c67

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

‎src/terminfo.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ struct TermInfo *terminfo_init(void *mem) {
2020
struct TermInfo *ti = (struct TermInfo *)mem;
2121
ti->generation = 1;
2222
ti->colors = 256;
23-
ti->flags = TERMINFO_BCE | TERMINFO_AM | TERMINFO_XENL | TERMINFO_ALTSCREEN;
23+
ti->flags = TERMINFO_BACK_COLOR_ERASE | TERMINFO_AUTO_RIGHT_MARGIN |
24+
TERMINFO_EAT_NEWLINE_GLITCH | TERMINFO_ALTSCREEN;
2425
ti->confirmed = 0;
2526
ti->theme_fg = 0;
2627
ti->theme_bg = 0;
@@ -244,13 +245,13 @@ int terminfo_parse(const uint8_t *bytes, int len, struct TermInfo *ti) {
244245
uint32_t flags = 0;
245246
if (bool_count > TERMINFO_BOOL_AUTO_RIGHT_MARGIN &&
246247
bytes[bools_off + TERMINFO_BOOL_AUTO_RIGHT_MARGIN])
247-
flags |= TERMINFO_AM;
248+
flags |= TERMINFO_AUTO_RIGHT_MARGIN;
248249
if (bool_count > TERMINFO_BOOL_EAT_NEWLINE_GLITCH &&
249250
bytes[bools_off + TERMINFO_BOOL_EAT_NEWLINE_GLITCH])
250-
flags |= TERMINFO_XENL;
251+
flags |= TERMINFO_EAT_NEWLINE_GLITCH;
251252
if (bool_count > TERMINFO_BOOL_BACK_COLOR_ERASE &&
252253
bytes[bools_off + TERMINFO_BOOL_BACK_COLOR_ERASE])
253-
flags |= TERMINFO_BCE;
254+
flags |= TERMINFO_BACK_COLOR_ERASE;
254255

255256
int32_t colors = 0;
256257
if (num_count > TERMINFO_NUM_MAX_COLORS) {
@@ -272,9 +273,9 @@ int terminfo_parse(const uint8_t *bytes, int len, struct TermInfo *ti) {
272273

273274
/* The entry describes the terminal completely for the capabilities it
274275
* owns: replace them, leave probe-only flags and theme fields alone. */
275-
uint32_t keep =
276-
~(TERMINFO_TRUECOLOR | TERMINFO_BCE | TERMINFO_AM | TERMINFO_XENL |
277-
TERMINFO_ALTSCREEN | TERMINFO_STYLED_UNDERLINE);
276+
uint32_t keep = ~(TERMINFO_TRUECOLOR | TERMINFO_BACK_COLOR_ERASE |
277+
TERMINFO_AUTO_RIGHT_MARGIN | TERMINFO_EAT_NEWLINE_GLITCH |
278+
TERMINFO_ALTSCREEN | TERMINFO_STYLED_UNDERLINE);
278279
ti->flags = (ti->flags & keep) | flags;
279280
ti->colors = (uint32_t)colors;
280281
ti->generation++;

‎src/terminfo.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
/* Capability flag bits (terminfo-spec section 6). */
1515
#define TERMINFO_TRUECOLOR (1u << 0)
16-
#define TERMINFO_BCE (1u << 1)
17-
#define TERMINFO_AM (1u << 2)
18-
#define TERMINFO_XENL (1u << 3)
16+
#define TERMINFO_BACK_COLOR_ERASE (1u << 1)
17+
#define TERMINFO_AUTO_RIGHT_MARGIN (1u << 2)
18+
#define TERMINFO_EAT_NEWLINE_GLITCH (1u << 3)
1919
#define TERMINFO_ALTSCREEN (1u << 4)
2020
#define TERMINFO_STYLED_UNDERLINE (1u << 5)
2121
#define TERMINFO_SYNC (1u << 6)

‎terminfo.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ export const MAX_TERMINFO = 32768;
99

1010
/* Flag bits — must match src/terminfo.h. */
1111
const FLAG_TRUECOLOR = 1 << 0;
12-
const FLAG_BCE = 1 << 1;
13-
const FLAG_AM = 1 << 2;
14-
const FLAG_XENL = 1 << 3;
12+
const FLAG_BACK_COLOR_ERASE = 1 << 1;
13+
const FLAG_AUTO_RIGHT_MARGIN = 1 << 2;
14+
const FLAG_EAT_NEWLINE_GLITCH = 1 << 3;
1515
const FLAG_ALTSCREEN = 1 << 4;
1616
const FLAG_STYLED_UNDERLINE = 1 << 5;
1717

@@ -173,9 +173,9 @@ export async function detectTerminal(
173173
let capabilities: Capabilities = Object.freeze({
174174
colors: view.getUint32(structPtr + TI.colors, true),
175175
trueColor: !!(flags & FLAG_TRUECOLOR),
176-
bce: !!(flags & FLAG_BCE),
177-
autoMargin: !!(flags & FLAG_AM),
178-
xenl: !!(flags & FLAG_XENL),
176+
bce: !!(flags & FLAG_BACK_COLOR_ERASE),
177+
autoMargin: !!(flags & FLAG_AUTO_RIGHT_MARGIN),
178+
xenl: !!(flags & FLAG_EAT_NEWLINE_GLITCH),
179179
altScreen: !!(flags & FLAG_ALTSCREEN),
180180
styledUnderline: !!(flags & FLAG_STYLED_UNDERLINE),
181181
});

0 commit comments

Comments
 (0)