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