2009-06-01 22:58:49 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2009-06-01 22:58:49 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
2011-05-18 20:24:29 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
2016-11-15 14:02:32 +00:00
|
|
|
#include <curses.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2011-05-18 20:24:29 +00:00
|
|
|
#include <resolv.h>
|
2009-10-12 13:01:18 +00:00
|
|
|
#include <stdlib.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static int tty_log_fd = -1;
|
2015-10-31 13:12:03 +00:00
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static int tty_client_ready(struct client *, struct window_pane *);
|
2016-04-30 18:59:02 +00:00
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void tty_set_italics(struct tty *);
|
|
|
|
static int tty_try_colour(struct tty *, int, const char *);
|
2016-10-11 13:21:59 +00:00
|
|
|
static void tty_force_cursor_colour(struct tty *, const char *);
|
|
|
|
static void tty_cursor_pane(struct tty *, const struct tty_ctx *, u_int,
|
|
|
|
u_int);
|
2017-03-15 09:21:21 +00:00
|
|
|
static void tty_cursor_pane_unless_wrap(struct tty *,
|
|
|
|
const struct tty_ctx *, u_int, u_int);
|
2017-02-08 23:53:03 +00:00
|
|
|
static void tty_invalidate(struct tty *);
|
2016-10-10 21:29:23 +00:00
|
|
|
static void tty_colours(struct tty *, const struct grid_cell *);
|
2017-01-07 15:28:13 +00:00
|
|
|
static void tty_check_fg(struct tty *, const struct window_pane *,
|
|
|
|
struct grid_cell *);
|
|
|
|
static void tty_check_bg(struct tty *, const struct window_pane *,
|
|
|
|
struct grid_cell *);
|
2016-10-10 21:29:23 +00:00
|
|
|
static void tty_colours_fg(struct tty *, const struct grid_cell *);
|
|
|
|
static void tty_colours_bg(struct tty *, const struct grid_cell *);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void tty_region_pane(struct tty *, const struct tty_ctx *, u_int,
|
|
|
|
u_int);
|
2016-11-15 15:17:28 +00:00
|
|
|
static void tty_region(struct tty *, u_int, u_int);
|
2016-11-15 14:02:32 +00:00
|
|
|
static void tty_margin_pane(struct tty *, const struct tty_ctx *);
|
2016-11-15 15:17:28 +00:00
|
|
|
static void tty_margin(struct tty *, u_int, u_int);
|
2016-10-10 21:29:23 +00:00
|
|
|
static int tty_large_region(struct tty *, const struct tty_ctx *);
|
2016-10-13 20:27:27 +00:00
|
|
|
static int tty_fake_bce(const struct tty *, const struct window_pane *,
|
|
|
|
u_int);
|
2016-10-10 21:29:23 +00:00
|
|
|
static void tty_redraw_region(struct tty *, const struct tty_ctx *);
|
|
|
|
static void tty_emulate_repeat(struct tty *, enum tty_code_code,
|
|
|
|
enum tty_code_code, u_int);
|
|
|
|
static void tty_repeat_space(struct tty *, u_int);
|
|
|
|
static void tty_cell(struct tty *, const struct grid_cell *,
|
|
|
|
const struct window_pane *);
|
|
|
|
static void tty_default_colours(struct grid_cell *,
|
|
|
|
const struct window_pane *);
|
2016-10-13 20:27:27 +00:00
|
|
|
static void tty_default_attributes(struct tty *, const struct window_pane *,
|
|
|
|
u_int);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2010-09-11 16:19:22 +00:00
|
|
|
#define tty_use_acs(tty) \
|
2012-05-05 18:31:09 +00:00
|
|
|
(tty_term_has((tty)->term, TTYC_ACSC) && !((tty)->flags & TTY_UTF8))
|
2016-11-15 14:02:32 +00:00
|
|
|
#define tty_use_margin(tty) \
|
2016-11-15 15:17:28 +00:00
|
|
|
((tty)->term_type == TTY_VT420)
|
2010-09-11 16:19:22 +00:00
|
|
|
|
2017-02-06 22:05:11 +00:00
|
|
|
#define tty_pane_full_width(tty, ctx) \
|
2012-05-05 18:45:55 +00:00
|
|
|
((ctx)->xoff == 0 && screen_size_x((ctx)->wp->screen) >= (tty)->sx)
|
|
|
|
|
2015-10-31 13:12:03 +00:00
|
|
|
void
|
|
|
|
tty_create_log(void)
|
|
|
|
{
|
|
|
|
char name[64];
|
|
|
|
|
|
|
|
xsnprintf(name, sizeof name, "tmux-out-%ld.log", (long)getpid());
|
|
|
|
|
|
|
|
tty_log_fd = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
|
|
|
if (tty_log_fd != -1 && fcntl(tty_log_fd, F_SETFD, FD_CLOEXEC) == -1)
|
|
|
|
fatal("fcntl failed");
|
|
|
|
}
|
|
|
|
|
2015-07-13 15:51:31 +00:00
|
|
|
int
|
2012-05-22 14:32:28 +00:00
|
|
|
tty_init(struct tty *tty, struct client *c, int fd, char *term)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-09-23 06:05:02 +00:00
|
|
|
char *path;
|
|
|
|
|
2015-07-13 15:51:31 +00:00
|
|
|
if (!isatty(fd))
|
|
|
|
return (-1);
|
|
|
|
|
2009-09-23 06:05:02 +00:00
|
|
|
memset(tty, 0, sizeof *tty);
|
2009-08-11 21:28:11 +00:00
|
|
|
|
2009-07-07 17:24:32 +00:00
|
|
|
if (term == NULL || *term == '\0')
|
2017-01-11 16:09:57 +00:00
|
|
|
tty->term_name = xstrdup("unknown");
|
2009-06-01 22:58:49 +00:00
|
|
|
else
|
2017-01-11 16:09:57 +00:00
|
|
|
tty->term_name = xstrdup(term);
|
2009-09-23 06:05:02 +00:00
|
|
|
tty->fd = fd;
|
2012-05-22 14:32:28 +00:00
|
|
|
tty->client = c;
|
2009-09-23 06:05:02 +00:00
|
|
|
|
|
|
|
if ((path = ttyname(fd)) == NULL)
|
2015-07-13 15:51:31 +00:00
|
|
|
return (-1);
|
2009-09-23 06:05:02 +00:00
|
|
|
tty->path = xstrdup(path);
|
2011-05-20 19:17:39 +00:00
|
|
|
tty->cstyle = 0;
|
2011-05-20 19:03:58 +00:00
|
|
|
tty->ccolour = xstrdup("");
|
2009-09-23 06:05:02 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
tty->flags = 0;
|
2016-11-15 14:02:32 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
tty->term_flags = 0;
|
2016-11-15 14:02:32 +00:00
|
|
|
tty->term_type = TTY_UNKNOWN;
|
2015-07-13 15:51:31 +00:00
|
|
|
|
|
|
|
return (0);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2010-06-05 16:47:11 +00:00
|
|
|
int
|
2009-09-23 06:12:58 +00:00
|
|
|
tty_resize(struct tty *tty)
|
|
|
|
{
|
|
|
|
struct winsize ws;
|
2010-06-05 16:47:11 +00:00
|
|
|
u_int sx, sy;
|
2009-09-23 06:12:58 +00:00
|
|
|
|
|
|
|
if (ioctl(tty->fd, TIOCGWINSZ, &ws) != -1) {
|
2010-06-05 16:47:11 +00:00
|
|
|
sx = ws.ws_col;
|
|
|
|
if (sx == 0)
|
|
|
|
sx = 80;
|
|
|
|
sy = ws.ws_row;
|
|
|
|
if (sy == 0)
|
|
|
|
sy = 24;
|
|
|
|
} else {
|
|
|
|
sx = 80;
|
|
|
|
sy = 24;
|
2009-09-23 06:12:58 +00:00
|
|
|
}
|
2017-02-08 13:53:32 +00:00
|
|
|
log_debug("%s: %s now %ux%u", __func__, tty->path, sx, sy);
|
2012-02-15 17:25:02 +00:00
|
|
|
if (!tty_set_size(tty, sx, sy))
|
2010-06-05 16:47:11 +00:00
|
|
|
return (0);
|
2017-02-08 23:53:03 +00:00
|
|
|
tty_invalidate(tty);
|
2010-06-05 16:47:11 +00:00
|
|
|
return (1);
|
2009-09-23 06:12:58 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 17:25:02 +00:00
|
|
|
int
|
2016-11-15 14:02:32 +00:00
|
|
|
tty_set_size(struct tty *tty, u_int sx, u_int sy)
|
|
|
|
{
|
2012-02-15 17:25:02 +00:00
|
|
|
if (sx == tty->sx && sy == tty->sy)
|
|
|
|
return (0);
|
|
|
|
tty->sx = sx;
|
|
|
|
tty->sy = sy;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2017-02-10 12:59:18 +00:00
|
|
|
tty_read_callback(__unused int fd, __unused short events, void *data)
|
2009-11-05 08:45:08 +00:00
|
|
|
{
|
|
|
|
struct tty *tty = data;
|
2017-02-10 12:59:18 +00:00
|
|
|
size_t size = EVBUFFER_LENGTH(tty->in);
|
|
|
|
int nread;
|
|
|
|
|
|
|
|
nread = evbuffer_read(tty->in, tty->fd, -1);
|
|
|
|
if (nread == -1)
|
|
|
|
return;
|
|
|
|
log_debug("%s: read %d bytes (already %zu)", tty->path, nread, size);
|
2009-11-05 08:45:08 +00:00
|
|
|
|
|
|
|
while (tty_keys_next(tty))
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2017-02-10 12:59:18 +00:00
|
|
|
tty_write_callback(__unused int fd, __unused short events, void *data)
|
2009-11-04 21:47:42 +00:00
|
|
|
{
|
2017-02-10 12:59:18 +00:00
|
|
|
struct tty *tty = data;
|
|
|
|
size_t size = EVBUFFER_LENGTH(tty->out);
|
|
|
|
int nwrite;
|
|
|
|
|
|
|
|
nwrite = evbuffer_write(tty->out, tty->fd);
|
|
|
|
if (nwrite == -1)
|
|
|
|
return;
|
|
|
|
log_debug("%s: wrote %d bytes (of %zu)", tty->path, nwrite, size);
|
|
|
|
|
2017-02-10 15:39:43 +00:00
|
|
|
if (EVBUFFER_LENGTH(tty->out) != 0)
|
|
|
|
event_add(&tty->event_out, NULL);
|
2009-11-04 21:47:42 +00:00
|
|
|
}
|
|
|
|
|
2017-02-10 12:59:18 +00:00
|
|
|
int
|
|
|
|
tty_open(struct tty *tty, char **cause)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2017-02-10 12:59:18 +00:00
|
|
|
tty->term = tty_term_find(tty->term_name, tty->fd, cause);
|
|
|
|
if (tty->term == NULL) {
|
|
|
|
tty_close(tty);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
tty->flags |= TTY_OPENED;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2017-02-10 12:59:18 +00:00
|
|
|
tty->flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
|
2009-09-23 07:25:31 +00:00
|
|
|
|
2017-02-10 12:59:18 +00:00
|
|
|
event_set(&tty->event_in, tty->fd, EV_PERSIST|EV_READ,
|
|
|
|
tty_read_callback, tty);
|
|
|
|
tty->in = evbuffer_new();
|
2009-09-23 12:03:30 +00:00
|
|
|
|
2017-02-10 12:59:18 +00:00
|
|
|
event_set(&tty->event_out, tty->fd, EV_WRITE, tty_write_callback, tty);
|
|
|
|
tty->out = evbuffer_new();
|
2009-11-04 21:47:42 +00:00
|
|
|
|
2017-02-10 12:59:18 +00:00
|
|
|
tty_start_tty(tty);
|
|
|
|
|
|
|
|
tty_keys_build(tty);
|
|
|
|
|
|
|
|
return (0);
|
2012-03-17 21:27:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_start_tty(struct tty *tty)
|
|
|
|
{
|
2017-02-10 12:59:18 +00:00
|
|
|
struct termios tio;
|
|
|
|
|
|
|
|
if (tty->fd != -1 && tcgetattr(tty->fd, &tty->tio) == 0) {
|
|
|
|
setblocking(tty->fd, 0);
|
|
|
|
event_add(&tty->event_in, NULL);
|
|
|
|
|
|
|
|
memcpy(&tio, &tty->tio, sizeof tio);
|
|
|
|
tio.c_iflag &= ~(IXON|IXOFF|ICRNL|INLCR|IGNCR|IMAXBEL|ISTRIP);
|
|
|
|
tio.c_iflag |= IGNBRK;
|
|
|
|
tio.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET);
|
|
|
|
tio.c_lflag &= ~(IEXTEN|ICANON|ECHO|ECHOE|ECHONL|ECHOCTL|
|
|
|
|
ECHOPRT|ECHOKE|ISIG);
|
|
|
|
tio.c_cc[VMIN] = 1;
|
|
|
|
tio.c_cc[VTIME] = 0;
|
|
|
|
if (tcsetattr(tty->fd, TCSANOW, &tio) == 0)
|
|
|
|
tcflush(tty->fd, TCIOFLUSH);
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
tty_putcode(tty, TTYC_SMCUP);
|
2009-07-10 07:11:59 +00:00
|
|
|
|
2017-03-08 14:34:35 +00:00
|
|
|
tty_putcode(tty, TTYC_SMKX);
|
2010-09-11 16:19:22 +00:00
|
|
|
if (tty_use_acs(tty))
|
|
|
|
tty_putcode(tty, TTYC_ENACS);
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_putcode(tty, TTYC_CLEAR);
|
|
|
|
|
|
|
|
tty_putcode(tty, TTYC_CNORM);
|
|
|
|
if (tty_term_has(tty->term, TTYC_KMOUS))
|
2015-04-25 15:57:48 +00:00
|
|
|
tty_puts(tty, "\033[?1000l\033[?1002l\033[?1006l\033[?1005l");
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2015-10-23 15:52:54 +00:00
|
|
|
if (tty_term_flag(tty->term, TTYC_XT)) {
|
2015-10-27 15:58:42 +00:00
|
|
|
if (options_get_number(global_options, "focus-events")) {
|
2013-06-23 13:10:46 +00:00
|
|
|
tty->flags |= TTY_FOCUS;
|
|
|
|
tty_puts(tty, "\033[?1004h");
|
|
|
|
}
|
2016-11-15 14:02:32 +00:00
|
|
|
tty_puts(tty, "\033[c");
|
2013-06-23 13:10:46 +00:00
|
|
|
}
|
2012-03-15 10:36:00 +00:00
|
|
|
|
2009-08-11 19:32:25 +00:00
|
|
|
tty->flags |= TTY_STARTED;
|
2017-02-08 23:53:03 +00:00
|
|
|
tty_invalidate(tty);
|
2011-05-20 19:03:58 +00:00
|
|
|
|
|
|
|
tty_force_cursor_colour(tty, "");
|
2015-04-19 21:34:21 +00:00
|
|
|
|
|
|
|
tty->mouse_drag_flag = 0;
|
|
|
|
tty->mouse_drag_update = NULL;
|
|
|
|
tty->mouse_drag_release = NULL;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_stop_tty(struct tty *tty)
|
|
|
|
{
|
|
|
|
struct winsize ws;
|
|
|
|
|
2009-08-11 19:32:25 +00:00
|
|
|
if (!(tty->flags & TTY_STARTED))
|
|
|
|
return;
|
|
|
|
tty->flags &= ~TTY_STARTED;
|
|
|
|
|
2017-02-10 12:59:18 +00:00
|
|
|
event_del(&tty->event_in);
|
|
|
|
event_del(&tty->event_out);
|
2009-11-04 21:47:42 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
/*
|
|
|
|
* Be flexible about error handling and try not kill the server just
|
|
|
|
* because the fd is invalid. Things like ssh -t can easily leave us
|
|
|
|
* with a dead tty.
|
|
|
|
*/
|
|
|
|
if (ioctl(tty->fd, TIOCGWINSZ, &ws) == -1)
|
|
|
|
return;
|
|
|
|
if (tcsetattr(tty->fd, TCSANOW, &tty->tio) == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tty_raw(tty, tty_term_string2(tty->term, TTYC_CSR, 0, ws.ws_row - 1));
|
2010-09-11 16:19:22 +00:00
|
|
|
if (tty_use_acs(tty))
|
|
|
|
tty_raw(tty, tty_term_string(tty->term, TTYC_RMACS));
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_raw(tty, tty_term_string(tty->term, TTYC_SGR0));
|
|
|
|
tty_raw(tty, tty_term_string(tty->term, TTYC_RMKX));
|
|
|
|
tty_raw(tty, tty_term_string(tty->term, TTYC_CLEAR));
|
2013-06-02 07:52:15 +00:00
|
|
|
if (tty_term_has(tty->term, TTYC_SS) && tty->cstyle != 0) {
|
|
|
|
if (tty_term_has(tty->term, TTYC_SE))
|
|
|
|
tty_raw(tty, tty_term_string(tty->term, TTYC_SE));
|
2011-05-26 07:08:48 +00:00
|
|
|
else
|
2013-06-02 07:52:15 +00:00
|
|
|
tty_raw(tty, tty_term_string1(tty->term, TTYC_SS, 0));
|
2011-05-20 19:17:39 +00:00
|
|
|
}
|
2015-02-05 11:46:57 +00:00
|
|
|
if (tty->mode & MODE_BRACKETPASTE)
|
|
|
|
tty_raw(tty, "\033[?2004l");
|
2011-05-20 19:03:58 +00:00
|
|
|
tty_raw(tty, tty_term_string(tty->term, TTYC_CR));
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
tty_raw(tty, tty_term_string(tty->term, TTYC_CNORM));
|
|
|
|
if (tty_term_has(tty->term, TTYC_KMOUS))
|
2015-04-25 15:57:48 +00:00
|
|
|
tty_raw(tty, "\033[?1000l\033[?1002l\033[?1006l\033[?1005l");
|
2013-03-22 10:34:46 +00:00
|
|
|
|
2015-10-23 15:52:54 +00:00
|
|
|
if (tty_term_flag(tty->term, TTYC_XT)) {
|
2013-06-23 13:10:46 +00:00
|
|
|
if (tty->flags & TTY_FOCUS) {
|
|
|
|
tty->flags &= ~TTY_FOCUS;
|
2015-01-30 12:33:03 +00:00
|
|
|
tty_raw(tty, "\033[?1004l");
|
2013-06-23 13:10:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-10 07:11:59 +00:00
|
|
|
|
2016-11-15 14:02:32 +00:00
|
|
|
if (tty_use_margin(tty))
|
|
|
|
tty_raw(tty, "\033[?69l"); /* DECLRMM */
|
2009-07-10 07:11:59 +00:00
|
|
|
tty_raw(tty, tty_term_string(tty->term, TTYC_RMCUP));
|
2013-03-22 10:34:46 +00:00
|
|
|
|
|
|
|
setblocking(tty->fd, 1);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-11 19:32:25 +00:00
|
|
|
tty_close(struct tty *tty)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2012-03-17 18:24:07 +00:00
|
|
|
if (event_initialized(&tty->key_timer))
|
|
|
|
evtimer_del(&tty->key_timer);
|
2009-08-11 19:32:25 +00:00
|
|
|
tty_stop_tty(tty);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-08-11 20:29:04 +00:00
|
|
|
if (tty->flags & TTY_OPENED) {
|
2017-02-10 12:59:18 +00:00
|
|
|
evbuffer_free(tty->in);
|
|
|
|
event_del(&tty->event_in);
|
|
|
|
evbuffer_free(tty->out);
|
|
|
|
event_del(&tty->event_out);
|
2009-11-04 21:47:42 +00:00
|
|
|
|
2009-08-11 20:29:04 +00:00
|
|
|
tty_term_free(tty->term);
|
|
|
|
tty_keys_free(tty);
|
|
|
|
|
|
|
|
tty->flags &= ~TTY_OPENED;
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-08-11 20:29:04 +00:00
|
|
|
if (tty->fd != -1) {
|
|
|
|
close(tty->fd);
|
|
|
|
tty->fd = -1;
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-11 19:32:25 +00:00
|
|
|
tty_free(struct tty *tty)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-08-11 19:32:25 +00:00
|
|
|
tty_close(tty);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2012-07-10 11:53:01 +00:00
|
|
|
free(tty->ccolour);
|
2015-10-23 16:30:15 +00:00
|
|
|
free(tty->path);
|
2017-01-11 16:09:57 +00:00
|
|
|
free(tty->term_name);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 14:02:32 +00:00
|
|
|
void
|
|
|
|
tty_set_type(struct tty *tty, int type)
|
|
|
|
{
|
|
|
|
tty->term_type = type;
|
|
|
|
|
|
|
|
if (tty_use_margin(tty))
|
|
|
|
tty_puts(tty, "\033[?69h"); /* DECLRMM */
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
|
|
|
tty_raw(struct tty *tty, const char *s)
|
|
|
|
{
|
2013-03-22 10:34:46 +00:00
|
|
|
ssize_t n, slen;
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
slen = strlen(s);
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
n = write(tty->fd, s, slen);
|
|
|
|
if (n >= 0) {
|
|
|
|
s += n;
|
|
|
|
slen -= n;
|
|
|
|
if (slen == 0)
|
|
|
|
break;
|
|
|
|
} else if (n == -1 && errno != EAGAIN)
|
|
|
|
break;
|
|
|
|
usleep(100);
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_putcode(struct tty *tty, enum tty_code_code code)
|
|
|
|
{
|
|
|
|
tty_puts(tty, tty_term_string(tty->term, code));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_putcode1(struct tty *tty, enum tty_code_code code, int a)
|
|
|
|
{
|
|
|
|
if (a < 0)
|
|
|
|
return;
|
|
|
|
tty_puts(tty, tty_term_string1(tty->term, code, a));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_putcode2(struct tty *tty, enum tty_code_code code, int a, int b)
|
|
|
|
{
|
|
|
|
if (a < 0 || b < 0)
|
|
|
|
return;
|
|
|
|
tty_puts(tty, tty_term_string2(tty->term, code, a, b));
|
|
|
|
}
|
|
|
|
|
2011-05-20 19:03:58 +00:00
|
|
|
void
|
|
|
|
tty_putcode_ptr1(struct tty *tty, enum tty_code_code code, const void *a)
|
|
|
|
{
|
|
|
|
if (a != NULL)
|
|
|
|
tty_puts(tty, tty_term_ptr1(tty->term, code, a));
|
|
|
|
}
|
|
|
|
|
2011-05-18 20:24:29 +00:00
|
|
|
void
|
2014-04-17 12:57:28 +00:00
|
|
|
tty_putcode_ptr2(struct tty *tty, enum tty_code_code code, const void *a,
|
|
|
|
const void *b)
|
2011-05-18 20:24:29 +00:00
|
|
|
{
|
|
|
|
if (a != NULL && b != NULL)
|
|
|
|
tty_puts(tty, tty_term_ptr2(tty->term, code, a, b));
|
|
|
|
}
|
|
|
|
|
2017-02-08 23:53:03 +00:00
|
|
|
static void
|
|
|
|
tty_add(struct tty *tty, const char *buf, size_t len)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2017-02-10 12:59:18 +00:00
|
|
|
evbuffer_add(tty->out, buf, len);
|
|
|
|
log_debug("%s: %.*s", tty->path, (int)len, (const char *)buf);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2015-10-31 13:12:03 +00:00
|
|
|
if (tty_log_fd != -1)
|
2017-02-08 23:53:03 +00:00
|
|
|
write(tty_log_fd, buf, len);
|
2017-02-10 12:59:18 +00:00
|
|
|
if (tty->flags & TTY_STARTED)
|
|
|
|
event_add(&tty->event_out, NULL);
|
2017-02-08 23:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_puts(struct tty *tty, const char *s)
|
|
|
|
{
|
|
|
|
if (*s != '\0')
|
|
|
|
tty_add(tty, s, strlen(s));
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_putc(struct tty *tty, u_char ch)
|
|
|
|
{
|
2010-09-11 16:19:22 +00:00
|
|
|
const char *acs;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2010-09-11 16:19:22 +00:00
|
|
|
if (tty->cell.attr & GRID_ATTR_CHARSET) {
|
|
|
|
acs = tty_acs_get(tty, ch);
|
2017-02-08 23:53:03 +00:00
|
|
|
if (acs != NULL)
|
|
|
|
tty_add(tty, acs, strlen(acs));
|
|
|
|
else
|
|
|
|
tty_add(tty, &ch, 1);
|
|
|
|
} else
|
|
|
|
tty_add(tty, &ch, 1);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
if (ch >= 0x20 && ch != 0x7f) {
|
2016-10-14 21:48:00 +00:00
|
|
|
if (tty->cx >= tty->sx) {
|
2009-10-12 17:19:47 +00:00
|
|
|
tty->cx = 1;
|
|
|
|
if (tty->cy != tty->rlower)
|
|
|
|
tty->cy++;
|
2016-10-14 21:48:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* On !xenl terminals, force the cursor position to
|
|
|
|
* where we think it should be after a line wrap - this
|
|
|
|
* means it works on sensible terminals as well.
|
|
|
|
*/
|
|
|
|
if (tty->term->flags & TERM_EARLYWRAP)
|
|
|
|
tty_putcode2(tty, TTYC_CUP, tty->cy, tty->cx);
|
2009-06-01 22:58:49 +00:00
|
|
|
} else
|
|
|
|
tty->cx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-24 16:01:02 +00:00
|
|
|
void
|
2013-01-18 02:16:21 +00:00
|
|
|
tty_putn(struct tty *tty, const void *buf, size_t len, u_int width)
|
2009-06-24 16:01:02 +00:00
|
|
|
{
|
2017-02-08 23:53:03 +00:00
|
|
|
tty_add(tty, buf, len);
|
2017-03-15 15:22:14 +00:00
|
|
|
if (tty->cx + width > tty->sx)
|
|
|
|
tty->cx = tty->cy = UINT_MAX;
|
|
|
|
else
|
|
|
|
tty->cx += width;
|
2009-06-24 16:01:02 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2015-04-29 15:59:08 +00:00
|
|
|
tty_set_italics(struct tty *tty)
|
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
if (tty_term_has(tty->term, TTYC_SITM)) {
|
2015-10-27 15:58:42 +00:00
|
|
|
s = options_get_string(global_options, "default-terminal");
|
2015-04-29 15:59:08 +00:00
|
|
|
if (strcmp(s, "screen") != 0 && strncmp(s, "screen-", 7) != 0) {
|
|
|
|
tty_putcode(tty, TTYC_SITM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tty_putcode(tty, TTYC_SMSO);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
|
|
|
tty_set_title(struct tty *tty, const char *title)
|
|
|
|
{
|
2011-05-08 19:53:06 +00:00
|
|
|
if (!tty_term_has(tty->term, TTYC_TSL) ||
|
|
|
|
!tty_term_has(tty->term, TTYC_FSL))
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
|
2011-05-08 19:53:06 +00:00
|
|
|
tty_putcode(tty, TTYC_TSL);
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_puts(tty, title);
|
2011-05-08 19:53:06 +00:00
|
|
|
tty_putcode(tty, TTYC_FSL);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2011-05-20 19:03:58 +00:00
|
|
|
tty_force_cursor_colour(struct tty *tty, const char *ccolour)
|
|
|
|
{
|
|
|
|
if (*ccolour == '\0')
|
|
|
|
tty_putcode(tty, TTYC_CR);
|
|
|
|
else
|
2013-06-02 07:52:15 +00:00
|
|
|
tty_putcode_ptr1(tty, TTYC_CS, ccolour);
|
2012-07-10 11:53:01 +00:00
|
|
|
free(tty->ccolour);
|
2011-05-20 19:03:58 +00:00
|
|
|
tty->ccolour = xstrdup(ccolour);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_update_mode(struct tty *tty, int mode, struct screen *s)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
int changed;
|
|
|
|
|
2015-12-28 14:02:52 +00:00
|
|
|
if (s != NULL && strcmp(s->ccolour, tty->ccolour) != 0)
|
2011-05-20 19:03:58 +00:00
|
|
|
tty_force_cursor_colour(tty, s->ccolour);
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
if (tty->flags & TTY_NOCURSOR)
|
|
|
|
mode &= ~MODE_CURSOR;
|
|
|
|
|
|
|
|
changed = mode ^ tty->mode;
|
2015-05-19 08:48:37 +00:00
|
|
|
if (changed & MODE_BLINKING) {
|
|
|
|
if (tty_term_has(tty->term, TTYC_CVVIS))
|
|
|
|
tty_putcode(tty, TTYC_CVVIS);
|
|
|
|
else
|
|
|
|
tty_putcode(tty, TTYC_CNORM);
|
|
|
|
changed |= MODE_CURSOR;
|
|
|
|
}
|
|
|
|
if (changed & MODE_CURSOR) {
|
|
|
|
if (mode & MODE_CURSOR)
|
|
|
|
tty_putcode(tty, TTYC_CNORM);
|
|
|
|
else
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_putcode(tty, TTYC_CIVIS);
|
|
|
|
}
|
2015-05-06 07:52:06 +00:00
|
|
|
if (s != NULL && tty->cstyle != s->cstyle) {
|
2013-06-02 07:52:15 +00:00
|
|
|
if (tty_term_has(tty->term, TTYC_SS)) {
|
2011-05-20 19:17:39 +00:00
|
|
|
if (s->cstyle == 0 &&
|
2013-06-02 07:52:15 +00:00
|
|
|
tty_term_has(tty->term, TTYC_SE))
|
|
|
|
tty_putcode(tty, TTYC_SE);
|
2011-05-20 19:17:39 +00:00
|
|
|
else
|
2013-06-02 07:52:15 +00:00
|
|
|
tty_putcode1(tty, TTYC_SS, s->cstyle);
|
2011-05-20 19:17:39 +00:00
|
|
|
}
|
|
|
|
tty->cstyle = s->cstyle;
|
|
|
|
}
|
2015-11-23 20:53:09 +00:00
|
|
|
if (changed & ALL_MOUSE_MODES) {
|
2010-12-29 21:49:06 +00:00
|
|
|
if (mode & ALL_MOUSE_MODES) {
|
2013-03-22 10:34:46 +00:00
|
|
|
/*
|
|
|
|
* Enable the SGR (1006) extension unconditionally, as
|
2017-01-11 22:36:07 +00:00
|
|
|
* it is safe from misinterpretation.
|
2013-03-22 10:34:46 +00:00
|
|
|
*/
|
|
|
|
tty_puts(tty, "\033[?1006h");
|
2017-02-01 09:55:07 +00:00
|
|
|
if (mode & MODE_MOUSE_ALL)
|
|
|
|
tty_puts(tty, "\033[?1003h");
|
|
|
|
else if (mode & MODE_MOUSE_BUTTON)
|
2010-12-29 21:49:06 +00:00
|
|
|
tty_puts(tty, "\033[?1002h");
|
2011-01-15 00:46:19 +00:00
|
|
|
else if (mode & MODE_MOUSE_STANDARD)
|
|
|
|
tty_puts(tty, "\033[?1000h");
|
2010-05-31 19:51:29 +00:00
|
|
|
} else {
|
2017-02-01 09:55:07 +00:00
|
|
|
if (tty->mode & MODE_MOUSE_ALL)
|
|
|
|
tty_puts(tty, "\033[?1003l");
|
|
|
|
else if (tty->mode & MODE_MOUSE_BUTTON)
|
2010-12-29 21:49:06 +00:00
|
|
|
tty_puts(tty, "\033[?1002l");
|
2011-01-15 00:46:19 +00:00
|
|
|
else if (tty->mode & MODE_MOUSE_STANDARD)
|
|
|
|
tty_puts(tty, "\033[?1000l");
|
2013-03-22 10:34:46 +00:00
|
|
|
tty_puts(tty, "\033[?1006l");
|
2010-05-31 19:51:29 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2012-03-03 09:43:22 +00:00
|
|
|
if (changed & MODE_BRACKETPASTE) {
|
|
|
|
if (mode & MODE_BRACKETPASTE)
|
|
|
|
tty_puts(tty, "\033[?2004h");
|
|
|
|
else
|
|
|
|
tty_puts(tty, "\033[?2004l");
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
tty->mode = mode;
|
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2014-04-17 14:45:49 +00:00
|
|
|
tty_emulate_repeat(struct tty *tty, enum tty_code_code code,
|
|
|
|
enum tty_code_code code1, u_int n)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
if (tty_term_has(tty->term, code))
|
|
|
|
tty_putcode1(tty, code, n);
|
|
|
|
else {
|
|
|
|
while (n-- > 0)
|
|
|
|
tty_putcode(tty, code1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2012-05-22 09:09:16 +00:00
|
|
|
tty_repeat_space(struct tty *tty, u_int n)
|
|
|
|
{
|
|
|
|
while (n-- > 0)
|
|
|
|
tty_putc(tty, ' ');
|
|
|
|
}
|
|
|
|
|
2012-03-15 09:10:33 +00:00
|
|
|
/*
|
|
|
|
* Is the region large enough to be worth redrawing once later rather than
|
|
|
|
* probably several times now? Currently yes if it is more than 50% of the
|
|
|
|
* pane.
|
|
|
|
*/
|
2016-10-10 21:29:23 +00:00
|
|
|
static int
|
2015-11-18 14:27:44 +00:00
|
|
|
tty_large_region(__unused struct tty *tty, const struct tty_ctx *ctx)
|
2012-03-15 09:10:33 +00:00
|
|
|
{
|
|
|
|
struct window_pane *wp = ctx->wp;
|
|
|
|
|
|
|
|
return (ctx->orlower - ctx->orupper >= screen_size_y(wp->screen) / 2);
|
|
|
|
}
|
|
|
|
|
2015-04-19 21:05:27 +00:00
|
|
|
/*
|
|
|
|
* Return if BCE is needed but the terminal doesn't have it - it'll need to be
|
|
|
|
* emulated.
|
|
|
|
*/
|
2016-10-10 21:29:23 +00:00
|
|
|
static int
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_fake_bce(const struct tty *tty, const struct window_pane *wp, u_int bg)
|
2015-04-19 21:05:27 +00:00
|
|
|
{
|
|
|
|
struct grid_cell gc;
|
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
if (tty_term_flag(tty->term, TTYC_BCE))
|
|
|
|
return (0);
|
|
|
|
|
2015-04-19 21:05:27 +00:00
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
2016-05-30 09:50:20 +00:00
|
|
|
if (wp != NULL)
|
|
|
|
tty_default_colours(&gc, wp);
|
2015-04-19 21:05:27 +00:00
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
if (bg != 8 || gc.bg != 8)
|
|
|
|
return (1);
|
|
|
|
return (0);
|
2015-04-19 21:05:27 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
/*
|
|
|
|
* Redraw scroll region using data from screen (already updated). Used when
|
|
|
|
* CSR not supported, or window is a pane that doesn't take up the full
|
|
|
|
* width of the terminal.
|
|
|
|
*/
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_redraw_region(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-07-22 20:53:38 +00:00
|
|
|
struct window_pane *wp = ctx->wp;
|
|
|
|
struct screen *s = wp->screen;
|
2016-07-15 00:49:08 +00:00
|
|
|
u_int i;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-15 09:10:33 +00:00
|
|
|
* If region is large, schedule a window redraw. In most cases this is
|
|
|
|
* likely to be followed by some more scrolling.
|
2009-06-01 22:58:49 +00:00
|
|
|
*/
|
2012-03-15 09:10:33 +00:00
|
|
|
if (tty_large_region(tty, ctx)) {
|
2009-06-01 22:58:49 +00:00
|
|
|
wp->flags |= PANE_REDRAW;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
if (ctx->ocy < ctx->orupper || ctx->ocy > ctx->orlower) {
|
|
|
|
for (i = ctx->ocy; i < screen_size_y(s); i++)
|
2015-04-19 21:05:27 +00:00
|
|
|
tty_draw_pane(tty, wp, i, ctx->xoff, ctx->yoff);
|
2009-06-01 22:58:49 +00:00
|
|
|
} else {
|
2009-07-22 20:53:38 +00:00
|
|
|
for (i = ctx->orupper; i <= ctx->orlower; i++)
|
2015-04-19 21:05:27 +00:00
|
|
|
tty_draw_pane(tty, wp, i, ctx->xoff, ctx->yoff);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-19 21:05:27 +00:00
|
|
|
tty_draw_pane(struct tty *tty, const struct window_pane *wp, u_int py, u_int ox,
|
|
|
|
u_int oy)
|
|
|
|
{
|
|
|
|
tty_draw_line(tty, wp, wp->screen, py, ox, oy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_draw_line(struct tty *tty, const struct window_pane *wp,
|
|
|
|
struct screen *s, u_int py, u_int ox, u_int oy)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2017-02-21 16:25:04 +00:00
|
|
|
struct grid_cell gc, last;
|
|
|
|
u_int i, j, sx, width;
|
|
|
|
int flags = (tty->flags & TTY_NOCURSOR);
|
|
|
|
char buf[512];
|
|
|
|
size_t len;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2015-05-06 07:52:06 +00:00
|
|
|
tty->flags |= TTY_NOCURSOR;
|
|
|
|
tty_update_mode(tty, tty->mode, s);
|
2009-10-09 07:23:28 +00:00
|
|
|
|
2016-11-15 15:17:28 +00:00
|
|
|
tty_region_off(tty);
|
|
|
|
tty_margin_off(tty);
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
sx = screen_size_x(s);
|
2017-02-21 16:25:04 +00:00
|
|
|
if (sx > s->grid->linedata[s->grid->hsize + py].cellused)
|
|
|
|
sx = s->grid->linedata[s->grid->hsize + py].cellused;
|
2009-06-01 22:58:49 +00:00
|
|
|
if (sx > tty->sx)
|
|
|
|
sx = tty->sx;
|
|
|
|
|
2017-02-21 16:25:04 +00:00
|
|
|
tty_cursor(tty, ox, oy + py);
|
|
|
|
|
|
|
|
memcpy(&last, &grid_default_cell, sizeof last);
|
|
|
|
len = 0;
|
|
|
|
width = 0;
|
2009-10-12 17:19:47 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
for (i = 0; i < sx; i++) {
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_view_get_cell(s->grid, i, py, &gc);
|
2017-02-21 16:25:04 +00:00
|
|
|
if (len != 0 &&
|
2017-03-06 09:02:59 +00:00
|
|
|
(((~tty->flags & TTY_UTF8) &&
|
|
|
|
(gc.data.size != 1 ||
|
|
|
|
*gc.data.data >= 0x7f ||
|
|
|
|
gc.data.width != 1)) ||
|
|
|
|
(gc.attr & GRID_ATTR_CHARSET) ||
|
2017-02-21 16:25:04 +00:00
|
|
|
gc.flags != last.flags ||
|
|
|
|
gc.attr != last.attr ||
|
|
|
|
gc.fg != last.fg ||
|
|
|
|
gc.bg != last.bg ||
|
|
|
|
(sizeof buf) - len < gc.data.size)) {
|
|
|
|
tty_attributes(tty, &last, wp);
|
|
|
|
tty_putn(tty, buf, len, width);
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
width = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gc.flags & GRID_FLAG_SELECTED)
|
|
|
|
screen_select_cell(s, &last, &gc);
|
|
|
|
else
|
|
|
|
memcpy(&last, &gc, sizeof last);
|
2017-03-06 09:02:59 +00:00
|
|
|
if (((~tty->flags & TTY_UTF8) &&
|
|
|
|
(gc.data.size != 1 ||
|
|
|
|
*gc.data.data >= 0x7f ||
|
|
|
|
gc.data.width != 1)) ||
|
|
|
|
(gc.attr & GRID_ATTR_CHARSET)) {
|
2017-02-21 16:25:04 +00:00
|
|
|
tty_attributes(tty, &last, wp);
|
2017-03-06 09:02:59 +00:00
|
|
|
if (~tty->flags & TTY_UTF8) {
|
|
|
|
for (j = 0; j < gc.data.width; j++)
|
|
|
|
tty_putc(tty, '_');
|
|
|
|
} else {
|
|
|
|
for (j = 0; j < gc.data.size; j++)
|
|
|
|
tty_putc(tty, gc.data.data[j]);
|
|
|
|
}
|
2017-02-21 16:25:04 +00:00
|
|
|
} else {
|
|
|
|
memcpy(buf + len, gc.data.data, gc.data.size);
|
|
|
|
len += gc.data.size;
|
|
|
|
width += gc.data.width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (len != 0) {
|
|
|
|
tty_attributes(tty, &last, wp);
|
|
|
|
tty_putn(tty, buf, len, width);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2015-05-06 07:52:06 +00:00
|
|
|
if (sx < tty->sx) {
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_default_attributes(tty, wp, 8);
|
2015-05-06 07:52:06 +00:00
|
|
|
|
|
|
|
tty_cursor(tty, ox + sx, oy + py);
|
|
|
|
if (sx != screen_size_x(s) &&
|
|
|
|
ox + screen_size_x(s) >= tty->sx &&
|
|
|
|
tty_term_has(tty->term, TTYC_EL) &&
|
2016-10-13 20:27:27 +00:00
|
|
|
!tty_fake_bce(tty, wp, 8))
|
2015-05-06 07:52:06 +00:00
|
|
|
tty_putcode(tty, TTYC_EL);
|
|
|
|
else
|
|
|
|
tty_repeat_space(tty, screen_size_x(s) - sx);
|
2009-10-09 07:23:28 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2015-05-06 07:52:06 +00:00
|
|
|
tty->flags = (tty->flags & ~TTY_NOCURSOR) | flags;
|
2011-05-20 19:03:58 +00:00
|
|
|
tty_update_mode(tty, tty->mode, s);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-04-30 18:59:02 +00:00
|
|
|
static int
|
2015-05-12 22:40:38 +00:00
|
|
|
tty_client_ready(struct client *c, struct window_pane *wp)
|
|
|
|
{
|
|
|
|
if (c->session == NULL || c->tty.term == NULL)
|
|
|
|
return (0);
|
2017-02-10 12:59:18 +00:00
|
|
|
if (c->flags & (CLIENT_REDRAW|CLIENT_SUSPENDED))
|
2015-05-12 22:40:38 +00:00
|
|
|
return (0);
|
|
|
|
if (c->tty.flags & TTY_FREEZE)
|
|
|
|
return (0);
|
|
|
|
if (c->session->curw->window != wp->window)
|
|
|
|
return (0);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2009-07-22 20:56:58 +00:00
|
|
|
void
|
2015-05-12 22:40:38 +00:00
|
|
|
tty_write(void (*cmdfn)(struct tty *, const struct tty_ctx *),
|
|
|
|
struct tty_ctx *ctx)
|
2009-07-22 20:56:58 +00:00
|
|
|
{
|
|
|
|
struct window_pane *wp = ctx->wp;
|
|
|
|
struct client *c;
|
|
|
|
|
2009-11-27 09:41:03 +00:00
|
|
|
/* wp can be NULL if updating the screen but not the terminal. */
|
2009-07-22 20:56:58 +00:00
|
|
|
if (wp == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (wp->window->flags & WINDOW_REDRAW || wp->flags & PANE_REDRAW)
|
|
|
|
return;
|
2012-03-20 11:01:00 +00:00
|
|
|
if (!window_pane_visible(wp) || wp->flags & PANE_DROP)
|
2009-07-22 20:56:58 +00:00
|
|
|
return;
|
|
|
|
|
2015-04-24 23:17:11 +00:00
|
|
|
TAILQ_FOREACH(c, &clients, entry) {
|
2015-05-12 22:40:38 +00:00
|
|
|
if (!tty_client_ready(c, wp))
|
2009-07-22 20:56:58 +00:00
|
|
|
continue;
|
2012-01-29 09:37:02 +00:00
|
|
|
|
2012-08-14 08:58:25 +00:00
|
|
|
ctx->xoff = wp->xoff;
|
|
|
|
ctx->yoff = wp->yoff;
|
|
|
|
if (status_at_line(c) == 0)
|
|
|
|
ctx->yoff++;
|
2012-01-29 09:37:02 +00:00
|
|
|
|
2012-08-14 08:58:25 +00:00
|
|
|
cmdfn(&c->tty, ctx);
|
2009-07-22 20:56:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_cmd_insertcharacter(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-12-03 22:50:09 +00:00
|
|
|
struct window_pane *wp = ctx->wp;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
if (!tty_pane_full_width(tty, ctx) ||
|
|
|
|
tty_fake_bce(tty, wp, ctx->bg) ||
|
|
|
|
(!tty_term_has(tty->term, TTYC_ICH) &&
|
|
|
|
!tty_term_has(tty->term, TTYC_ICH1))) {
|
2015-04-19 21:05:27 +00:00
|
|
|
tty_draw_pane(tty, wp, ctx->ocy, ctx->xoff, ctx->yoff);
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_default_attributes(tty, wp, ctx->bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-12-03 22:50:09 +00:00
|
|
|
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
|
2009-10-12 09:29:58 +00:00
|
|
|
|
2016-10-03 19:19:18 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_ICH, TTYC_ICH1, ctx->num);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_cmd_deletecharacter(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-12-03 22:50:09 +00:00
|
|
|
struct window_pane *wp = ctx->wp;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
if (!tty_pane_full_width(tty, ctx) ||
|
|
|
|
tty_fake_bce(tty, wp, ctx->bg) ||
|
2009-08-21 12:29:59 +00:00
|
|
|
(!tty_term_has(tty->term, TTYC_DCH) &&
|
|
|
|
!tty_term_has(tty->term, TTYC_DCH1))) {
|
2015-04-19 21:05:27 +00:00
|
|
|
tty_draw_pane(tty, wp, ctx->ocy, ctx->xoff, ctx->yoff);
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_default_attributes(tty, wp, ctx->bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-12-03 22:50:09 +00:00
|
|
|
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
|
2009-10-12 09:29:58 +00:00
|
|
|
|
2016-10-03 19:19:18 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_DCH, TTYC_DCH1, ctx->num);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 23:18:55 +00:00
|
|
|
void
|
|
|
|
tty_cmd_clearcharacter(struct tty *tty, const struct tty_ctx *ctx)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
2015-04-19 21:05:27 +00:00
|
|
|
tty_attributes(tty, &grid_default_cell, ctx->wp);
|
2013-01-15 23:18:55 +00:00
|
|
|
|
|
|
|
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
|
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
if (tty_term_has(tty->term, TTYC_ECH) &&
|
|
|
|
!tty_fake_bce(tty, ctx->wp, ctx->bg))
|
2013-01-15 23:18:55 +00:00
|
|
|
tty_putcode1(tty, TTYC_ECH, ctx->num);
|
|
|
|
else {
|
|
|
|
for (i = 0; i < ctx->num; i++)
|
|
|
|
tty_putc(tty, ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_cmd_insertline(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2016-10-13 20:27:27 +00:00
|
|
|
if (!tty_pane_full_width(tty, ctx) ||
|
|
|
|
tty_fake_bce(tty, ctx->wp, ctx->bg) ||
|
2009-12-03 22:50:09 +00:00
|
|
|
!tty_term_has(tty->term, TTYC_CSR) ||
|
2009-11-26 14:46:08 +00:00
|
|
|
!tty_term_has(tty->term, TTYC_IL1)) {
|
2009-07-22 20:53:38 +00:00
|
|
|
tty_redraw_region(tty, ctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_default_attributes(tty, ctx->wp, ctx->bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-12-03 22:50:09 +00:00
|
|
|
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
|
2016-11-15 15:17:28 +00:00
|
|
|
tty_margin_off(tty);
|
2009-12-03 22:50:09 +00:00
|
|
|
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-22 16:45:31 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_IL, TTYC_IL1, ctx->num);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_cmd_deleteline(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2016-10-13 20:27:27 +00:00
|
|
|
if (!tty_pane_full_width(tty, ctx) ||
|
|
|
|
tty_fake_bce(tty, ctx->wp, ctx->bg) ||
|
2009-11-26 14:46:08 +00:00
|
|
|
!tty_term_has(tty->term, TTYC_CSR) ||
|
|
|
|
!tty_term_has(tty->term, TTYC_DL1)) {
|
2009-07-22 20:53:38 +00:00
|
|
|
tty_redraw_region(tty, ctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_default_attributes(tty, ctx->wp, ctx->bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-12-03 22:50:09 +00:00
|
|
|
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
|
2016-11-15 15:17:28 +00:00
|
|
|
tty_margin_off(tty);
|
2009-12-03 22:50:09 +00:00
|
|
|
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-22 16:45:31 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_DL, TTYC_DL1, ctx->num);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_cmd_clearline(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-12-03 22:50:09 +00:00
|
|
|
struct window_pane *wp = ctx->wp;
|
2009-07-22 16:45:31 +00:00
|
|
|
struct screen *s = wp->screen;
|
2017-02-06 22:05:11 +00:00
|
|
|
u_int sx = screen_size_x(s);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_default_attributes(tty, wp, ctx->bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-12-03 22:50:09 +00:00
|
|
|
tty_cursor_pane(tty, ctx, 0, ctx->ocy);
|
2009-10-12 09:29:58 +00:00
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
if (tty_pane_full_width(tty, ctx) &&
|
|
|
|
!tty_fake_bce(tty, wp, ctx->bg) &&
|
2015-04-19 21:05:27 +00:00
|
|
|
tty_term_has(tty->term, TTYC_EL))
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_putcode(tty, TTYC_EL);
|
2012-05-22 09:09:16 +00:00
|
|
|
else
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_repeat_space(tty, sx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_cmd_clearendofline(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-12-03 22:50:09 +00:00
|
|
|
struct window_pane *wp = ctx->wp;
|
2009-07-22 16:45:31 +00:00
|
|
|
struct screen *s = wp->screen;
|
2017-02-06 22:05:11 +00:00
|
|
|
u_int sx = screen_size_x(s);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_default_attributes(tty, wp, ctx->bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-10-12 09:29:58 +00:00
|
|
|
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
|
|
|
|
|
2015-04-19 21:05:27 +00:00
|
|
|
if (tty_pane_full_width(tty, ctx) &&
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_term_has(tty->term, TTYC_EL) &&
|
|
|
|
!tty_fake_bce(tty, wp, ctx->bg))
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_putcode(tty, TTYC_EL);
|
2012-05-22 09:09:16 +00:00
|
|
|
else
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_repeat_space(tty, sx - ctx->ocx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2016-10-13 20:27:27 +00:00
|
|
|
struct window_pane *wp = ctx->wp;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_default_attributes(tty, wp, ctx->bg);
|
|
|
|
|
|
|
|
if (ctx->xoff == 0 &&
|
|
|
|
tty_term_has(tty->term, TTYC_EL1) &&
|
2017-02-08 16:18:20 +00:00
|
|
|
!tty_fake_bce(tty, ctx->wp, ctx->bg)) {
|
|
|
|
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_putcode(tty, TTYC_EL1);
|
2017-02-08 16:18:20 +00:00
|
|
|
} else {
|
|
|
|
tty_cursor_pane(tty, ctx, 0, ctx->ocy);
|
2012-05-22 09:09:16 +00:00
|
|
|
tty_repeat_space(tty, ctx->ocx + 1);
|
2017-02-08 16:18:20 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_cmd_reverseindex(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-10-21 13:42:44 +00:00
|
|
|
if (ctx->ocy != ctx->orupper)
|
|
|
|
return;
|
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
if (!tty_pane_full_width(tty, ctx) ||
|
|
|
|
tty_fake_bce(tty, ctx->wp, ctx->bg) ||
|
2009-11-12 08:05:23 +00:00
|
|
|
!tty_term_has(tty->term, TTYC_CSR) ||
|
|
|
|
!tty_term_has(tty->term, TTYC_RI)) {
|
2009-07-22 20:53:38 +00:00
|
|
|
tty_redraw_region(tty, ctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-19 21:05:27 +00:00
|
|
|
tty_attributes(tty, &grid_default_cell, ctx->wp);
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-10-21 13:42:44 +00:00
|
|
|
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
|
2016-11-15 15:17:28 +00:00
|
|
|
tty_margin_off(tty);
|
2009-10-21 13:42:44 +00:00
|
|
|
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->orupper);
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-10-21 13:42:44 +00:00
|
|
|
tty_putcode(tty, TTYC_RI);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_cmd_linefeed(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-12-03 22:50:09 +00:00
|
|
|
struct window_pane *wp = ctx->wp;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-10-21 13:42:44 +00:00
|
|
|
if (ctx->ocy != ctx->orlower)
|
|
|
|
return;
|
|
|
|
|
2016-11-15 14:02:32 +00:00
|
|
|
if ((!tty_pane_full_width(tty, ctx) && !tty_use_margin(tty)) ||
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_fake_bce(tty, wp, ctx->bg) ||
|
2009-06-01 22:58:49 +00:00
|
|
|
!tty_term_has(tty->term, TTYC_CSR)) {
|
2017-02-08 15:24:48 +00:00
|
|
|
tty_redraw_region(tty, ctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-19 21:05:27 +00:00
|
|
|
tty_attributes(tty, &grid_default_cell, wp);
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-10-21 13:42:44 +00:00
|
|
|
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
|
2016-11-15 14:02:32 +00:00
|
|
|
tty_margin_pane(tty, ctx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we want to wrap a pane, the cursor needs to be exactly on the
|
|
|
|
* right of the region. But if the pane isn't on the right, it may be
|
|
|
|
* off the edge - if so, move the cursor back to the right.
|
|
|
|
*/
|
|
|
|
if (ctx->xoff + ctx->ocx > tty->rright)
|
2016-11-28 17:50:00 +00:00
|
|
|
tty_cursor(tty, tty->rright, ctx->yoff + ctx->ocy);
|
2016-11-15 14:02:32 +00:00
|
|
|
else
|
|
|
|
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-10-21 13:42:44 +00:00
|
|
|
tty_putc(tty, '\n');
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 17:31:09 +00:00
|
|
|
void
|
|
|
|
tty_cmd_scrollup(struct tty *tty, const struct tty_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct window_pane *wp = ctx->wp;
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
if ((!tty_pane_full_width(tty, ctx) && !tty_use_margin(tty)) ||
|
|
|
|
tty_fake_bce(tty, wp, ctx->bg) ||
|
|
|
|
!tty_term_has(tty->term, TTYC_CSR)) {
|
|
|
|
tty_redraw_region(tty, ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tty_attributes(tty, &grid_default_cell, wp);
|
|
|
|
|
|
|
|
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
|
|
|
|
tty_margin_pane(tty, ctx);
|
|
|
|
|
|
|
|
if (ctx->num == 1 || !tty_term_has(tty->term, TTYC_INDN)) {
|
2017-02-08 22:42:07 +00:00
|
|
|
tty_cursor(tty, tty->rright, tty->rlower);
|
2017-02-08 17:31:09 +00:00
|
|
|
for (i = 0; i < ctx->num; i++)
|
|
|
|
tty_putc(tty, '\n');
|
|
|
|
} else
|
|
|
|
tty_putcode1(tty, TTYC_INDN, ctx->num);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_cmd_clearendofscreen(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-12-03 22:50:09 +00:00
|
|
|
struct window_pane *wp = ctx->wp;
|
2009-07-22 16:45:31 +00:00
|
|
|
struct screen *s = wp->screen;
|
2016-07-15 00:49:08 +00:00
|
|
|
u_int i, j;
|
2017-02-06 22:05:11 +00:00
|
|
|
u_int sx = screen_size_x(s), sy = screen_size_y(s);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_default_attributes(tty, wp, ctx->bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_region_pane(tty, ctx, 0, sy - 1);
|
2016-11-15 15:17:28 +00:00
|
|
|
tty_margin_off(tty);
|
2009-10-12 09:09:35 +00:00
|
|
|
|
2015-04-19 21:05:27 +00:00
|
|
|
if (tty_pane_full_width(tty, ctx) &&
|
2017-02-15 11:22:13 +00:00
|
|
|
ctx->yoff + wp->sy >= tty->sy - 1 &&
|
2017-02-06 22:05:11 +00:00
|
|
|
status_at_line(tty->client) <= 0 &&
|
|
|
|
tty_term_has(tty->term, TTYC_ED)) {
|
|
|
|
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
|
|
|
|
tty_putcode(tty, TTYC_ED);
|
|
|
|
} else if (tty_pane_full_width(tty, ctx) &&
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_term_has(tty->term, TTYC_EL) &&
|
|
|
|
!tty_fake_bce(tty, wp, ctx->bg)) {
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_putcode(tty, TTYC_EL);
|
2017-02-06 22:05:11 +00:00
|
|
|
if (ctx->ocy != sy - 1) {
|
2009-10-12 09:29:58 +00:00
|
|
|
tty_cursor_pane(tty, ctx, 0, ctx->ocy + 1);
|
2017-02-06 22:05:11 +00:00
|
|
|
for (i = ctx->ocy + 1; i < sy; i++) {
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_putcode(tty, TTYC_EL);
|
2017-02-06 22:05:11 +00:00
|
|
|
if (i == sy - 1)
|
2009-06-01 22:58:49 +00:00
|
|
|
continue;
|
|
|
|
tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1);
|
|
|
|
tty->cy++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
|
|
|
|
tty_repeat_space(tty, sx - ctx->ocx);
|
|
|
|
for (j = ctx->ocy + 1; j < sy; j++) {
|
2009-10-12 09:29:58 +00:00
|
|
|
tty_cursor_pane(tty, ctx, 0, j);
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_repeat_space(tty, sx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_cmd_clearstartofscreen(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-12-03 22:50:09 +00:00
|
|
|
struct window_pane *wp = ctx->wp;
|
2009-07-22 16:45:31 +00:00
|
|
|
struct screen *s = wp->screen;
|
2016-07-15 00:49:08 +00:00
|
|
|
u_int i, j;
|
2017-02-06 22:05:11 +00:00
|
|
|
u_int sx = screen_size_x(s), sy = screen_size_y(s);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2017-02-06 19:26:49 +00:00
|
|
|
tty_default_attributes(tty, wp, ctx->bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_region_pane(tty, ctx, 0, sy - 1);
|
2016-11-15 15:17:28 +00:00
|
|
|
tty_margin_off(tty);
|
2009-10-12 09:09:35 +00:00
|
|
|
|
2017-02-07 14:33:37 +00:00
|
|
|
if (tty_pane_full_width(tty, ctx) &&
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_term_has(tty->term, TTYC_EL) &&
|
|
|
|
!tty_fake_bce(tty, wp, ctx->bg)) {
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_cursor_pane(tty, ctx, 0, 0);
|
2009-07-22 20:53:38 +00:00
|
|
|
for (i = 0; i < ctx->ocy; i++) {
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_putcode(tty, TTYC_EL);
|
|
|
|
tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1);
|
|
|
|
tty->cy++;
|
|
|
|
}
|
|
|
|
} else {
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_cursor_pane(tty, ctx, 0, 0);
|
2009-07-22 20:53:38 +00:00
|
|
|
for (j = 0; j < ctx->ocy; j++) {
|
2009-10-12 09:29:58 +00:00
|
|
|
tty_cursor_pane(tty, ctx, 0, j);
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_repeat_space(tty, sx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_cursor_pane(tty, ctx, 0, ctx->ocy);
|
2012-05-22 09:09:16 +00:00
|
|
|
tty_repeat_space(tty, ctx->ocx + 1);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_cmd_clearscreen(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-12-03 22:50:09 +00:00
|
|
|
struct window_pane *wp = ctx->wp;
|
2009-07-22 16:45:31 +00:00
|
|
|
struct screen *s = wp->screen;
|
2016-07-15 00:49:08 +00:00
|
|
|
u_int i, j;
|
2017-02-06 22:05:11 +00:00
|
|
|
u_int sx = screen_size_x(s), sy = screen_size_y(s);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_default_attributes(tty, wp, ctx->bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_region_pane(tty, ctx, 0, sy - 1);
|
2016-11-15 15:17:28 +00:00
|
|
|
tty_margin_off(tty);
|
2009-10-12 09:09:35 +00:00
|
|
|
|
2015-04-19 21:05:27 +00:00
|
|
|
if (tty_pane_full_width(tty, ctx) &&
|
2017-02-06 22:05:11 +00:00
|
|
|
status_at_line(tty->client) <= 0 &&
|
|
|
|
tty_term_has(tty->term, TTYC_ED)) {
|
|
|
|
tty_cursor_pane(tty, ctx, 0, 0);
|
|
|
|
tty_putcode(tty, TTYC_ED);
|
2017-02-07 14:33:37 +00:00
|
|
|
} else if (tty_pane_full_width(tty, ctx) &&
|
2016-10-13 20:27:27 +00:00
|
|
|
tty_term_has(tty->term, TTYC_EL) &&
|
|
|
|
!tty_fake_bce(tty, wp, ctx->bg)) {
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_cursor_pane(tty, ctx, 0, 0);
|
|
|
|
for (i = 0; i < sy; i++) {
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_putcode(tty, TTYC_EL);
|
2017-02-06 22:05:11 +00:00
|
|
|
if (i != sy - 1) {
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1);
|
|
|
|
tty->cy++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_cursor_pane(tty, ctx, 0, 0);
|
|
|
|
for (j = 0; j < sy; j++) {
|
2009-10-12 09:29:58 +00:00
|
|
|
tty_cursor_pane(tty, ctx, 0, j);
|
2017-02-06 22:05:11 +00:00
|
|
|
tty_repeat_space(tty, sx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-03 23:30:40 +00:00
|
|
|
void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_cmd_alignmenttest(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-03 23:30:40 +00:00
|
|
|
{
|
2009-07-22 16:45:31 +00:00
|
|
|
struct window_pane *wp = ctx->wp;
|
|
|
|
struct screen *s = wp->screen;
|
|
|
|
u_int i, j;
|
2009-06-03 23:30:40 +00:00
|
|
|
|
2015-04-19 21:05:27 +00:00
|
|
|
tty_attributes(tty, &grid_default_cell, wp);
|
2009-06-03 23:30:40 +00:00
|
|
|
|
2009-10-12 09:09:35 +00:00
|
|
|
tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1);
|
2016-11-15 15:17:28 +00:00
|
|
|
tty_margin_off(tty);
|
2009-06-03 23:30:40 +00:00
|
|
|
|
|
|
|
for (j = 0; j < screen_size_y(s); j++) {
|
2009-10-12 09:29:58 +00:00
|
|
|
tty_cursor_pane(tty, ctx, 0, j);
|
2009-06-03 23:30:40 +00:00
|
|
|
for (i = 0; i < screen_size_x(s); i++)
|
|
|
|
tty_putc(tty, 'E');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
2009-08-12 09:41:59 +00:00
|
|
|
tty_cmd_cell(struct tty *tty, const struct tty_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2017-01-11 23:10:04 +00:00
|
|
|
if (ctx->xoff + ctx->ocx > tty->sx - 1 && ctx->ocy == ctx->orlower) {
|
|
|
|
if (tty_pane_full_width(tty, ctx))
|
|
|
|
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
|
|
|
|
else
|
|
|
|
tty_margin_off(tty);
|
|
|
|
}
|
2009-10-12 17:19:47 +00:00
|
|
|
|
2017-03-15 09:21:21 +00:00
|
|
|
tty_cursor_pane_unless_wrap(tty, ctx, ctx->ocx, ctx->ocy);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2017-02-08 15:49:29 +00:00
|
|
|
tty_cell(tty, ctx->cell, ctx->wp);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 16:45:18 +00:00
|
|
|
void
|
|
|
|
tty_cmd_cells(struct tty *tty, const struct tty_ctx *ctx)
|
|
|
|
{
|
2017-03-15 09:21:21 +00:00
|
|
|
tty_cursor_pane_unless_wrap(tty, ctx, ctx->ocx, ctx->ocy);
|
2017-02-08 16:45:18 +00:00
|
|
|
|
|
|
|
tty_attributes(tty, ctx->cell, ctx->wp);
|
|
|
|
tty_putn(tty, ctx->ptr, ctx->num, ctx->num);
|
|
|
|
}
|
|
|
|
|
2011-05-18 20:24:29 +00:00
|
|
|
void
|
|
|
|
tty_cmd_setselection(struct tty *tty, const struct tty_ctx *ctx)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
size_t off;
|
|
|
|
|
|
|
|
if (!tty_term_has(tty->term, TTYC_MS))
|
|
|
|
return;
|
|
|
|
|
|
|
|
off = 4 * ((ctx->num + 2) / 3) + 1; /* storage for base64 */
|
|
|
|
buf = xmalloc(off);
|
|
|
|
|
|
|
|
b64_ntop(ctx->ptr, ctx->num, buf, off);
|
|
|
|
tty_putcode_ptr2(tty, TTYC_MS, "", buf);
|
|
|
|
|
2012-07-10 11:53:01 +00:00
|
|
|
free(buf);
|
2011-05-18 20:24:29 +00:00
|
|
|
}
|
|
|
|
|
2011-03-07 23:46:27 +00:00
|
|
|
void
|
|
|
|
tty_cmd_rawstring(struct tty *tty, const struct tty_ctx *ctx)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
u_char *str = ctx->ptr;
|
|
|
|
|
|
|
|
for (i = 0; i < ctx->num; i++)
|
|
|
|
tty_putc(tty, str[i]);
|
2017-02-08 23:53:03 +00:00
|
|
|
tty_invalidate(tty);
|
2011-03-07 23:46:27 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2015-04-19 21:05:27 +00:00
|
|
|
tty_cell(struct tty *tty, const struct grid_cell *gc,
|
|
|
|
const struct window_pane *wp)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2015-11-13 08:09:28 +00:00
|
|
|
u_int i;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
/* Skip last character if terminal is stupid. */
|
2016-10-14 21:48:00 +00:00
|
|
|
if ((tty->term->flags & TERM_EARLYWRAP) &&
|
|
|
|
tty->cy == tty->sy - 1 &&
|
|
|
|
tty->cx == tty->sx - 1)
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* If this is a padding character, do nothing. */
|
|
|
|
if (gc->flags & GRID_FLAG_PADDING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Set the attributes. */
|
2015-04-19 21:05:27 +00:00
|
|
|
tty_attributes(tty, gc, wp);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2013-01-18 02:16:21 +00:00
|
|
|
/* Get the cell and if ASCII write with putc to do ACS translation. */
|
2015-11-13 08:09:28 +00:00
|
|
|
if (gc->data.size == 1) {
|
|
|
|
if (*gc->data.data < 0x20 || *gc->data.data == 0x7f)
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
2015-11-13 08:09:28 +00:00
|
|
|
tty_putc(tty, *gc->data.data);
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-18 02:16:21 +00:00
|
|
|
/* If not UTF-8, write _. */
|
2009-06-01 22:58:49 +00:00
|
|
|
if (!(tty->flags & TTY_UTF8)) {
|
2015-11-13 08:09:28 +00:00
|
|
|
for (i = 0; i < gc->data.width; i++)
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_putc(tty, '_');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-18 02:16:21 +00:00
|
|
|
/* Write the data. */
|
2015-11-13 08:09:28 +00:00
|
|
|
tty_putn(tty, gc->data.data, gc->data.size, gc->data.width);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_reset(struct tty *tty)
|
|
|
|
{
|
|
|
|
struct grid_cell *gc = &tty->cell;
|
|
|
|
|
2017-02-06 19:45:23 +00:00
|
|
|
if (!grid_cells_equal(gc, &grid_default_cell)) {
|
|
|
|
if ((gc->attr & GRID_ATTR_CHARSET) && tty_use_acs(tty))
|
|
|
|
tty_putcode(tty, TTYC_RMACS);
|
|
|
|
tty_putcode(tty, TTYC_SGR0);
|
|
|
|
memcpy(gc, &grid_default_cell, sizeof *gc);
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2017-02-06 19:45:23 +00:00
|
|
|
memcpy(&tty->last_cell, &grid_default_cell, sizeof tty->last_cell);
|
|
|
|
tty->last_wp = -1;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 23:53:03 +00:00
|
|
|
static void
|
|
|
|
tty_invalidate(struct tty *tty)
|
|
|
|
{
|
|
|
|
memcpy(&tty->cell, &grid_default_cell, sizeof tty->cell);
|
|
|
|
|
|
|
|
memcpy(&tty->last_cell, &grid_default_cell, sizeof tty->last_cell);
|
|
|
|
tty->last_wp = -1;
|
|
|
|
|
|
|
|
tty->cx = tty->cy = UINT_MAX;
|
|
|
|
|
|
|
|
tty->rupper = tty->rleft = UINT_MAX;
|
|
|
|
tty->rlower = tty->rright = UINT_MAX;
|
|
|
|
|
|
|
|
if (tty->flags & TTY_STARTED) {
|
|
|
|
tty_putcode(tty, TTYC_SGR0);
|
|
|
|
|
|
|
|
tty->mode = ALL_MODES;
|
|
|
|
tty_update_mode(tty, MODE_CURSOR, NULL);
|
|
|
|
|
|
|
|
tty_cursor(tty, 0, 0);
|
|
|
|
tty_region_off(tty);
|
|
|
|
tty_margin_off(tty);
|
|
|
|
} else
|
|
|
|
tty->mode = MODE_CURSOR;
|
|
|
|
}
|
|
|
|
|
2016-11-15 15:17:28 +00:00
|
|
|
/* Turn off margin. */
|
|
|
|
void
|
|
|
|
tty_region_off(struct tty *tty)
|
|
|
|
{
|
|
|
|
tty_region(tty, 0, tty->sy - 1);
|
|
|
|
}
|
|
|
|
|
2009-10-12 09:16:59 +00:00
|
|
|
/* Set region inside pane. */
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2015-12-11 16:37:21 +00:00
|
|
|
tty_region_pane(struct tty *tty, const struct tty_ctx *ctx, u_int rupper,
|
|
|
|
u_int rlower)
|
2009-10-12 09:09:35 +00:00
|
|
|
{
|
2012-01-29 09:37:02 +00:00
|
|
|
tty_region(tty, ctx->yoff + rupper, ctx->yoff + rlower);
|
2009-10-12 09:09:35 +00:00
|
|
|
}
|
|
|
|
|
2009-10-12 09:16:59 +00:00
|
|
|
/* Set region at absolute position. */
|
2016-11-15 15:17:28 +00:00
|
|
|
static void
|
2009-10-12 09:16:59 +00:00
|
|
|
tty_region(struct tty *tty, u_int rupper, u_int rlower)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-10-12 09:09:35 +00:00
|
|
|
if (tty->rlower == rlower && tty->rupper == rupper)
|
|
|
|
return;
|
2009-06-01 22:58:49 +00:00
|
|
|
if (!tty_term_has(tty->term, TTYC_CSR))
|
|
|
|
return;
|
2009-10-12 09:09:35 +00:00
|
|
|
|
|
|
|
tty->rupper = rupper;
|
|
|
|
tty->rlower = rlower;
|
2009-10-12 13:01:18 +00:00
|
|
|
|
2009-10-21 09:36:53 +00:00
|
|
|
/*
|
|
|
|
* Some terminals (such as PuTTY) do not correctly reset the cursor to
|
|
|
|
* 0,0 if it is beyond the last column (they do not reset their wrap
|
|
|
|
* flag so further output causes a line feed). As a workaround, do an
|
|
|
|
* explicit move to 0 first.
|
|
|
|
*/
|
|
|
|
if (tty->cx >= tty->sx)
|
|
|
|
tty_cursor(tty, 0, tty->cy);
|
|
|
|
|
2009-10-12 09:09:35 +00:00
|
|
|
tty_putcode2(tty, TTYC_CSR, tty->rupper, tty->rlower);
|
2017-02-16 12:56:01 +00:00
|
|
|
tty->cx = tty->cy = UINT_MAX;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 15:17:28 +00:00
|
|
|
/* Turn off margin. */
|
|
|
|
void
|
|
|
|
tty_margin_off(struct tty *tty)
|
|
|
|
{
|
|
|
|
tty_margin(tty, 0, tty->sx - 1);
|
|
|
|
}
|
|
|
|
|
2016-11-15 14:02:32 +00:00
|
|
|
/* Set margin inside pane. */
|
|
|
|
static void
|
|
|
|
tty_margin_pane(struct tty *tty, const struct tty_ctx *ctx)
|
|
|
|
{
|
|
|
|
tty_margin(tty, ctx->xoff, ctx->xoff + ctx->wp->sx - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set margin at absolute position. */
|
2016-11-15 15:17:28 +00:00
|
|
|
static void
|
2016-11-15 14:02:32 +00:00
|
|
|
tty_margin(struct tty *tty, u_int rleft, u_int rright)
|
|
|
|
{
|
|
|
|
char s[64];
|
|
|
|
|
|
|
|
if (!tty_use_margin(tty))
|
|
|
|
return;
|
|
|
|
if (tty->rleft == rleft && tty->rright == rright)
|
|
|
|
return;
|
|
|
|
|
2017-02-07 18:27:46 +00:00
|
|
|
tty_putcode2(tty, TTYC_CSR, tty->rupper, tty->rlower);
|
2017-02-07 17:13:28 +00:00
|
|
|
|
2016-11-15 14:02:32 +00:00
|
|
|
tty->rleft = rleft;
|
|
|
|
tty->rright = rright;
|
|
|
|
|
2017-02-07 18:27:46 +00:00
|
|
|
if (rleft == 0 && rright == tty->sx - 1)
|
|
|
|
snprintf(s, sizeof s, "\033[s");
|
|
|
|
else
|
|
|
|
snprintf(s, sizeof s, "\033[%u;%us", rleft + 1, rright + 1);
|
2016-11-15 14:02:32 +00:00
|
|
|
tty_puts(tty, s);
|
2017-02-16 12:56:01 +00:00
|
|
|
tty->cx = tty->cy = UINT_MAX;
|
2016-11-15 14:02:32 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 09:21:21 +00:00
|
|
|
/*
|
|
|
|
* Move the cursor, unless it would wrap itself when the next character is
|
|
|
|
* printed.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
tty_cursor_pane_unless_wrap(struct tty *tty, const struct tty_ctx *ctx,
|
|
|
|
u_int cx, u_int cy)
|
|
|
|
{
|
|
|
|
if (!tty_pane_full_width(tty, ctx) ||
|
|
|
|
(tty->term->flags & TERM_EARLYWRAP) ||
|
|
|
|
ctx->xoff + cx != 0 ||
|
|
|
|
ctx->yoff + cy != tty->cy + 1 ||
|
2017-03-15 15:22:14 +00:00
|
|
|
tty->cx < tty->sx ||
|
|
|
|
tty->cy == tty->rlower)
|
2017-03-15 09:21:21 +00:00
|
|
|
tty_cursor_pane(tty, ctx, cx, cy);
|
|
|
|
else
|
|
|
|
log_debug("%s: will wrap at %u,%u", __func__, tty->cx, tty->cy);
|
|
|
|
}
|
|
|
|
|
2009-10-12 13:01:18 +00:00
|
|
|
/* Move cursor inside pane. */
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-10-12 09:29:58 +00:00
|
|
|
tty_cursor_pane(struct tty *tty, const struct tty_ctx *ctx, u_int cx, u_int cy)
|
|
|
|
{
|
2012-01-29 09:37:02 +00:00
|
|
|
tty_cursor(tty, ctx->xoff + cx, ctx->yoff + cy);
|
2009-10-12 09:29:58 +00:00
|
|
|
}
|
|
|
|
|
2009-10-12 13:01:18 +00:00
|
|
|
/* Move cursor to absolute position. */
|
2009-10-12 09:29:58 +00:00
|
|
|
void
|
|
|
|
tty_cursor(struct tty *tty, u_int cx, u_int cy)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-10-12 13:01:18 +00:00
|
|
|
struct tty_term *term = tty->term;
|
|
|
|
u_int thisx, thisy;
|
|
|
|
int change;
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-10-12 13:01:18 +00:00
|
|
|
if (cx > tty->sx - 1)
|
|
|
|
cx = tty->sx - 1;
|
|
|
|
|
|
|
|
thisx = tty->cx;
|
|
|
|
thisy = tty->cy;
|
|
|
|
|
|
|
|
/* No change. */
|
|
|
|
if (cx == thisx && cy == thisy)
|
|
|
|
return;
|
|
|
|
|
2009-10-12 14:54:19 +00:00
|
|
|
/* Very end of the line, just use absolute movement. */
|
|
|
|
if (thisx > tty->sx - 1)
|
|
|
|
goto absolute;
|
|
|
|
|
2009-10-12 13:01:18 +00:00
|
|
|
/* Move to home position (0, 0). */
|
|
|
|
if (cx == 0 && cy == 0 && tty_term_has(term, TTYC_HOME)) {
|
|
|
|
tty_putcode(tty, TTYC_HOME);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Zero on the next line. */
|
2009-10-13 08:37:15 +00:00
|
|
|
if (cx == 0 && cy == thisy + 1 && thisy != tty->rlower) {
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_putc(tty, '\r');
|
2009-10-12 13:01:18 +00:00
|
|
|
tty_putc(tty, '\n');
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-10-12 16:41:02 +00:00
|
|
|
/* Moving column or row. */
|
2009-10-12 13:01:18 +00:00
|
|
|
if (cy == thisy) {
|
2009-10-12 16:41:02 +00:00
|
|
|
/*
|
|
|
|
* Moving column only, row staying the same.
|
|
|
|
*/
|
|
|
|
|
2009-10-12 13:01:18 +00:00
|
|
|
/* To left edge. */
|
2016-05-30 09:26:49 +00:00
|
|
|
if (cx == 0) {
|
2009-10-12 13:01:18 +00:00
|
|
|
tty_putc(tty, '\r');
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* One to the left. */
|
|
|
|
if (cx == thisx - 1 && tty_term_has(term, TTYC_CUB1)) {
|
|
|
|
tty_putcode(tty, TTYC_CUB1);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* One to the right. */
|
|
|
|
if (cx == thisx + 1 && tty_term_has(term, TTYC_CUF1)) {
|
|
|
|
tty_putcode(tty, TTYC_CUF1);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate difference. */
|
|
|
|
change = thisx - cx; /* +ve left, -ve right */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use HPA if change is larger than absolute, otherwise move
|
|
|
|
* the cursor with CUB/CUF.
|
|
|
|
*/
|
2010-06-05 16:32:22 +00:00
|
|
|
if ((u_int) abs(change) > cx && tty_term_has(term, TTYC_HPA)) {
|
2009-10-12 13:01:18 +00:00
|
|
|
tty_putcode1(tty, TTYC_HPA, cx);
|
|
|
|
goto out;
|
|
|
|
} else if (change > 0 && tty_term_has(term, TTYC_CUB)) {
|
2016-05-30 09:26:49 +00:00
|
|
|
if (change == 2 && tty_term_has(term, TTYC_CUB1)) {
|
|
|
|
tty_putcode(tty, TTYC_CUB1);
|
|
|
|
tty_putcode(tty, TTYC_CUB1);
|
|
|
|
goto out;
|
|
|
|
}
|
2009-10-12 13:01:18 +00:00
|
|
|
tty_putcode1(tty, TTYC_CUB, change);
|
|
|
|
goto out;
|
|
|
|
} else if (change < 0 && tty_term_has(term, TTYC_CUF)) {
|
|
|
|
tty_putcode1(tty, TTYC_CUF, -change);
|
|
|
|
goto out;
|
|
|
|
}
|
2009-10-12 16:41:02 +00:00
|
|
|
} else if (cx == thisx) {
|
|
|
|
/*
|
|
|
|
* Moving row only, column staying the same.
|
|
|
|
*/
|
2009-10-12 13:01:18 +00:00
|
|
|
|
|
|
|
/* One above. */
|
2009-12-03 22:50:09 +00:00
|
|
|
if (thisy != tty->rupper &&
|
2009-10-12 13:01:18 +00:00
|
|
|
cy == thisy - 1 && tty_term_has(term, TTYC_CUU1)) {
|
|
|
|
tty_putcode(tty, TTYC_CUU1);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* One below. */
|
2009-10-16 19:09:40 +00:00
|
|
|
if (thisy != tty->rlower &&
|
2009-10-12 13:01:18 +00:00
|
|
|
cy == thisy + 1 && tty_term_has(term, TTYC_CUD1)) {
|
|
|
|
tty_putcode(tty, TTYC_CUD1);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate difference. */
|
|
|
|
change = thisy - cy; /* +ve up, -ve down */
|
|
|
|
|
|
|
|
/*
|
2009-12-03 22:50:09 +00:00
|
|
|
* Try to use VPA if change is larger than absolute or if this
|
|
|
|
* change would cross the scroll region, otherwise use CUU/CUD.
|
2009-10-12 13:01:18 +00:00
|
|
|
*/
|
2010-06-05 16:32:22 +00:00
|
|
|
if ((u_int) abs(change) > cy ||
|
2009-10-12 13:01:18 +00:00
|
|
|
(change < 0 && cy - change > tty->rlower) ||
|
2009-10-12 16:37:43 +00:00
|
|
|
(change > 0 && cy - change < tty->rupper)) {
|
|
|
|
if (tty_term_has(term, TTYC_VPA)) {
|
|
|
|
tty_putcode1(tty, TTYC_VPA, cy);
|
|
|
|
goto out;
|
|
|
|
}
|
2009-10-12 13:01:18 +00:00
|
|
|
} else if (change > 0 && tty_term_has(term, TTYC_CUU)) {
|
|
|
|
tty_putcode1(tty, TTYC_CUU, change);
|
|
|
|
goto out;
|
|
|
|
} else if (change < 0 && tty_term_has(term, TTYC_CUD)) {
|
|
|
|
tty_putcode1(tty, TTYC_CUD, -change);
|
|
|
|
goto out;
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2009-10-12 13:01:18 +00:00
|
|
|
|
2009-10-12 14:54:19 +00:00
|
|
|
absolute:
|
2009-10-12 13:01:18 +00:00
|
|
|
/* Absolute movement. */
|
|
|
|
tty_putcode2(tty, TTYC_CUP, cy, cx);
|
|
|
|
|
|
|
|
out:
|
|
|
|
tty->cx = cx;
|
|
|
|
tty->cy = cy;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-19 21:05:27 +00:00
|
|
|
tty_attributes(struct tty *tty, const struct grid_cell *gc,
|
|
|
|
const struct window_pane *wp)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-10-28 08:52:36 +00:00
|
|
|
struct grid_cell *tc = &tty->cell, gc2;
|
2010-03-01 22:44:31 +00:00
|
|
|
u_char changed;
|
2009-10-28 08:27:33 +00:00
|
|
|
|
2017-02-06 19:45:23 +00:00
|
|
|
/* Ignore cell if it is the same as the last one. */
|
|
|
|
if (wp != NULL &&
|
|
|
|
(int)wp->id == tty->last_wp &&
|
|
|
|
~(wp->window->flags & WINDOW_STYLECHANGED) &&
|
|
|
|
gc->attr == tty->last_cell.attr &&
|
|
|
|
gc->fg == tty->last_cell.fg &&
|
|
|
|
gc->bg == tty->last_cell.bg)
|
|
|
|
return;
|
|
|
|
tty->last_wp = (wp != NULL ? (int)wp->id : -1);
|
|
|
|
memcpy(&tty->last_cell, gc, sizeof tty->last_cell);
|
|
|
|
|
|
|
|
/* Copy cell and update default colours. */
|
2010-03-01 22:44:31 +00:00
|
|
|
memcpy(&gc2, gc, sizeof gc2);
|
2016-05-30 09:50:20 +00:00
|
|
|
if (wp != NULL)
|
|
|
|
tty_default_colours(&gc2, wp);
|
2009-10-28 08:52:36 +00:00
|
|
|
|
2009-08-05 16:26:38 +00:00
|
|
|
/*
|
|
|
|
* If no setab, try to use the reverse attribute as a best-effort for a
|
|
|
|
* non-default background. This is a bit of a hack but it doesn't do
|
|
|
|
* any serious harm and makes a couple of applications happier.
|
|
|
|
*/
|
|
|
|
if (!tty_term_has(tty->term, TTYC_SETAB)) {
|
2010-03-01 22:44:31 +00:00
|
|
|
if (gc2.attr & GRID_ATTR_REVERSE) {
|
|
|
|
if (gc2.fg != 7 && gc2.fg != 8)
|
2009-11-04 13:34:26 +00:00
|
|
|
gc2.attr &= ~GRID_ATTR_REVERSE;
|
2009-08-05 16:26:38 +00:00
|
|
|
} else {
|
2010-03-01 22:44:31 +00:00
|
|
|
if (gc2.bg != 0 && gc2.bg != 8)
|
2009-11-04 13:34:26 +00:00
|
|
|
gc2.attr |= GRID_ATTR_REVERSE;
|
2009-08-05 16:26:38 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2010-03-01 22:44:31 +00:00
|
|
|
/* Fix up the colours if necessary. */
|
2017-01-07 15:28:13 +00:00
|
|
|
tty_check_fg(tty, wp, &gc2);
|
|
|
|
tty_check_bg(tty, wp, &gc2);
|
2010-03-01 22:44:31 +00:00
|
|
|
|
2009-11-04 13:34:26 +00:00
|
|
|
/* If any bits are being cleared, reset everything. */
|
2010-03-01 22:44:31 +00:00
|
|
|
if (tc->attr & ~gc2.attr)
|
2009-11-04 13:34:26 +00:00
|
|
|
tty_reset(tty);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the colours. This may call tty_reset() (so it comes next) and
|
|
|
|
* may add to (NOT remove) the desired attributes by changing new_attr.
|
|
|
|
*/
|
2010-03-01 22:44:31 +00:00
|
|
|
tty_colours(tty, &gc2);
|
2009-11-04 13:34:26 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
/* Filter out attribute bits already set. */
|
2010-03-01 22:44:31 +00:00
|
|
|
changed = gc2.attr & ~tc->attr;
|
|
|
|
tc->attr = gc2.attr;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
/* Set the attributes. */
|
|
|
|
if (changed & GRID_ATTR_BRIGHT)
|
|
|
|
tty_putcode(tty, TTYC_BOLD);
|
|
|
|
if (changed & GRID_ATTR_DIM)
|
|
|
|
tty_putcode(tty, TTYC_DIM);
|
2015-04-29 15:59:08 +00:00
|
|
|
if (changed & GRID_ATTR_ITALICS)
|
|
|
|
tty_set_italics(tty);
|
2009-06-01 22:58:49 +00:00
|
|
|
if (changed & GRID_ATTR_UNDERSCORE)
|
|
|
|
tty_putcode(tty, TTYC_SMUL);
|
|
|
|
if (changed & GRID_ATTR_BLINK)
|
|
|
|
tty_putcode(tty, TTYC_BLINK);
|
|
|
|
if (changed & GRID_ATTR_REVERSE) {
|
|
|
|
if (tty_term_has(tty->term, TTYC_REV))
|
|
|
|
tty_putcode(tty, TTYC_REV);
|
|
|
|
else if (tty_term_has(tty->term, TTYC_SMSO))
|
|
|
|
tty_putcode(tty, TTYC_SMSO);
|
|
|
|
}
|
|
|
|
if (changed & GRID_ATTR_HIDDEN)
|
|
|
|
tty_putcode(tty, TTYC_INVIS);
|
2010-09-11 16:19:22 +00:00
|
|
|
if ((changed & GRID_ATTR_CHARSET) && tty_use_acs(tty))
|
2009-06-01 22:58:49 +00:00
|
|
|
tty_putcode(tty, TTYC_SMACS);
|
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2010-03-01 22:44:31 +00:00
|
|
|
tty_colours(struct tty *tty, const struct grid_cell *gc)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-10-28 08:27:33 +00:00
|
|
|
struct grid_cell *tc = &tty->cell;
|
2016-07-15 00:49:08 +00:00
|
|
|
int have_ax;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-10-28 08:27:33 +00:00
|
|
|
/* No changes? Nothing is necessary. */
|
2016-07-15 00:49:08 +00:00
|
|
|
if (gc->fg == tc->fg && gc->bg == tc->bg)
|
2009-10-28 08:52:36 +00:00
|
|
|
return;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-10-28 08:27:33 +00:00
|
|
|
/*
|
|
|
|
* Is either the default colour? This is handled specially because the
|
|
|
|
* best solution might be to reset both colours to default, in which
|
|
|
|
* case if only one is default need to fall onward to set the other
|
|
|
|
* colour.
|
|
|
|
*/
|
2016-07-15 00:49:08 +00:00
|
|
|
if (gc->fg == 8 || gc->bg == 8) {
|
2009-10-28 08:27:33 +00:00
|
|
|
/*
|
|
|
|
* If don't have AX but do have op, send sgr0 (op can't
|
|
|
|
* actually be used because it is sometimes the same as sgr0
|
|
|
|
* and sometimes isn't). This resets both colours to default.
|
|
|
|
*
|
|
|
|
* Otherwise, try to set the default colour only as needed.
|
|
|
|
*/
|
2015-04-15 22:10:13 +00:00
|
|
|
have_ax = tty_term_flag(tty->term, TTYC_AX);
|
2009-10-28 08:27:33 +00:00
|
|
|
if (!have_ax && tty_term_has(tty->term, TTYC_OP))
|
|
|
|
tty_reset(tty);
|
|
|
|
else {
|
2016-07-15 00:49:08 +00:00
|
|
|
if (gc->fg == 8 && tc->fg != 8) {
|
2009-10-28 08:27:33 +00:00
|
|
|
if (have_ax)
|
|
|
|
tty_puts(tty, "\033[39m");
|
2016-07-15 00:49:08 +00:00
|
|
|
else if (tc->fg != 7)
|
2009-10-28 08:27:33 +00:00
|
|
|
tty_putcode1(tty, TTYC_SETAF, 7);
|
|
|
|
tc->fg = 8;
|
|
|
|
}
|
2016-07-15 00:49:08 +00:00
|
|
|
if (gc->bg == 8 && tc->bg != 8) {
|
2009-12-03 22:50:09 +00:00
|
|
|
if (have_ax)
|
2009-10-28 08:27:33 +00:00
|
|
|
tty_puts(tty, "\033[49m");
|
2016-07-15 00:49:08 +00:00
|
|
|
else if (tc->bg != 0)
|
2009-10-28 08:27:33 +00:00
|
|
|
tty_putcode1(tty, TTYC_SETAB, 0);
|
|
|
|
tc->bg = 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-10-28 08:27:33 +00:00
|
|
|
/* Set the foreground colour. */
|
2016-07-15 00:49:08 +00:00
|
|
|
if (gc->fg != 8 && gc->fg != tc->fg)
|
2010-03-01 22:44:31 +00:00
|
|
|
tty_colours_fg(tty, gc);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-10-28 08:27:33 +00:00
|
|
|
/*
|
|
|
|
* Set the background colour. This must come after the foreground as
|
|
|
|
* tty_colour_fg() can call tty_reset().
|
|
|
|
*/
|
2016-07-15 00:49:08 +00:00
|
|
|
if (gc->bg != 8 && gc->bg != tc->bg)
|
2009-11-26 21:37:13 +00:00
|
|
|
tty_colours_bg(tty, gc);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2017-01-07 15:28:13 +00:00
|
|
|
static void
|
|
|
|
tty_check_fg(struct tty *tty, const struct window_pane *wp,
|
|
|
|
struct grid_cell *gc)
|
2010-03-01 22:44:31 +00:00
|
|
|
{
|
2016-07-15 00:49:08 +00:00
|
|
|
u_char r, g, b;
|
|
|
|
u_int colours;
|
2017-01-12 00:19:32 +00:00
|
|
|
int c;
|
2010-03-01 22:44:31 +00:00
|
|
|
|
2017-01-07 15:28:13 +00:00
|
|
|
/* Perform substitution if this pane has a palette */
|
|
|
|
if ((~gc->flags & GRID_FLAG_NOPALETTE) &&
|
2017-01-12 00:19:32 +00:00
|
|
|
(c = window_pane_get_palette(wp, gc->fg)) != -1)
|
|
|
|
gc->fg = c;
|
2017-01-07 15:28:13 +00:00
|
|
|
|
2016-01-29 11:13:56 +00:00
|
|
|
/* Is this a 24-bit colour? */
|
2016-07-15 00:49:08 +00:00
|
|
|
if (gc->fg & COLOUR_FLAG_RGB) {
|
2016-01-29 11:13:56 +00:00
|
|
|
/* Not a 24-bit terminal? Translate to 256-colour palette. */
|
|
|
|
if (!tty_term_flag(tty->term, TTYC_TC)) {
|
2016-07-15 00:49:08 +00:00
|
|
|
colour_split_rgb(gc->fg, &r, &g, &b);
|
|
|
|
gc->fg = colour_find_rgb(r, g, b);
|
|
|
|
} else
|
2016-03-03 12:58:15 +00:00
|
|
|
return;
|
2016-01-29 11:13:56 +00:00
|
|
|
}
|
2017-01-12 00:30:41 +00:00
|
|
|
|
|
|
|
/* How many colours does this terminal have? */
|
|
|
|
if ((tty->term->flags|tty->term_flags) & TERM_256COLOURS)
|
|
|
|
colours = 256;
|
|
|
|
else
|
|
|
|
colours = tty_term_number(tty->term, TTYC_COLORS);
|
2015-04-15 22:34:46 +00:00
|
|
|
|
2010-03-01 22:44:31 +00:00
|
|
|
/* Is this a 256-colour colour? */
|
2016-07-15 00:49:08 +00:00
|
|
|
if (gc->fg & COLOUR_FLAG_256) {
|
2010-03-01 22:44:31 +00:00
|
|
|
/* And not a 256 colour mode? */
|
2017-01-12 00:30:41 +00:00
|
|
|
if (colours != 256) {
|
2010-03-01 22:44:31 +00:00
|
|
|
gc->fg = colour_256to16(gc->fg);
|
|
|
|
if (gc->fg & 8) {
|
|
|
|
gc->fg &= 7;
|
2015-04-15 22:34:46 +00:00
|
|
|
if (colours >= 16)
|
|
|
|
gc->fg += 90;
|
|
|
|
else
|
|
|
|
gc->attr |= GRID_ATTR_BRIGHT;
|
2010-03-01 22:44:31 +00:00
|
|
|
} else
|
|
|
|
gc->attr &= ~GRID_ATTR_BRIGHT;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is this an aixterm colour? */
|
|
|
|
if (gc->fg >= 90 && gc->fg <= 97 && colours < 16) {
|
|
|
|
gc->fg -= 90;
|
|
|
|
gc->attr |= GRID_ATTR_BRIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-07 15:28:13 +00:00
|
|
|
static void
|
|
|
|
tty_check_bg(struct tty *tty, const struct window_pane *wp,
|
|
|
|
struct grid_cell *gc)
|
2010-03-01 22:44:31 +00:00
|
|
|
{
|
2016-07-15 00:49:08 +00:00
|
|
|
u_char r, g, b;
|
|
|
|
u_int colours;
|
2017-01-12 00:19:32 +00:00
|
|
|
int c;
|
2010-03-01 22:44:31 +00:00
|
|
|
|
2017-01-07 15:28:13 +00:00
|
|
|
/* Perform substitution if this pane has a palette */
|
|
|
|
if ((~gc->flags & GRID_FLAG_NOPALETTE) &&
|
2017-01-12 00:19:32 +00:00
|
|
|
(c = window_pane_get_palette(wp, gc->bg)) != -1)
|
|
|
|
gc->bg = c;
|
2017-01-07 15:28:13 +00:00
|
|
|
|
2016-01-29 11:13:56 +00:00
|
|
|
/* Is this a 24-bit colour? */
|
2016-07-15 00:49:08 +00:00
|
|
|
if (gc->bg & COLOUR_FLAG_RGB) {
|
2016-01-29 11:13:56 +00:00
|
|
|
/* Not a 24-bit terminal? Translate to 256-colour palette. */
|
|
|
|
if (!tty_term_flag(tty->term, TTYC_TC)) {
|
2016-07-15 00:49:08 +00:00
|
|
|
colour_split_rgb(gc->bg, &r, &g, &b);
|
|
|
|
gc->bg = colour_find_rgb(r, g, b);
|
|
|
|
} else
|
2016-03-03 12:58:15 +00:00
|
|
|
return;
|
2016-01-29 11:13:56 +00:00
|
|
|
}
|
2017-01-12 00:30:41 +00:00
|
|
|
|
|
|
|
/* How many colours does this terminal have? */
|
|
|
|
if ((tty->term->flags|tty->term_flags) & TERM_256COLOURS)
|
|
|
|
colours = 256;
|
|
|
|
else
|
|
|
|
colours = tty_term_number(tty->term, TTYC_COLORS);
|
2015-04-15 22:34:46 +00:00
|
|
|
|
2010-03-01 22:44:31 +00:00
|
|
|
/* Is this a 256-colour colour? */
|
2016-07-15 00:49:08 +00:00
|
|
|
if (gc->bg & COLOUR_FLAG_256) {
|
2010-03-01 22:44:31 +00:00
|
|
|
/*
|
|
|
|
* And not a 256 colour mode? Translate to 16-colour
|
|
|
|
* palette. Bold background doesn't exist portably, so just
|
|
|
|
* discard the bold bit if set.
|
|
|
|
*/
|
2017-01-12 00:30:41 +00:00
|
|
|
if (colours != 256) {
|
2010-03-01 22:44:31 +00:00
|
|
|
gc->bg = colour_256to16(gc->bg);
|
2015-04-15 22:34:46 +00:00
|
|
|
if (gc->bg & 8) {
|
2010-03-01 22:44:31 +00:00
|
|
|
gc->bg &= 7;
|
2015-04-15 22:34:46 +00:00
|
|
|
if (colours >= 16)
|
|
|
|
gc->fg += 90;
|
|
|
|
}
|
2010-03-01 22:44:31 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is this an aixterm colour? */
|
2015-04-15 22:34:46 +00:00
|
|
|
if (gc->bg >= 90 && gc->bg <= 97 && colours < 16)
|
2010-03-01 22:44:31 +00:00
|
|
|
gc->bg -= 90;
|
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2010-03-01 22:44:31 +00:00
|
|
|
tty_colours_fg(struct tty *tty, const struct grid_cell *gc)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-10-28 08:27:33 +00:00
|
|
|
struct grid_cell *tc = &tty->cell;
|
2009-12-14 21:33:38 +00:00
|
|
|
char s[32];
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
/* Is this a 24-bit or 256-colour colour? */
|
|
|
|
if (gc->fg & COLOUR_FLAG_RGB ||
|
|
|
|
gc->fg & COLOUR_FLAG_256) {
|
|
|
|
if (tty_try_colour(tty, gc->fg, "38") == 0)
|
2009-10-28 08:27:33 +00:00
|
|
|
goto save_fg;
|
2016-01-29 11:13:56 +00:00
|
|
|
/* Should not get here, already converted in tty_check_fg. */
|
2010-03-01 22:44:31 +00:00
|
|
|
return;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2009-12-14 21:33:38 +00:00
|
|
|
/* Is this an aixterm bright colour? */
|
2016-07-15 00:49:08 +00:00
|
|
|
if (gc->fg >= 90 && gc->fg <= 97) {
|
|
|
|
xsnprintf(s, sizeof s, "\033[%dm", gc->fg);
|
2010-03-01 22:44:31 +00:00
|
|
|
tty_puts(tty, s);
|
|
|
|
goto save_fg;
|
2009-12-14 21:33:38 +00:00
|
|
|
}
|
|
|
|
|
2009-10-28 08:27:33 +00:00
|
|
|
/* Otherwise set the foreground colour. */
|
2016-07-15 00:49:08 +00:00
|
|
|
tty_putcode1(tty, TTYC_SETAF, gc->fg);
|
2009-10-28 08:27:33 +00:00
|
|
|
|
2009-12-03 22:50:09 +00:00
|
|
|
save_fg:
|
2009-10-28 08:27:33 +00:00
|
|
|
/* Save the new values in the terminal current cell. */
|
2016-07-15 00:49:08 +00:00
|
|
|
tc->fg = gc->fg;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2009-11-26 21:37:13 +00:00
|
|
|
tty_colours_bg(struct tty *tty, const struct grid_cell *gc)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-10-28 08:27:33 +00:00
|
|
|
struct grid_cell *tc = &tty->cell;
|
2009-12-14 21:33:38 +00:00
|
|
|
char s[32];
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
/* Is this a 24-bit or 256-colour colour? */
|
|
|
|
if (gc->bg & COLOUR_FLAG_RGB ||
|
|
|
|
gc->bg & COLOUR_FLAG_256) {
|
|
|
|
if (tty_try_colour(tty, gc->bg, "48") == 0)
|
2009-10-28 08:27:33 +00:00
|
|
|
goto save_bg;
|
2016-01-29 11:13:56 +00:00
|
|
|
/* Should not get here, already converted in tty_check_bg. */
|
2010-03-01 22:44:31 +00:00
|
|
|
return;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2009-12-14 21:33:38 +00:00
|
|
|
/* Is this an aixterm bright colour? */
|
2016-07-15 00:49:08 +00:00
|
|
|
if (gc->bg >= 90 && gc->bg <= 97) {
|
|
|
|
xsnprintf(s, sizeof s, "\033[%dm", gc->bg + 10);
|
2015-04-15 22:34:46 +00:00
|
|
|
tty_puts(tty, s);
|
|
|
|
goto save_bg;
|
2009-12-14 21:33:38 +00:00
|
|
|
}
|
|
|
|
|
2009-10-28 08:27:33 +00:00
|
|
|
/* Otherwise set the background colour. */
|
2016-07-15 00:49:08 +00:00
|
|
|
tty_putcode1(tty, TTYC_SETAB, gc->bg);
|
2009-10-28 08:27:33 +00:00
|
|
|
|
|
|
|
save_bg:
|
|
|
|
/* Save the new values in the terminal current cell. */
|
2016-07-15 00:49:08 +00:00
|
|
|
tc->bg = gc->bg;
|
2009-10-28 08:27:33 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static int
|
2016-07-15 00:49:08 +00:00
|
|
|
tty_try_colour(struct tty *tty, int colour, const char *type)
|
2009-10-28 08:27:33 +00:00
|
|
|
{
|
2016-07-15 00:49:08 +00:00
|
|
|
u_char r, g, b;
|
2009-10-28 08:27:33 +00:00
|
|
|
char s[32];
|
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
if (colour & COLOUR_FLAG_256) {
|
|
|
|
/*
|
|
|
|
* If the user has specified -2 to the client, setaf and setab
|
|
|
|
* may not work (or they may not want to use them), so send the
|
|
|
|
* usual sequence.
|
|
|
|
*/
|
|
|
|
if (tty->term_flags & TERM_256COLOURS)
|
|
|
|
goto fallback_256;
|
2015-10-23 15:52:54 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
/*
|
|
|
|
* If the terminfo entry has 256 colours and setaf and setab
|
|
|
|
* exist, assume that they work correctly.
|
|
|
|
*/
|
|
|
|
if (tty->term->flags & TERM_256COLOURS) {
|
|
|
|
if (*type == '3') {
|
|
|
|
if (!tty_term_has(tty->term, TTYC_SETAF))
|
|
|
|
goto fallback_256;
|
|
|
|
tty_putcode1(tty, TTYC_SETAF, colour & 0xff);
|
|
|
|
} else {
|
|
|
|
if (!tty_term_has(tty->term, TTYC_SETAB))
|
|
|
|
goto fallback_256;
|
|
|
|
tty_putcode1(tty, TTYC_SETAB, colour & 0xff);
|
|
|
|
}
|
|
|
|
return (0);
|
2015-09-25 23:30:12 +00:00
|
|
|
}
|
2016-07-15 00:49:08 +00:00
|
|
|
goto fallback_256;
|
2014-02-14 14:37:08 +00:00
|
|
|
}
|
2009-10-28 08:27:33 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
if (colour & COLOUR_FLAG_RGB) {
|
|
|
|
if (!tty_term_flag(tty->term, TTYC_TC))
|
|
|
|
return (-1);
|
2009-10-28 08:27:33 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
colour_split_rgb(colour & 0xffffff, &r, &g, &b);
|
|
|
|
xsnprintf(s, sizeof s, "\033[%s;2;%hhu;%hhu;%hhum", type,
|
|
|
|
r, g, b);
|
|
|
|
tty_puts(tty, s);
|
|
|
|
return (0);
|
|
|
|
}
|
2016-01-29 11:13:56 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
return (-1);
|
2016-01-29 11:13:56 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
fallback_256:
|
|
|
|
xsnprintf(s, sizeof s, "\033[%s;5;%dm", type, colour & 0xff);
|
2016-01-29 11:13:56 +00:00
|
|
|
tty_puts(tty, s);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2015-04-19 21:05:27 +00:00
|
|
|
tty_default_colours(struct grid_cell *gc, const struct window_pane *wp)
|
|
|
|
{
|
2016-05-30 09:50:20 +00:00
|
|
|
struct window *w = wp->window;
|
|
|
|
struct options *oo = w->options;
|
|
|
|
const struct grid_cell *agc, *pgc, *wgc;
|
2017-01-12 00:19:32 +00:00
|
|
|
int c;
|
2015-04-19 21:05:27 +00:00
|
|
|
|
2016-05-30 09:50:20 +00:00
|
|
|
if (w->flags & WINDOW_STYLECHANGED) {
|
|
|
|
w->flags &= ~WINDOW_STYLECHANGED;
|
|
|
|
agc = options_get_style(oo, "window-active-style");
|
|
|
|
memcpy(&w->active_style, agc, sizeof w->active_style);
|
|
|
|
wgc = options_get_style(oo, "window-style");
|
|
|
|
memcpy(&w->style, wgc, sizeof w->style);
|
|
|
|
} else {
|
|
|
|
agc = &w->active_style;
|
|
|
|
wgc = &w->style;
|
|
|
|
}
|
2015-04-19 21:05:27 +00:00
|
|
|
pgc = &wp->colgc;
|
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
if (gc->fg == 8) {
|
|
|
|
if (pgc->fg != 8)
|
2015-04-19 21:05:27 +00:00
|
|
|
gc->fg = pgc->fg;
|
2016-07-15 00:49:08 +00:00
|
|
|
else if (wp == w->active && agc->fg != 8)
|
2015-04-19 21:05:27 +00:00
|
|
|
gc->fg = agc->fg;
|
2016-07-15 00:49:08 +00:00
|
|
|
else
|
2015-04-19 21:05:27 +00:00
|
|
|
gc->fg = wgc->fg;
|
2017-01-07 15:28:13 +00:00
|
|
|
|
2017-01-12 00:19:32 +00:00
|
|
|
if (gc->fg != 8 &&
|
|
|
|
(c = window_pane_get_palette(wp, gc->fg)) != -1)
|
|
|
|
gc->fg = c;
|
2015-04-19 21:05:27 +00:00
|
|
|
}
|
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
if (gc->bg == 8) {
|
|
|
|
if (pgc->bg != 8)
|
2015-04-19 21:05:27 +00:00
|
|
|
gc->bg = pgc->bg;
|
2016-07-15 00:49:08 +00:00
|
|
|
else if (wp == w->active && agc->bg != 8)
|
2015-04-19 21:05:27 +00:00
|
|
|
gc->bg = agc->bg;
|
2016-07-15 00:49:08 +00:00
|
|
|
else
|
2015-04-19 21:05:27 +00:00
|
|
|
gc->bg = wgc->bg;
|
2017-01-07 15:28:13 +00:00
|
|
|
|
2017-01-12 00:19:32 +00:00
|
|
|
if (gc->bg != 8 &&
|
|
|
|
(c = window_pane_get_palette(wp, gc->bg)) != -1)
|
|
|
|
gc->bg = c;
|
2015-04-19 21:05:27 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-13 20:27:27 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
tty_default_attributes(struct tty *tty, const struct window_pane *wp, u_int bg)
|
|
|
|
{
|
|
|
|
static struct grid_cell gc;
|
|
|
|
|
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
|
|
|
gc.bg = bg;
|
|
|
|
tty_attributes(tty, &gc, wp);
|
|
|
|
}
|