Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. |
| 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | */ |
| 6 | |
| 7 | #include <ctype.h> |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 8 | #include <fcntl.h> |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 9 | #include <libtsm.h> |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 10 | #include <stdio.h> |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 11 | #include <stdlib.h> |
Dominik Behr | 9389945 | 2014-08-18 22:16:21 -0700 | [diff] [blame] | 12 | #include <sys/select.h> |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 13 | #include <sys/stat.h> |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 14 | #include <sys/types.h> |
| 15 | #include <sys/wait.h> |
Dominik Behr | 32680e3 | 2016-08-16 12:18:41 -0700 | [diff] [blame] | 16 | #include <unistd.h> |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 17 | |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 18 | #include "dbus.h" |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 19 | #include "fb.h" |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 20 | #include "font.h" |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 21 | #include "image.h" |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 22 | #include "input.h" |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 23 | #include "main.h" |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 24 | #include "shl_pty.h" |
| 25 | #include "term.h" |
| 26 | #include "util.h" |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 27 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 28 | unsigned int term_num_terminals = 4; |
| 29 | static terminal_t* terminals[TERM_MAX_TERMINALS]; |
Dominik Behr | 4defb36 | 2016-01-13 12:36:14 -0800 | [diff] [blame] | 30 | static uint32_t current_terminal = 0; |
Stéphane Marchesin | 08c08e7 | 2016-01-07 16:44:08 -0800 | [diff] [blame] | 31 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 32 | struct term { |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 33 | struct tsm_screen* screen; |
| 34 | struct tsm_vte* vte; |
| 35 | struct shl_pty* pty; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 36 | int pty_bridge; |
| 37 | int pid; |
| 38 | tsm_age_t age; |
| 39 | int char_x, char_y; |
| 40 | int pitch; |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 41 | uint32_t* dst_image; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 44 | struct _terminal_t { |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 45 | unsigned vt; |
| 46 | bool active; |
Dominik Behr | da55e6c | 2017-02-28 18:12:10 -0800 | [diff] [blame] | 47 | bool input_enable; |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 48 | uint32_t background; |
| 49 | bool background_valid; |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 50 | fb_t* fb; |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 51 | struct term* term; |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 52 | char** exec; |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 55 | |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 56 | static char* interactive_cmd_line[] = { |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 57 | "/sbin/agetty", |
| 58 | "-", |
| 59 | "9600", |
| 60 | "xterm", |
| 61 | NULL |
| 62 | }; |
| 63 | |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 64 | static bool in_background = false; |
| 65 | static bool hotplug_occured = false; |
| 66 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 67 | |
| 68 | static void __attribute__ ((noreturn)) term_run_child(terminal_t* terminal) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 69 | { |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 70 | /* XXX figure out how to fix "top" for xterm-256color */ |
| 71 | setenv("TERM", "xterm", 1); |
Dominik Behr | 32680e3 | 2016-08-16 12:18:41 -0700 | [diff] [blame] | 72 | if (terminal->exec) { |
| 73 | execve(terminal->exec[0], terminal->exec, environ); |
| 74 | exit(1); |
| 75 | } else { |
| 76 | while (1) |
| 77 | sleep(1000000); |
| 78 | } |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 81 | static int term_draw_cell(struct tsm_screen* screen, uint32_t id, |
Stéphane Marchesin | 8fc1352 | 2015-12-14 17:02:28 -0800 | [diff] [blame] | 82 | const uint32_t* ch, size_t len, |
| 83 | unsigned int cwidth, unsigned int posx, |
| 84 | unsigned int posy, |
| 85 | const struct tsm_screen_attr* attr, |
| 86 | tsm_age_t age, void* data) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 87 | { |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 88 | terminal_t* terminal = (terminal_t*)data; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 89 | uint32_t front_color, back_color; |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 90 | uint8_t br, bb, bg; |
Stéphane Marchesin | edece33 | 2015-12-14 15:10:58 -0800 | [diff] [blame] | 91 | uint32_t luminance; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 92 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 93 | if (age && terminal->term->age && age <= terminal->term->age) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 94 | return 0; |
| 95 | |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 96 | if (terminal->background_valid) { |
| 97 | br = (terminal->background >> 16) & 0xFF; |
| 98 | bg = (terminal->background >> 8) & 0xFF; |
| 99 | bb = (terminal->background) & 0xFF; |
Stéphane Marchesin | edece33 | 2015-12-14 15:10:58 -0800 | [diff] [blame] | 100 | luminance = (3 * br + bb + 4 * bg) >> 3; |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 101 | |
Stéphane Marchesin | edece33 | 2015-12-14 15:10:58 -0800 | [diff] [blame] | 102 | /* |
| 103 | * FIXME: black is chosen on a dark background, but it uses the |
| 104 | * default color for light backgrounds |
| 105 | */ |
| 106 | if (luminance > 128) { |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 107 | front_color = 0; |
| 108 | back_color = terminal->background; |
| 109 | } else { |
| 110 | front_color = (attr->fr << 16) | (attr->fg << 8) | attr->fb; |
| 111 | back_color = terminal->background; |
| 112 | } |
| 113 | } else { |
| 114 | front_color = (attr->fr << 16) | (attr->fg << 8) | attr->fb; |
| 115 | back_color = (attr->br << 16) | (attr->bg << 8) | attr->bb; |
| 116 | } |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 117 | |
| 118 | if (attr->inverse) { |
| 119 | uint32_t tmp = front_color; |
| 120 | front_color = back_color; |
| 121 | back_color = tmp; |
| 122 | } |
| 123 | |
| 124 | if (len) |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 125 | font_render(terminal->term->dst_image, posx, posy, terminal->term->pitch, *ch, |
| 126 | front_color, back_color); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 127 | else |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 128 | font_fillchar(terminal->term->dst_image, posx, posy, terminal->term->pitch, |
| 129 | front_color, back_color); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
Stéphane Marchesin | e2a46cd | 2016-01-07 16:45:24 -0800 | [diff] [blame] | 134 | static void term_redraw(terminal_t* terminal) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 135 | { |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 136 | uint32_t* fb_buffer; |
| 137 | fb_buffer = fb_lock(terminal->fb); |
| 138 | if (fb_buffer != NULL) { |
| 139 | terminal->term->dst_image = fb_buffer; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 140 | terminal->term->age = |
| 141 | tsm_screen_draw(terminal->term->screen, term_draw_cell, terminal); |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 142 | fb_unlock(terminal->fb); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 143 | } |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 144 | } |
| 145 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 146 | void term_key_event(terminal_t* terminal, uint32_t keysym, int32_t unicode) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 147 | { |
Dominik Behr | da55e6c | 2017-02-28 18:12:10 -0800 | [diff] [blame] | 148 | if (!terminal->input_enable) |
| 149 | return; |
| 150 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 151 | if (tsm_vte_handle_keyboard(terminal->term->vte, keysym, 0, 0, unicode)) |
| 152 | tsm_screen_sb_reset(terminal->term->screen); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 153 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 154 | term_redraw(terminal); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 157 | static void term_read_cb(struct shl_pty* pty, char* u8, size_t len, void* data) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 158 | { |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 159 | terminal_t* terminal = (terminal_t*)data; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 160 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 161 | tsm_vte_input(terminal->term->vte, u8, len); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 162 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 163 | term_redraw(terminal); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 166 | static void term_write_cb(struct tsm_vte* vte, const char* u8, size_t len, |
| 167 | void* data) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 168 | { |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 169 | struct term* term = data; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 170 | int r; |
| 171 | |
| 172 | r = shl_pty_write(term->pty, u8, len); |
| 173 | if (r < 0) |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 174 | LOG(ERROR, "OOM in pty-write (%d)", r); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 175 | |
| 176 | shl_pty_dispatch(term->pty); |
| 177 | } |
| 178 | |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 179 | static void term_esc_show_image(terminal_t* terminal, char* params) |
| 180 | { |
| 181 | char* tok; |
| 182 | image_t* image; |
| 183 | int status; |
| 184 | |
| 185 | image = image_create(); |
| 186 | if (!image) { |
| 187 | LOG(ERROR, "Out of memory when creating an image.\n"); |
| 188 | return; |
| 189 | } |
| 190 | for (tok = strtok(params, ";"); tok; tok = strtok(NULL, ";")) { |
| 191 | if (strncmp("file=", tok, 5) == 0) { |
| 192 | image_set_filename(image, tok + 5); |
| 193 | } else if (strncmp("location=", tok, 9) == 0) { |
| 194 | uint32_t x, y; |
| 195 | if (sscanf(tok + 9, "%u,%u", &x, &y) != 2) { |
| 196 | LOG(ERROR, "Error parsing image location.\n"); |
| 197 | goto done; |
| 198 | } |
| 199 | image_set_location(image, x, y); |
| 200 | } else if (strncmp("offset=", tok, 7) == 0) { |
| 201 | int32_t x, y; |
| 202 | if (sscanf(tok + 7, "%d,%d", &x, &y) != 2) { |
| 203 | LOG(ERROR, "Error parsing image offset.\n"); |
| 204 | goto done; |
| 205 | } |
| 206 | image_set_offset(image, x, y); |
| 207 | } else if (strncmp("scale=", tok, 6) == 0) { |
| 208 | uint32_t s; |
| 209 | if (sscanf(tok + 6, "%u", &s) != 1) { |
| 210 | LOG(ERROR, "Error parsing image scale.\n"); |
| 211 | goto done; |
| 212 | } |
| 213 | if (s == 0) |
| 214 | s = image_get_auto_scale(term_getfb(terminal)); |
| 215 | image_set_scale(image, s); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | status = image_load_image_from_file(image); |
| 220 | if (status != 0) { |
| 221 | LOG(WARNING, "Term ESC image_load_image_from_file %s failed: %d:%s.", |
| 222 | image_get_filename(image), status, strerror(status)); |
| 223 | } else { |
| 224 | term_show_image(terminal, image); |
| 225 | } |
| 226 | done: |
| 227 | image_destroy(image); |
| 228 | } |
| 229 | |
| 230 | static void term_esc_draw_box(terminal_t* terminal, char* params) |
| 231 | { |
| 232 | char* tok; |
| 233 | uint32_t color = 0; |
| 234 | uint32_t w = 1; |
| 235 | uint32_t h = 1; |
| 236 | uint32_t locx, locy; |
| 237 | bool use_location = false; |
| 238 | int32_t offx, offy; |
| 239 | bool use_offset = false; |
| 240 | uint32_t scale = 1; |
| 241 | uint32_t* buffer; |
| 242 | int32_t startx, starty; |
| 243 | uint32_t pitch4; |
| 244 | |
| 245 | for (tok = strtok(params, ";"); tok; tok = strtok(NULL, ";")) { |
| 246 | if (strncmp("color=", tok, 6) == 0) { |
| 247 | color = strtoul(tok + 6, NULL, 0); |
| 248 | } else if (strncmp("size=", tok, 5) == 0) { |
| 249 | if (sscanf(tok + 5, "%u,%u", &w, &h) != 2) { |
| 250 | LOG(ERROR, "Error parsing box size.\n"); |
| 251 | goto done; |
| 252 | } |
| 253 | } else if (strncmp("location=", tok, 9) == 0) { |
| 254 | if (sscanf(tok + 9, "%u,%u", &locx, &locy) != 2) { |
| 255 | LOG(ERROR, "Error parsing box location.\n"); |
| 256 | goto done; |
| 257 | } |
| 258 | use_location = true; |
| 259 | } else if (strncmp("offset=", tok, 7) == 0) { |
| 260 | if (sscanf(tok + 7, "%d,%d", &offx, &offy) != 2) { |
| 261 | LOG(ERROR, "Error parsing box offset.\n"); |
| 262 | goto done; |
| 263 | } |
| 264 | use_offset = true; |
| 265 | } else if (strncmp("scale=", tok, 6) == 0) { |
| 266 | if (sscanf(tok + 6, "%u", &scale) != 1) { |
| 267 | LOG(ERROR, "Error parsing box scale.\n"); |
| 268 | goto done; |
| 269 | } |
| 270 | if (scale == 0) |
| 271 | scale = image_get_auto_scale(term_getfb(terminal)); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | w *= scale; |
| 276 | h *= scale; |
| 277 | offx *= scale; |
| 278 | offy *= scale; |
| 279 | |
| 280 | buffer = fb_lock(terminal->fb); |
| 281 | if (buffer == NULL) |
| 282 | goto done; |
| 283 | |
| 284 | if (use_offset && use_location) { |
| 285 | LOG(WARNING, "Box offset and location set, using location."); |
| 286 | use_offset = false; |
| 287 | } |
| 288 | |
| 289 | if (use_location) { |
| 290 | startx = locx; |
| 291 | starty = locy; |
| 292 | } else { |
Mattias Nissler | 066044c | 2017-07-04 15:23:02 +0200 | [diff] [blame] | 293 | startx = (fb_getwidth(terminal->fb) - w)/2; |
| 294 | starty = (fb_getheight(terminal->fb) - h)/2; |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | if (use_offset) { |
| 298 | startx += offx; |
| 299 | starty += offy; |
| 300 | } |
| 301 | |
| 302 | pitch4 = fb_getpitch(terminal->fb) / 4; |
| 303 | |
| 304 | /* Completely outside buffer, do nothing */ |
| 305 | if (startx + w <= 0 || startx >= fb_getwidth(terminal->fb)) |
| 306 | goto done_fb; |
| 307 | if (starty + h <= 0 || starty >= fb_getheight(terminal->fb)) |
| 308 | goto done_fb; |
| 309 | /* Make sure we are inside buffer. */ |
| 310 | if (startx < 0) |
| 311 | startx = 0; |
Mattias Nissler | 066044c | 2017-07-04 15:23:02 +0200 | [diff] [blame] | 312 | if (w > (uint32_t)(fb_getwidth(terminal->fb) - startx)) |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 313 | w = fb_getwidth(terminal->fb) - startx; |
| 314 | if (starty < 0) |
| 315 | starty = 0; |
Mattias Nissler | 066044c | 2017-07-04 15:23:02 +0200 | [diff] [blame] | 316 | if (h > (uint32_t)(fb_getheight(terminal->fb) - starty)) |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 317 | h = fb_getheight(terminal->fb) - starty; |
| 318 | |
| 319 | for (uint32_t y = 0; y < h; y++) { |
| 320 | uint32_t *o = buffer + (starty + y) * pitch4 |
| 321 | + startx; |
| 322 | for (uint32_t x = 0; x < w; x++) |
| 323 | o[x] = color; |
| 324 | } |
| 325 | done_fb: |
| 326 | fb_unlock(terminal->fb); |
| 327 | done: |
| 328 | ; |
| 329 | } |
| 330 | |
Dominik Behr | da55e6c | 2017-02-28 18:12:10 -0800 | [diff] [blame] | 331 | static void term_esc_input(terminal_t* terminal, char* params) |
| 332 | { |
| 333 | if (strcmp(params, "1") == 0 || |
| 334 | strcasecmp(params, "on") == 0 || |
| 335 | strcasecmp(params, "true") == 0) |
| 336 | term_input_enable(terminal, true); |
| 337 | else if (strcmp(params, "0") == 0 || |
| 338 | strcasecmp(params, "off") == 0 || |
| 339 | strcasecmp(params, "false") == 0) |
| 340 | term_input_enable(terminal, false); |
| 341 | else |
| 342 | LOG(ERROR, "Invalid parameter for input escape.\n"); |
| 343 | } |
| 344 | |
Dominik Behr | 3a2c61c | 2017-06-22 15:13:48 -0700 | [diff] [blame] | 345 | /* |
| 346 | * Assume all one or two digit sequences followed by ; are xterm OSC escapes. |
| 347 | */ |
| 348 | static bool is_xterm_osc(char *osc) |
| 349 | { |
| 350 | if (isdigit(osc[0])) { |
| 351 | if (osc[1] == ';') |
| 352 | return true; |
| 353 | if (isdigit(osc[1]) && osc[2] == ';') |
| 354 | return true; |
| 355 | } |
| 356 | return false; |
| 357 | } |
| 358 | |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 359 | static void term_osc_cb(struct tsm_vte *vte, const uint32_t *osc_string, |
| 360 | size_t osc_len, void *data) |
| 361 | { |
| 362 | terminal_t* terminal = (terminal_t*)data; |
| 363 | size_t i; |
| 364 | char *osc; |
| 365 | |
| 366 | for (i = 0; i < osc_len; i++) |
| 367 | if (osc_string[i] >= 128) |
| 368 | return; /* we only want to deal with ASCII */ |
| 369 | |
| 370 | osc = malloc(osc_len + 1); |
| 371 | if (!osc) { |
Dominik Behr | 3a2c61c | 2017-06-22 15:13:48 -0700 | [diff] [blame] | 372 | LOG(WARNING, "Out of memory when processing OSC.\n"); |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 373 | return; |
| 374 | } |
| 375 | |
| 376 | for (i = 0; i < osc_len; i++) |
| 377 | osc[i] = (char)osc_string[i]; |
| 378 | osc[i] = '\0'; |
| 379 | |
| 380 | if (strncmp(osc, "image:", 6) == 0) |
| 381 | term_esc_show_image(terminal, osc + 6); |
| 382 | else if (strncmp(osc, "box:", 4) == 0) |
| 383 | term_esc_draw_box(terminal, osc + 4); |
Dominik Behr | da55e6c | 2017-02-28 18:12:10 -0800 | [diff] [blame] | 384 | else if (strncmp(osc, "input:", 6) == 0) |
| 385 | term_esc_input(terminal, osc + 6); |
Dominik Behr | 3a2c61c | 2017-06-22 15:13:48 -0700 | [diff] [blame] | 386 | else if (is_xterm_osc(osc)) |
| 387 | ; /* Ignore it. */ |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 388 | else |
| 389 | LOG(WARNING, "Unknown OSC escape sequence \"%s\", ignoring.", osc); |
| 390 | |
| 391 | free(osc); |
| 392 | } |
| 393 | |
Dominik Behr | 0000350 | 2014-08-15 16:42:37 -0700 | [diff] [blame] | 394 | #ifdef __clang__ |
| 395 | __attribute__((__format__ (__printf__, 7, 0))) |
| 396 | #endif |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 397 | static void log_tsm(void* data, const char* file, int line, const char* fn, |
Stéphane Marchesin | 8fc1352 | 2015-12-14 17:02:28 -0800 | [diff] [blame] | 398 | const char* subs, unsigned int sev, const char* format, |
| 399 | va_list args) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 400 | { |
Chris Morin | 255d9f0 | 2019-02-04 23:29:27 -0800 | [diff] [blame] | 401 | char buffer[KMSG_LINE_MAX]; |
| 402 | int len = snprintf(buffer, KMSG_LINE_MAX, "<%i>frecon[%d]: %s: ", sev, |
| 403 | getpid(), subs); |
| 404 | if (len < 0) |
| 405 | return; |
| 406 | if (len < KMSG_LINE_MAX - 1) |
| 407 | vsnprintf(buffer+len, KMSG_LINE_MAX - len, format, args); |
| 408 | fprintf(stderr, "%s\n", buffer); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Haixia Shi | 9528587 | 2016-11-08 15:26:35 -0800 | [diff] [blame] | 411 | static int term_resize(terminal_t* term, int scaling) |
Stéphane Marchesin | 7831066 | 2016-01-06 16:09:39 -0800 | [diff] [blame] | 412 | { |
| 413 | uint32_t char_width, char_height; |
| 414 | int status; |
| 415 | |
Haixia Shi | 9528587 | 2016-11-08 15:26:35 -0800 | [diff] [blame] | 416 | if (!scaling) |
| 417 | scaling = fb_getscaling(term->fb); |
| 418 | |
| 419 | font_init(scaling); |
Stéphane Marchesin | 7831066 | 2016-01-06 16:09:39 -0800 | [diff] [blame] | 420 | font_get_size(&char_width, &char_height); |
| 421 | |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 422 | term->term->char_x = fb_getwidth(term->fb) / char_width; |
| 423 | term->term->char_y = fb_getheight(term->fb) / char_height; |
| 424 | term->term->pitch = fb_getpitch(term->fb); |
Stéphane Marchesin | 7831066 | 2016-01-06 16:09:39 -0800 | [diff] [blame] | 425 | |
| 426 | status = tsm_screen_resize(term->term->screen, |
| 427 | term->term->char_x, term->term->char_y); |
| 428 | if (status < 0) { |
| 429 | font_free(); |
| 430 | return -1; |
| 431 | } |
| 432 | |
| 433 | status = shl_pty_resize(term->term->pty, term->term->char_x, |
| 434 | term->term->char_y); |
| 435 | if (status < 0) { |
| 436 | font_free(); |
| 437 | return -1; |
| 438 | } |
| 439 | |
| 440 | return 0; |
| 441 | } |
| 442 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 443 | void term_set_num_terminals(unsigned new_num) |
| 444 | { |
| 445 | if (new_num < 1) |
| 446 | term_num_terminals = 1; |
| 447 | else if (new_num > TERM_MAX_TERMINALS) |
| 448 | term_num_terminals = TERM_MAX_TERMINALS; |
| 449 | else |
| 450 | term_num_terminals = new_num; |
| 451 | } |
| 452 | |
| 453 | static bool term_is_interactive(unsigned int vt) |
| 454 | { |
| 455 | if (command_flags.no_login) |
| 456 | return false; |
| 457 | |
| 458 | if (vt == TERM_SPLASH_TERMINAL) |
| 459 | return command_flags.enable_vt1; |
| 460 | |
| 461 | return true; |
| 462 | } |
| 463 | |
Jacek Fedorynski | 9a0c422 | 2018-11-17 19:13:01 +0100 | [diff] [blame] | 464 | /* |
| 465 | * Set the area not covered by any characters, possibly existing on the right |
| 466 | * side and bottom of the screen, to the background color. |
| 467 | */ |
| 468 | static void term_clear_border(terminal_t* terminal) |
| 469 | { |
| 470 | uint32_t char_width, char_height; |
| 471 | font_get_size(&char_width, &char_height); |
| 472 | int32_t width = fb_getwidth(terminal->fb); |
| 473 | int32_t height = fb_getheight(terminal->fb); |
| 474 | int32_t pitch4 = fb_getpitch(terminal->fb) / 4; |
| 475 | uint32_t* fb_buffer = fb_lock(terminal->fb); |
| 476 | |
| 477 | if (fb_buffer) { |
| 478 | for (uint32_t y = 0; y < terminal->term->char_y * char_height; |
| 479 | y++) { |
| 480 | for (int32_t x = terminal->term->char_x * char_width; |
| 481 | x < width; x++) { |
| 482 | fb_buffer[y * pitch4 + x] = terminal->background; |
| 483 | } |
| 484 | } |
| 485 | for (int32_t y = terminal->term->char_y * char_height; |
| 486 | y < height; y++) { |
| 487 | for (int32_t x = 0; x < width; x++) { |
| 488 | fb_buffer[y * pitch4 + x] = terminal->background; |
| 489 | } |
| 490 | } |
| 491 | fb_unlock(terminal->fb); |
| 492 | } |
| 493 | } |
| 494 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 495 | terminal_t* term_init(unsigned vt, int pts_fd) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 496 | { |
| 497 | const int scrollback_size = 200; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 498 | int status; |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 499 | terminal_t* new_terminal; |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 500 | bool interactive = term_is_interactive(vt); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 501 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 502 | new_terminal = (terminal_t*)calloc(1, sizeof(*new_terminal)); |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 503 | if (!new_terminal) |
| 504 | return NULL; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 505 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 506 | new_terminal->vt = vt; |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 507 | new_terminal->background_valid = false; |
Dominik Behr | da55e6c | 2017-02-28 18:12:10 -0800 | [diff] [blame] | 508 | new_terminal->input_enable = true; |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 509 | |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 510 | new_terminal->fb = fb_init(); |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 511 | |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 512 | if (!new_terminal->fb) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 513 | LOG(ERROR, "Failed to create fb on VT%u.", vt); |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 514 | term_close(new_terminal); |
| 515 | return NULL; |
| 516 | } |
| 517 | |
| 518 | new_terminal->term = (struct term*)calloc(1, sizeof(*new_terminal->term)); |
| 519 | if (!new_terminal->term) { |
| 520 | term_close(new_terminal); |
| 521 | return NULL; |
| 522 | } |
| 523 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 524 | if (interactive) |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 525 | new_terminal->exec = interactive_cmd_line; |
| 526 | else |
Dominik Behr | 32680e3 | 2016-08-16 12:18:41 -0700 | [diff] [blame] | 527 | new_terminal->exec = NULL; |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 528 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 529 | status = tsm_screen_new(&new_terminal->term->screen, |
| 530 | log_tsm, new_terminal->term); |
zhuo-hao | 471f1e2 | 2015-08-12 14:55:56 +0800 | [diff] [blame] | 531 | if (status < 0) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 532 | LOG(ERROR, "Failed to create new screen on VT%u.", vt); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 533 | term_close(new_terminal); |
| 534 | return NULL; |
| 535 | } |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 536 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 537 | tsm_screen_set_max_sb(new_terminal->term->screen, scrollback_size); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 538 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 539 | status = tsm_vte_new(&new_terminal->term->vte, new_terminal->term->screen, |
| 540 | term_write_cb, new_terminal->term, log_tsm, new_terminal->term); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 541 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 542 | if (status < 0) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 543 | LOG(ERROR, "Failed to create new VT%u.", vt); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 544 | term_close(new_terminal); |
| 545 | return NULL; |
| 546 | } |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 547 | |
Dominik Behr | da55e6c | 2017-02-28 18:12:10 -0800 | [diff] [blame] | 548 | if (command_flags.enable_osc) |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 549 | tsm_vte_set_osc_cb(new_terminal->term->vte, term_osc_cb, (void *)new_terminal); |
| 550 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 551 | new_terminal->term->pty_bridge = shl_pty_bridge_new(); |
| 552 | if (new_terminal->term->pty_bridge < 0) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 553 | LOG(ERROR, "Failed to create pty bridge on VT%u.", vt); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 554 | term_close(new_terminal); |
| 555 | return NULL; |
| 556 | } |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 557 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 558 | status = shl_pty_open(&new_terminal->term->pty, |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 559 | term_read_cb, new_terminal, 1, 1, pts_fd); |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 560 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 561 | if (status < 0) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 562 | LOG(ERROR, "Failed to open pty on VT%u.", vt); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 563 | term_close(new_terminal); |
| 564 | return NULL; |
| 565 | } else if (status == 0) { |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 566 | term_run_child(new_terminal); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 567 | exit(1); |
| 568 | } |
| 569 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 570 | status = mkdir(FRECON_RUN_DIR, S_IRWXU); |
| 571 | if (status == 0 || (status < 0 && errno == EEXIST)) { |
| 572 | char path[32]; |
| 573 | snprintf(path, sizeof(path), FRECON_VT_PATH, vt); |
Dominik Behr | b23b05b | 2016-08-15 16:29:02 -0700 | [diff] [blame] | 574 | unlink(path); /* In case it already exists. Ignore return codes. */ |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 575 | if (symlink(ptsname(shl_pty_get_fd(new_terminal->term->pty)), path) < 0) |
| 576 | LOG(ERROR, "Failed to symlink pts name %s to %s, %d:%s", |
| 577 | path, |
| 578 | ptsname(shl_pty_get_fd(new_terminal->term->pty)), |
| 579 | errno, strerror(errno)); |
| 580 | } |
| 581 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 582 | status = shl_pty_bridge_add(new_terminal->term->pty_bridge, new_terminal->term->pty); |
| 583 | if (status) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 584 | LOG(ERROR, "Failed to add pty bridge on VT%u.", vt); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 585 | term_close(new_terminal); |
| 586 | return NULL; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 587 | } |
| 588 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 589 | new_terminal->term->pid = shl_pty_get_child(new_terminal->term->pty); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 590 | |
Haixia Shi | 9528587 | 2016-11-08 15:26:35 -0800 | [diff] [blame] | 591 | status = term_resize(new_terminal, 0); |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 592 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 593 | if (status < 0) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 594 | LOG(ERROR, "Failed to resize VT%u.", vt); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 595 | term_close(new_terminal); |
| 596 | return NULL; |
| 597 | } |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 598 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 599 | return new_terminal; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 600 | } |
| 601 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 602 | void term_activate(terminal_t* terminal) |
| 603 | { |
Dominik Behr | 4defb36 | 2016-01-13 12:36:14 -0800 | [diff] [blame] | 604 | term_set_current_to(terminal); |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 605 | terminal->active = true; |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 606 | fb_setmode(terminal->fb); |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 607 | term_redraw(terminal); |
| 608 | } |
| 609 | |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 610 | void term_deactivate(terminal_t* terminal) |
| 611 | { |
| 612 | if (!terminal->active) |
| 613 | return; |
| 614 | |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 615 | terminal->active = false; |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 618 | void term_close(terminal_t* term) |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 619 | { |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 620 | char path[32]; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 621 | if (!term) |
| 622 | return; |
| 623 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 624 | snprintf(path, sizeof(path), FRECON_VT_PATH, term->vt); |
| 625 | unlink(path); |
| 626 | |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 627 | if (term->fb) { |
| 628 | fb_close(term->fb); |
| 629 | term->fb = NULL; |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 630 | } |
| 631 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 632 | if (term->term) { |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 633 | if (term->term->pty) { |
| 634 | if (term->term->pty_bridge >= 0) { |
| 635 | shl_pty_bridge_remove(term->term->pty_bridge, term->term->pty); |
| 636 | shl_pty_bridge_free(term->term->pty_bridge); |
| 637 | term->term->pty_bridge = -1; |
| 638 | } |
| 639 | shl_pty_close(term->term->pty); |
| 640 | term->term->pty = NULL; |
| 641 | } |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 642 | free(term->term); |
| 643 | term->term = NULL; |
| 644 | } |
| 645 | |
Haixia Shi | 95d680e | 2015-04-27 20:29:17 -0700 | [diff] [blame] | 646 | font_free(); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 647 | free(term); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 648 | } |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 649 | |
| 650 | bool term_is_child_done(terminal_t* terminal) |
| 651 | { |
| 652 | int status; |
| 653 | int ret; |
| 654 | ret = waitpid(terminal->term->pid, &status, WNOHANG); |
| 655 | |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 656 | if ((ret == -1) && (errno == ECHILD)) { |
| 657 | return false; |
| 658 | } |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 659 | return ret != 0; |
| 660 | } |
| 661 | |
| 662 | void term_page_up(terminal_t* terminal) |
| 663 | { |
| 664 | tsm_screen_sb_page_up(terminal->term->screen, 1); |
| 665 | term_redraw(terminal); |
| 666 | } |
| 667 | |
| 668 | void term_page_down(terminal_t* terminal) |
| 669 | { |
| 670 | tsm_screen_sb_page_down(terminal->term->screen, 1); |
| 671 | term_redraw(terminal); |
| 672 | } |
| 673 | |
| 674 | void term_line_up(terminal_t* terminal) |
| 675 | { |
| 676 | tsm_screen_sb_up(terminal->term->screen, 1); |
| 677 | term_redraw(terminal); |
| 678 | } |
| 679 | |
| 680 | void term_line_down(terminal_t* terminal) |
| 681 | { |
| 682 | tsm_screen_sb_down(terminal->term->screen, 1); |
| 683 | term_redraw(terminal); |
| 684 | } |
| 685 | |
| 686 | bool term_is_valid(terminal_t* terminal) |
| 687 | { |
| 688 | return ((terminal != NULL) && (terminal->term != NULL)); |
| 689 | } |
| 690 | |
| 691 | int term_fd(terminal_t* terminal) |
| 692 | { |
| 693 | if (term_is_valid(terminal)) |
| 694 | return terminal->term->pty_bridge; |
| 695 | else |
| 696 | return -1; |
| 697 | } |
| 698 | |
| 699 | void term_dispatch_io(terminal_t* terminal, fd_set* read_set) |
| 700 | { |
| 701 | if (term_is_valid(terminal)) |
| 702 | if (FD_ISSET(terminal->term->pty_bridge, read_set)) |
| 703 | shl_pty_bridge_dispatch(terminal->term->pty_bridge, 0); |
| 704 | } |
| 705 | |
| 706 | bool term_exception(terminal_t* terminal, fd_set* exception_set) |
| 707 | { |
| 708 | if (term_is_valid(terminal)) { |
| 709 | if (terminal->term->pty_bridge >= 0) { |
| 710 | return FD_ISSET(terminal->term->pty_bridge, |
| 711 | exception_set); |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | return false; |
| 716 | } |
| 717 | |
| 718 | bool term_is_active(terminal_t* terminal) |
| 719 | { |
| 720 | if (term_is_valid(terminal)) |
| 721 | return terminal->active; |
| 722 | |
| 723 | return false; |
| 724 | } |
| 725 | |
Dominik Behr | b1abcba | 2016-04-14 14:57:21 -0700 | [diff] [blame] | 726 | void term_add_fds(terminal_t* terminal, fd_set* read_set, fd_set* exception_set, int* maxfd) |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 727 | { |
| 728 | if (term_is_valid(terminal)) { |
| 729 | if (terminal->term->pty_bridge >= 0) { |
Dominik Behr | d711267 | 2016-01-20 16:59:34 -0800 | [diff] [blame] | 730 | *maxfd = MAX(*maxfd, terminal->term->pty_bridge); |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 731 | FD_SET(terminal->term->pty_bridge, read_set); |
| 732 | FD_SET(terminal->term->pty_bridge, exception_set); |
| 733 | } |
| 734 | } |
| 735 | } |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 736 | |
| 737 | const char* term_get_ptsname(terminal_t* terminal) |
| 738 | { |
| 739 | return ptsname(shl_pty_get_fd(terminal->term->pty)); |
| 740 | } |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 741 | |
| 742 | void term_set_background(terminal_t* terminal, uint32_t bg) |
| 743 | { |
| 744 | terminal->background = bg; |
| 745 | terminal->background_valid = true; |
| 746 | } |
| 747 | |
| 748 | int term_show_image(terminal_t* terminal, image_t* image) |
| 749 | { |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 750 | return image_show(image, terminal->fb); |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | void term_write_message(terminal_t* terminal, char* message) |
| 754 | { |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 755 | FILE* fp; |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 756 | |
| 757 | fp = fopen(term_get_ptsname(terminal), "w"); |
| 758 | if (fp) { |
| 759 | fputs(message, fp); |
| 760 | fclose(fp); |
| 761 | } |
| 762 | } |
| 763 | |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 764 | static void term_hide_cursor(terminal_t* terminal) |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 765 | { |
| 766 | term_write_message(terminal, "\033[?25l"); |
| 767 | } |
| 768 | |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 769 | __attribute__ ((unused)) |
| 770 | static void term_show_cursor(terminal_t* terminal) |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 771 | { |
| 772 | term_write_message(terminal, "\033[?25h"); |
| 773 | } |
David Sodman | 30a94ef | 2015-07-26 17:37:12 -0700 | [diff] [blame] | 774 | |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 775 | fb_t* term_getfb(terminal_t* terminal) |
David Sodman | 30a94ef | 2015-07-26 17:37:12 -0700 | [diff] [blame] | 776 | { |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 777 | return terminal->fb; |
David Sodman | 30a94ef | 2015-07-26 17:37:12 -0700 | [diff] [blame] | 778 | } |
Stéphane Marchesin | 08c08e7 | 2016-01-07 16:44:08 -0800 | [diff] [blame] | 779 | |
| 780 | terminal_t* term_get_terminal(int num) |
| 781 | { |
| 782 | return terminals[num]; |
| 783 | } |
| 784 | |
| 785 | void term_set_terminal(int num, terminal_t* terminal) |
| 786 | { |
| 787 | terminals[num] = terminal; |
| 788 | } |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 789 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 790 | int term_create_splash_term(int pts_fd) |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 791 | { |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 792 | terminal_t* terminal = term_init(TERM_SPLASH_TERMINAL, pts_fd); |
| 793 | |
| 794 | if (!terminal) { |
| 795 | LOG(ERROR, "Could not create splash term."); |
| 796 | return -1; |
| 797 | } |
| 798 | term_set_terminal(TERM_SPLASH_TERMINAL, terminal); |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 799 | |
| 800 | // Hide the cursor on the splash screen |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 801 | term_hide_cursor(terminal); |
| 802 | return 0; |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 803 | } |
| 804 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 805 | void term_destroy_splash_term(void) |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 806 | { |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 807 | terminal_t *terminal; |
| 808 | if (command_flags.enable_vt1) { |
| 809 | return; |
| 810 | } |
Jacek Fedorynski | 83776b7 | 2019-03-06 22:56:56 +0100 | [diff] [blame^] | 811 | terminal = term_get_terminal(TERM_SPLASH_TERMINAL); |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 812 | term_set_terminal(TERM_SPLASH_TERMINAL, NULL); |
| 813 | term_close(terminal); |
Stéphane Marchesin | 92a297d | 2016-01-07 20:24:55 -0800 | [diff] [blame] | 814 | } |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 815 | |
Dominik Behr | 4defb36 | 2016-01-13 12:36:14 -0800 | [diff] [blame] | 816 | void term_set_current(uint32_t t) |
| 817 | { |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 818 | if (t >= TERM_MAX_TERMINALS) |
| 819 | LOG(ERROR, "set_current: larger than array size"); |
| 820 | else |
| 821 | if (t >= term_num_terminals) |
| 822 | LOG(ERROR, "set_current: larger than num terminals"); |
Dominik Behr | 4defb36 | 2016-01-13 12:36:14 -0800 | [diff] [blame] | 823 | else |
| 824 | current_terminal = t; |
| 825 | } |
| 826 | |
| 827 | uint32_t term_get_current(void) |
| 828 | { |
| 829 | return current_terminal; |
| 830 | } |
| 831 | |
| 832 | terminal_t *term_get_current_terminal(void) |
| 833 | { |
| 834 | return terminals[current_terminal]; |
| 835 | } |
| 836 | |
Dominik Behr | b1abcba | 2016-04-14 14:57:21 -0700 | [diff] [blame] | 837 | void term_set_current_terminal(terminal_t* terminal) |
Dominik Behr | 4defb36 | 2016-01-13 12:36:14 -0800 | [diff] [blame] | 838 | { |
| 839 | terminals[current_terminal] = terminal; |
| 840 | } |
| 841 | |
| 842 | void term_set_current_to(terminal_t* terminal) |
| 843 | { |
| 844 | if (!terminal) { |
Haixia Shi | 9528587 | 2016-11-08 15:26:35 -0800 | [diff] [blame] | 845 | if (terminals[current_terminal]) |
| 846 | term_close(terminals[current_terminal]); |
Dominik Behr | 4defb36 | 2016-01-13 12:36:14 -0800 | [diff] [blame] | 847 | terminals[current_terminal] = NULL; |
| 848 | current_terminal = 0; |
| 849 | return; |
| 850 | } |
| 851 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 852 | for (unsigned i = 0; i < term_num_terminals; i++) { |
Dominik Behr | 4defb36 | 2016-01-13 12:36:14 -0800 | [diff] [blame] | 853 | if (terminal == terminals[i]) { |
| 854 | current_terminal = i; |
| 855 | return; |
| 856 | } |
| 857 | } |
| 858 | LOG(ERROR, "set_current_to: terminal not in array"); |
| 859 | } |
Dominik Behr | 01a7a58 | 2016-01-28 17:02:21 -0800 | [diff] [blame] | 860 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 861 | int term_switch_to(unsigned int vt) |
| 862 | { |
| 863 | terminal_t *terminal; |
| 864 | if (vt == term_get_current()) { |
| 865 | terminal = term_get_current_terminal(); |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 866 | if (term_is_valid(terminal)) { |
| 867 | if (!term_is_active(terminal)) |
| 868 | term_activate(terminal); |
| 869 | return vt; |
| 870 | } |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | if (vt >= term_num_terminals) |
| 874 | return -EINVAL; |
| 875 | |
| 876 | terminal = term_get_current_terminal(); |
| 877 | if (term_is_active(terminal)) |
| 878 | term_deactivate(terminal); |
| 879 | |
| 880 | if (vt == TERM_SPLASH_TERMINAL |
| 881 | && !term_get_terminal(TERM_SPLASH_TERMINAL) |
| 882 | && !command_flags.enable_vt1) { |
| 883 | term_set_current(vt); |
| 884 | /* Splash term is already gone, returning to Chrome. */ |
Dominik Behr | 3384733 | 2016-12-12 17:27:56 -0800 | [diff] [blame] | 885 | term_background(false); |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 886 | return vt; |
| 887 | } |
| 888 | |
| 889 | term_foreground(); |
| 890 | |
| 891 | term_set_current(vt); |
| 892 | terminal = term_get_current_terminal(); |
| 893 | if (!terminal) { |
| 894 | /* No terminal where we are switching to, create new one. */ |
| 895 | term_set_current_terminal(term_init(vt, -1)); |
| 896 | terminal = term_get_current_terminal(); |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 897 | if (!term_is_valid(terminal)) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 898 | LOG(ERROR, "Term init failed VT%u.", vt); |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 899 | return -1; |
| 900 | } |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 901 | term_activate(terminal); |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 902 | } else { |
| 903 | term_activate(terminal); |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | return vt; |
| 907 | } |
| 908 | |
Dominik Behr | 01a7a58 | 2016-01-28 17:02:21 -0800 | [diff] [blame] | 909 | void term_monitor_hotplug(void) |
| 910 | { |
| 911 | unsigned int t; |
| 912 | |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 913 | if (in_background) { |
| 914 | hotplug_occured = true; |
| 915 | return; |
| 916 | } |
| 917 | |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 918 | if (!drm_rescan()) |
| 919 | return; |
| 920 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 921 | for (t = 0; t < term_num_terminals; t++) { |
Dominik Behr | 01a7a58 | 2016-01-28 17:02:21 -0800 | [diff] [blame] | 922 | if (!terminals[t]) |
| 923 | continue; |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 924 | if (!terminals[t]->fb) |
Dominik Behr | 01a7a58 | 2016-01-28 17:02:21 -0800 | [diff] [blame] | 925 | continue; |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 926 | fb_buffer_destroy(terminals[t]->fb); |
Dominik Behr | a3f6571 | 2016-04-25 17:42:14 -0700 | [diff] [blame] | 927 | font_free(); |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 930 | for (t = 0; t < term_num_terminals; t++) { |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 931 | if (!terminals[t]) |
| 932 | continue; |
| 933 | if (!terminals[t]->fb) |
| 934 | continue; |
| 935 | fb_buffer_init(terminals[t]->fb); |
Haixia Shi | 9528587 | 2016-11-08 15:26:35 -0800 | [diff] [blame] | 936 | term_resize(terminals[t], 0); |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 937 | if (current_terminal == t && terminals[t]->active) |
| 938 | fb_setmode(terminals[t]->fb); |
| 939 | terminals[t]->term->age = 0; |
| 940 | term_redraw(terminals[t]); |
Dominik Behr | 01a7a58 | 2016-01-28 17:02:21 -0800 | [diff] [blame] | 941 | } |
| 942 | } |
Dominik Behr | b1abcba | 2016-04-14 14:57:21 -0700 | [diff] [blame] | 943 | |
| 944 | void term_redrm(terminal_t* terminal) |
| 945 | { |
| 946 | fb_buffer_destroy(terminal->fb); |
Dominik Behr | a3f6571 | 2016-04-25 17:42:14 -0700 | [diff] [blame] | 947 | font_free(); |
Dominik Behr | b1abcba | 2016-04-14 14:57:21 -0700 | [diff] [blame] | 948 | fb_buffer_init(terminal->fb); |
Haixia Shi | 9528587 | 2016-11-08 15:26:35 -0800 | [diff] [blame] | 949 | term_resize(terminal, 0); |
Dominik Behr | b1abcba | 2016-04-14 14:57:21 -0700 | [diff] [blame] | 950 | terminal->term->age = 0; |
| 951 | term_redraw(terminal); |
| 952 | } |
| 953 | |
| 954 | void term_clear(terminal_t* terminal) |
| 955 | { |
Jacek Fedorynski | 9a0c422 | 2018-11-17 19:13:01 +0100 | [diff] [blame] | 956 | term_clear_border(terminal); |
Dominik Behr | b1abcba | 2016-04-14 14:57:21 -0700 | [diff] [blame] | 957 | tsm_screen_erase_screen(terminal->term->screen, false); |
| 958 | term_redraw(terminal); |
| 959 | } |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 960 | |
Haixia Shi | 9528587 | 2016-11-08 15:26:35 -0800 | [diff] [blame] | 961 | void term_zoom(bool zoom_in) |
| 962 | { |
| 963 | int scaling = font_get_scaling(); |
| 964 | if (zoom_in && scaling < 4) |
| 965 | scaling++; |
| 966 | else if (!zoom_in && scaling > 1) |
| 967 | scaling--; |
| 968 | else |
| 969 | return; |
| 970 | |
| 971 | unsigned int t; |
| 972 | for (t = 0; t < term_num_terminals; t++) { |
| 973 | if (terminals[t]) |
| 974 | font_free(); |
| 975 | } |
| 976 | for (t = 0; t < term_num_terminals; t++) { |
| 977 | terminal_t* term = terminals[t]; |
| 978 | if (term) { |
| 979 | term_resize(term, scaling); |
| 980 | term->term->age = 0; |
| 981 | term_redraw(term); |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | |
Dominik Behr | 3384733 | 2016-12-12 17:27:56 -0800 | [diff] [blame] | 986 | /* |
| 987 | * Put frecon in background. Give up DRM master. |
| 988 | * onetry - if true, do not retry to notify Chrome multiple times. For use at |
| 989 | * time when Chrome may be not around yet to receive the message. |
| 990 | */ |
| 991 | void term_background(bool onetry) |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 992 | { |
Dominik Behr | 3384733 | 2016-12-12 17:27:56 -0800 | [diff] [blame] | 993 | int retry = onetry ? 1 : 5; |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 994 | if (in_background) |
| 995 | return; |
| 996 | in_background = true; |
Dominik Behr | da3c010 | 2016-06-08 15:05:38 -0700 | [diff] [blame] | 997 | drm_dropmaster(NULL); |
Dominik Behr | a818a1e | 2016-10-26 19:46:22 -0700 | [diff] [blame] | 998 | while (!dbus_take_display_ownership() && retry--) { |
Dominik Behr | 3384733 | 2016-12-12 17:27:56 -0800 | [diff] [blame] | 999 | if (onetry) |
| 1000 | break; |
Dominik Behr | a818a1e | 2016-10-26 19:46:22 -0700 | [diff] [blame] | 1001 | LOG(ERROR, "Chrome failed to take display ownership. %s", |
| 1002 | retry ? "Trying again." : "Giving up, Chrome is probably dead."); |
Dominik Behr | 3384733 | 2016-12-12 17:27:56 -0800 | [diff] [blame] | 1003 | if (retry > 0) |
| 1004 | usleep(500 * 1000); |
Dominik Behr | a818a1e | 2016-10-26 19:46:22 -0700 | [diff] [blame] | 1005 | } |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | void term_foreground(void) |
| 1009 | { |
Dominik Behr | da3c010 | 2016-06-08 15:05:38 -0700 | [diff] [blame] | 1010 | int ret; |
Dominik Behr | 3384733 | 2016-12-12 17:27:56 -0800 | [diff] [blame] | 1011 | int retry = 5; |
Dominik Behr | a818a1e | 2016-10-26 19:46:22 -0700 | [diff] [blame] | 1012 | |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 1013 | if (!in_background) |
| 1014 | return; |
| 1015 | in_background = false; |
Dominik Behr | a818a1e | 2016-10-26 19:46:22 -0700 | [diff] [blame] | 1016 | |
Dominik Behr | 57b5c72 | 2018-08-08 18:52:31 -0700 | [diff] [blame] | 1017 | /* LOG(INFO, "TIMING: Console switch time start."); */ /* Keep around for timing it in the future. */ |
Dominik Behr | a818a1e | 2016-10-26 19:46:22 -0700 | [diff] [blame] | 1018 | while (!dbus_release_display_ownership() && retry--) { |
| 1019 | LOG(ERROR, "Chrome did not release master. %s", |
| 1020 | retry ? "Trying again." : "Frecon will steal master."); |
Dominik Behr | 3384733 | 2016-12-12 17:27:56 -0800 | [diff] [blame] | 1021 | if (retry > 0) |
| 1022 | usleep(500 * 1000); |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 1023 | } |
Dominik Behr | da3c010 | 2016-06-08 15:05:38 -0700 | [diff] [blame] | 1024 | |
Dominik Behr | 57b5c72 | 2018-08-08 18:52:31 -0700 | [diff] [blame] | 1025 | /* LOG(INFO, "TIMING: Console switch setmaster."); */ |
Dominik Behr | da3c010 | 2016-06-08 15:05:38 -0700 | [diff] [blame] | 1026 | ret = drm_setmaster(NULL); |
Dominik Behr | da3c010 | 2016-06-08 15:05:38 -0700 | [diff] [blame] | 1027 | if (ret < 0) |
| 1028 | LOG(ERROR, "Could not set master when switching to foreground %m."); |
| 1029 | |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 1030 | if (hotplug_occured) { |
| 1031 | hotplug_occured = false; |
| 1032 | term_monitor_hotplug(); |
| 1033 | } |
| 1034 | } |
Dominik Behr | 1883c04 | 2016-04-27 12:31:02 -0700 | [diff] [blame] | 1035 | |
| 1036 | void term_suspend_done(void* ignore) |
| 1037 | { |
| 1038 | term_monitor_hotplug(); |
| 1039 | } |
Dominik Behr | da55e6c | 2017-02-28 18:12:10 -0800 | [diff] [blame] | 1040 | |
| 1041 | void term_input_enable(terminal_t* terminal, bool input_enable) |
| 1042 | { |
| 1043 | terminal->input_enable = input_enable; |
| 1044 | } |