dte test coverage


Directory: ./
File: src/terminal/terminal.c
Date: 2026-01-27 12:16:02
Coverage Exec Excl Total
Lines: 35.0% 14 0 40
Functions: 50.0% 2 0 4
Branches: 15.0% 3 0 20

Line Branch Exec Source
1 #include "terminal.h"
2 #include "color.h"
3 #include "output.h"
4 #include "parse.h"
5
6 7 void term_init(Terminal *term, const char *name, const char *colorterm)
7 {
8 7 TermFeatureFlags features = term_get_features(name, colorterm);
9 7 term->features = features;
10 7 term->width = 80;
11 7 term->height = 24;
12
13 14 term->ncv_attributes =
14
2/2
✓ Branch 3 → 4 taken 6 times.
✓ Branch 3 → 6 taken 1 time.
7 (features & TFLAG_NCV_UNDERLINE) ? ATTR_UNDERLINE : 0
15
1/2
✓ Branch 4 → 5 taken 6 times.
✗ Branch 4 → 6 not taken.
6 | (features & TFLAG_NCV_DIM) ? ATTR_DIM : 0
16 6 | (features & TFLAG_NCV_REVERSE) ? ATTR_REVERSE : 0
17 ;
18 7 }
19
20 void term_enable_private_modes(Terminal *term)
21 {
22 TermOutputBuffer *obuf = &term->obuf;
23 TermFeatureFlags features = term->features;
24
25 // Note that changes to some of the sequences below may require
26 // corresponding updates to handle_query_reply()
27
28 if (features & TFLAG_META_ESC) {
29 term_put_literal(obuf, "\033[?1036h"); // DECSET 1036 (metaSendsEscape)
30 }
31 if (features & TFLAG_ALT_ESC) {
32 term_put_literal(obuf, "\033[?1039h"); // DECSET 1039 (altSendsEscape)
33 }
34
35 if (features & TFLAG_KITTY_KEYBOARD) {
36 // https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement
37 term_put_literal(obuf, "\033[>5u");
38 } else if (features & TFLAG_MODIFY_OTHER_KEYS) {
39 // Try to use "modifyOtherKeys" mode (level 2 or 1)
40 term_put_literal(obuf, "\033[>4;1m\033[>4;2m");
41 }
42
43 // Try to enable bracketed paste mode. This is done unconditionally,
44 // since it should be ignored by terminals that don't recognize it
45 // and we really want to enable it for terminals that support it but
46 // are spoofing $TERM for whatever reason.
47 term_put_literal(obuf, "\033[?2004s\033[?2004h");
48 }
49
50 void term_restore_private_modes(Terminal *term)
51 {
52 TermOutputBuffer *obuf = &term->obuf;
53 TermFeatureFlags features = term->features;
54 if (features & TFLAG_META_ESC) {
55 term_put_literal(obuf, "\033[?1036l"); // DECRST 1036 (metaSendsEscape)
56 }
57 if (features & TFLAG_ALT_ESC) {
58 term_put_literal(obuf, "\033[?1039l"); // DECRST 1039 (altSendsEscape)
59 }
60 if (features & TFLAG_KITTY_KEYBOARD) {
61 term_put_literal(obuf, "\033[<u");
62 } else if (features & TFLAG_MODIFY_OTHER_KEYS) {
63 term_put_literal(obuf, "\033[>4m");
64 }
65 term_put_literal(obuf, "\033[?2004l\033[?2004r");
66 }
67
68 1 void term_restore_cursor_style(Terminal *term)
69 {
70 // TODO: Query the cursor style at startup (using DECRQSS DECSCUSR)
71 // and restore the value provided in the reply (if any), instead
72 // of using CURSOR_DEFAULT (which basically amounts to using the
73 // so-called "DECSCUSR 0 hack")
74 1 static const TermCursorStyle reset = {
75 .type = CURSOR_DEFAULT,
76 .color = COLOR_DEFAULT,
77 };
78
79 1 term_set_cursor_style(term, reset);
80 1 }
81