dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 35.0% 14 / 0 / 40
Functions: 50.0% 2 / 0 / 4
Branches: 15.0% 3 / 0 / 20

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