2009-01-10 01:51:22 +00:00
|
|
|
/* $Id: tty.c,v 1.56 2009-01-10 01:51:22 nicm Exp $ */
|
2007-11-27 19:23:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <termios.h>
|
2008-06-18 22:08:56 +00:00
|
|
|
#include <unistd.h>
|
2007-11-27 19:23:34 +00:00
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
void tty_fill_acs(struct tty *);
|
|
|
|
u_char tty_get_acs(struct tty *, u_char);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
void tty_emulate_repeat(
|
|
|
|
struct tty *, enum tty_code_code, enum tty_code_code, u_int);
|
2008-12-13 17:41:49 +00:00
|
|
|
|
2007-11-27 19:23:34 +00:00
|
|
|
void tty_raw(struct tty *, const char *);
|
2009-01-09 23:57:42 +00:00
|
|
|
void tty_putcode(struct tty *, enum tty_code_code);
|
|
|
|
void tty_putcode1(struct tty *, enum tty_code_code, int);
|
|
|
|
void tty_putcode2(struct tty *, enum tty_code_code, int, int);
|
2007-11-27 19:23:34 +00:00
|
|
|
void tty_puts(struct tty *, const char *);
|
|
|
|
void tty_putc(struct tty *, char);
|
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
void tty_reset(struct tty *);
|
|
|
|
void tty_attributes(struct tty *, const struct grid_cell *);
|
|
|
|
void tty_attributes_fg(struct tty *, const struct grid_cell *);
|
|
|
|
void tty_attributes_bg(struct tty *, const struct grid_cell *);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
void tty_cmd_bell(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_carriagereturn(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_cell(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_clearendofline(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_clearendofscreen(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_clearline(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_clearscreen(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_clearstartofline(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_clearstartofscreen(struct tty *, struct screen *, va_list);
|
2008-09-25 20:08:57 +00:00
|
|
|
void tty_cmd_cursordown(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_cursorleft(struct tty *, struct screen *, va_list);
|
2009-01-09 23:57:42 +00:00
|
|
|
void tty_cmd_cursormode(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_cursormove(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_cursorright(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_cursorup(struct tty *, struct screen *, va_list);
|
2008-09-25 20:08:57 +00:00
|
|
|
void tty_cmd_deletecharacter(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_deleteline(struct tty *, struct screen *, va_list);
|
2009-01-09 23:57:42 +00:00
|
|
|
void tty_cmd_insertcharacter(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_insertline(struct tty *, struct screen *, va_list);
|
2008-09-25 20:08:57 +00:00
|
|
|
void tty_cmd_insertmode(struct tty *, struct screen *, va_list);
|
2009-01-09 23:57:42 +00:00
|
|
|
void tty_cmd_kcursormode(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_kkeypadmode(struct tty *, struct screen *, va_list);
|
2008-09-25 20:08:57 +00:00
|
|
|
void tty_cmd_linefeed(struct tty *, struct screen *, va_list);
|
2009-01-09 23:57:42 +00:00
|
|
|
void tty_cmd_mousemode(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_reverseindex(struct tty *, struct screen *, va_list);
|
|
|
|
void tty_cmd_scrollregion(struct tty *, struct screen *, va_list);
|
2008-09-25 20:08:57 +00:00
|
|
|
|
|
|
|
void (*tty_cmds[])(struct tty *, struct screen *, va_list) = {
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_cmd_bell,
|
|
|
|
tty_cmd_carriagereturn,
|
|
|
|
tty_cmd_cell,
|
|
|
|
tty_cmd_clearendofline,
|
|
|
|
tty_cmd_clearendofscreen,
|
|
|
|
tty_cmd_clearline,
|
|
|
|
tty_cmd_clearscreen,
|
|
|
|
tty_cmd_clearstartofline,
|
|
|
|
tty_cmd_clearstartofscreen,
|
2008-09-25 20:08:57 +00:00
|
|
|
tty_cmd_cursordown,
|
|
|
|
tty_cmd_cursorleft,
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_cmd_cursormode,
|
|
|
|
tty_cmd_cursormove,
|
|
|
|
tty_cmd_cursorright,
|
|
|
|
tty_cmd_cursorup,
|
2008-09-25 20:08:57 +00:00
|
|
|
tty_cmd_deletecharacter,
|
|
|
|
tty_cmd_deleteline,
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_cmd_insertcharacter,
|
|
|
|
tty_cmd_insertline,
|
2008-09-25 20:08:57 +00:00
|
|
|
tty_cmd_insertmode,
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_cmd_kcursormode,
|
|
|
|
tty_cmd_kkeypadmode,
|
2008-09-25 20:08:57 +00:00
|
|
|
tty_cmd_linefeed,
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_cmd_mousemode,
|
|
|
|
tty_cmd_reverseindex,
|
|
|
|
tty_cmd_scrollregion,
|
2008-09-25 20:08:57 +00:00
|
|
|
};
|
2007-11-27 19:23:34 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
tty_init(struct tty *tty, char *path, char *term)
|
|
|
|
{
|
|
|
|
tty->path = xstrdup(path);
|
2007-12-06 20:53:48 +00:00
|
|
|
if (term == NULL)
|
|
|
|
tty->termname = xstrdup("unknown");
|
|
|
|
else
|
|
|
|
tty->termname = xstrdup(term);
|
2008-09-09 22:16:37 +00:00
|
|
|
tty->flags = 0;
|
2008-09-25 20:08:57 +00:00
|
|
|
tty->term_flags = 0;
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tty_open(struct tty *tty, char **cause)
|
|
|
|
{
|
|
|
|
struct termios tio;
|
2008-12-06 09:30:25 +00:00
|
|
|
#ifdef TIOCFLUSH
|
|
|
|
int what;
|
|
|
|
#endif
|
|
|
|
int mode;
|
2007-11-27 19:23:34 +00:00
|
|
|
|
|
|
|
tty->fd = open(tty->path, O_RDWR|O_NONBLOCK);
|
|
|
|
if (tty->fd == -1) {
|
|
|
|
xasprintf(cause, "%s: %s", tty->path, strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2008-06-18 22:08:56 +00:00
|
|
|
if ((mode = fcntl(tty->fd, F_GETFL)) == -1)
|
|
|
|
fatal("fcntl");
|
|
|
|
if (fcntl(tty->fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
|
|
|
fatal("fcntl");
|
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
if (debug_level > 3)
|
2008-09-09 22:16:37 +00:00
|
|
|
tty->log_fd = open("tmux.out", O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
2008-09-25 20:08:57 +00:00
|
|
|
else
|
2008-09-09 22:16:37 +00:00
|
|
|
tty->log_fd = -1;
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
if ((tty->term = tty_term_find(tty->termname, tty->fd, cause)) == NULL)
|
2007-12-06 18:28:55 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
tty->in = buffer_create(BUFSIZ);
|
|
|
|
tty->out = buffer_create(BUFSIZ);
|
|
|
|
|
2008-09-09 22:16:37 +00:00
|
|
|
tty->flags &= TTY_UTF8;
|
2008-09-25 20:08:57 +00:00
|
|
|
memcpy(&tty->cell, &grid_default_cell, sizeof tty->cell);
|
2007-12-06 18:28:55 +00:00
|
|
|
|
|
|
|
if (tcgetattr(tty->fd, &tty->tio) != 0)
|
|
|
|
fatal("tcgetattr failed");
|
2008-06-10 18:51:22 +00:00
|
|
|
memcpy(&tio, &tty->tio, sizeof tio);
|
2008-07-02 16:18:24 +00:00
|
|
|
tio.c_iflag &= ~(IXON|IXOFF|ICRNL|INLCR|IGNCR|IMAXBEL|ISTRIP);
|
2008-06-18 22:08:56 +00:00
|
|
|
tio.c_iflag |= IGNBRK;
|
2008-07-02 16:18:24 +00:00
|
|
|
tio.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET);
|
2008-09-08 17:40:51 +00:00
|
|
|
tio.c_lflag &= ~(IEXTEN|ICANON|ECHO|ECHOE|ECHONL|ECHOCTL|
|
|
|
|
ECHOPRT|ECHOKE|ECHOCTL|ISIG);
|
2008-06-18 22:21:51 +00:00
|
|
|
tio.c_cc[VMIN] = 1;
|
2008-06-18 22:08:56 +00:00
|
|
|
tio.c_cc[VTIME] = 0;
|
2007-12-06 18:28:55 +00:00
|
|
|
if (tcsetattr(tty->fd, TCSANOW, &tio) != 0)
|
|
|
|
fatal("tcsetattr failed");
|
|
|
|
|
2007-12-16 17:18:43 +00:00
|
|
|
#ifdef TIOCFLUSH
|
2007-12-06 18:28:55 +00:00
|
|
|
what = 0;
|
|
|
|
if (ioctl(tty->fd, TIOCFLUSH, &what) != 0)
|
|
|
|
fatal("ioctl(TIOCFLUSH)");
|
2007-12-16 17:18:43 +00:00
|
|
|
#endif
|
2007-12-06 18:28:55 +00:00
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode(tty, TTYC_IS1);
|
|
|
|
tty_putcode(tty, TTYC_IS2);
|
|
|
|
tty_putcode(tty, TTYC_IS3);
|
|
|
|
|
|
|
|
tty_putcode(tty, TTYC_SMCUP);
|
|
|
|
tty_putcode(tty, TTYC_SMKX);
|
|
|
|
tty_putcode(tty, TTYC_ENACS);
|
|
|
|
tty_putcode(tty, TTYC_CLEAR);
|
2008-06-21 12:41:05 +00:00
|
|
|
|
|
|
|
tty_keys_init(tty);
|
|
|
|
|
|
|
|
tty_fill_acs(tty);
|
2007-12-06 18:28:55 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
error:
|
|
|
|
close(tty->fd);
|
|
|
|
tty->fd = -1;
|
|
|
|
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
void
|
|
|
|
tty_fill_acs(struct tty *tty)
|
|
|
|
{
|
|
|
|
const char *ptr;
|
|
|
|
|
|
|
|
memset(tty->acs, 0, sizeof tty->acs);
|
|
|
|
if (!tty_term_has(tty->term, TTYC_ACSC))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ptr = tty_term_string(tty->term, TTYC_ACSC);
|
|
|
|
if (strlen(ptr) % 2 != 0)
|
|
|
|
return;
|
|
|
|
for (; *ptr != '\0'; ptr += 2)
|
|
|
|
tty->acs[(u_char) ptr[0]] = ptr[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
u_char
|
|
|
|
tty_get_acs(struct tty *tty, u_char ch)
|
|
|
|
{
|
|
|
|
if (tty->acs[ch] != '\0')
|
|
|
|
return (tty->acs[ch]);
|
|
|
|
return (ch);
|
|
|
|
}
|
|
|
|
|
2007-12-06 18:28:55 +00:00
|
|
|
void
|
|
|
|
tty_close(struct tty *tty)
|
|
|
|
{
|
|
|
|
struct winsize ws;
|
|
|
|
|
2007-12-06 20:53:48 +00:00
|
|
|
if (tty->fd == -1)
|
|
|
|
return;
|
|
|
|
|
2008-09-09 22:16:37 +00:00
|
|
|
if (tty->log_fd != -1) {
|
|
|
|
close(tty->log_fd);
|
|
|
|
tty->log_fd = -1;
|
|
|
|
}
|
|
|
|
|
2008-01-02 19:22:21 +00:00
|
|
|
/*
|
2008-10-27 20:13:37 +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.
|
2008-01-02 19:22:21 +00:00
|
|
|
*/
|
|
|
|
if (ioctl(tty->fd, TIOCGWINSZ, &ws) == -1) {
|
2008-10-27 20:13:37 +00:00
|
|
|
if (errno != EBADF && errno != ENXIO && errno != ENOTTY)
|
2008-01-02 19:22:21 +00:00
|
|
|
fatal("ioctl(TIOCGWINSZ)");
|
2008-10-27 20:13:37 +00:00
|
|
|
} else if (tcsetattr(tty->fd, TCSANOW, &tty->tio) == -1) {
|
|
|
|
if (errno != EBADF && errno != ENXIO && errno != ENOTTY)
|
|
|
|
fatal("tcsetattr failed");
|
2008-01-02 19:22:21 +00:00
|
|
|
} else {
|
2009-01-10 01:51:22 +00:00
|
|
|
tty_raw(tty,
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_term_string2(tty->term, TTYC_CSR, 0, ws.ws_row - 1));
|
|
|
|
tty_raw(tty, tty_term_string(tty->term, TTYC_RMACS));
|
|
|
|
tty_raw(tty, tty_term_string(tty->term, TTYC_SGR0));
|
|
|
|
tty_raw(tty, tty_term_string(tty->term, TTYC_CLEAR));
|
|
|
|
tty_raw(tty, tty_term_string(tty->term, TTYC_RMKX));
|
|
|
|
tty_raw(tty, tty_term_string(tty->term, TTYC_RMCUP));
|
|
|
|
tty_raw(tty, tty_term_string(tty->term, TTYC_CNORM));
|
2008-01-02 19:22:21 +00:00
|
|
|
}
|
2009-01-10 01:51:22 +00:00
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_term_free(tty->term);
|
2007-12-06 18:28:55 +00:00
|
|
|
tty_keys_free(tty);
|
|
|
|
|
|
|
|
close(tty->fd);
|
|
|
|
tty->fd = -1;
|
|
|
|
|
|
|
|
buffer_destroy(tty->in);
|
|
|
|
buffer_destroy(tty->out);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_free(struct tty *tty)
|
|
|
|
{
|
2007-12-06 20:53:48 +00:00
|
|
|
tty_close(tty);
|
2007-12-06 18:28:55 +00:00
|
|
|
|
|
|
|
if (tty->path != NULL)
|
|
|
|
xfree(tty->path);
|
|
|
|
if (tty->termname != NULL)
|
|
|
|
xfree(tty->termname);
|
|
|
|
}
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
void
|
|
|
|
tty_raw(struct tty *tty, const char *s)
|
2007-12-06 18:28:55 +00:00
|
|
|
{
|
2009-01-09 23:57:42 +00:00
|
|
|
write(tty->fd, s, strlen(s));
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode(struct tty *tty, enum tty_code_code code)
|
2007-11-27 19:23:34 +00:00
|
|
|
{
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_puts(tty, tty_term_string(tty->term, code));
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode1(struct tty *tty, enum tty_code_code code, int a)
|
2007-11-27 19:23:34 +00:00
|
|
|
{
|
2009-01-09 23:57:42 +00:00
|
|
|
if (a < 0)
|
2007-11-27 19:23:34 +00:00
|
|
|
return;
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_puts(tty, tty_term_string1(tty->term, code, a));
|
2008-06-21 12:41:05 +00:00
|
|
|
}
|
|
|
|
|
2007-11-27 19:23:34 +00:00
|
|
|
void
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode2(struct tty *tty, enum tty_code_code code, int a, int b)
|
2007-11-27 19:23:34 +00:00
|
|
|
{
|
2009-01-09 23:57:42 +00:00
|
|
|
if (a < 0 || b < 0)
|
|
|
|
return;
|
|
|
|
tty_puts(tty, tty_term_string2(tty->term, code, a, b));
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_puts(struct tty *tty, const char *s)
|
|
|
|
{
|
2009-01-09 23:57:42 +00:00
|
|
|
if (*s == '\0')
|
2008-09-23 17:54:35 +00:00
|
|
|
return;
|
2009-01-09 23:57:42 +00:00
|
|
|
buffer_write(tty->out, s, strlen(s));
|
2008-09-09 22:16:37 +00:00
|
|
|
|
|
|
|
if (tty->log_fd != -1)
|
2009-01-09 23:57:42 +00:00
|
|
|
write(tty->log_fd, s, strlen(s));
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_putc(struct tty *tty, char ch)
|
|
|
|
{
|
2008-09-25 20:08:57 +00:00
|
|
|
if (tty->cell.attr & GRID_ATTR_CHARSET)
|
2007-11-27 19:23:34 +00:00
|
|
|
ch = tty_get_acs(tty, ch);
|
|
|
|
buffer_write8(tty->out, ch);
|
2008-09-09 22:16:37 +00:00
|
|
|
|
|
|
|
if (tty->log_fd != -1)
|
|
|
|
write(tty->log_fd, &ch, 1);
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
|
|
|
|
2008-06-18 18:52:44 +00:00
|
|
|
void
|
|
|
|
tty_set_title(struct tty *tty, const char *title)
|
|
|
|
{
|
2008-06-21 13:11:28 +00:00
|
|
|
if (strstr(tty->termname, "xterm") == NULL &&
|
|
|
|
strstr(tty->termname, "rxvt") == NULL &&
|
|
|
|
strcmp(tty->termname, "screen") != 0)
|
|
|
|
return;
|
|
|
|
|
2008-06-23 16:58:49 +00:00
|
|
|
tty_puts(tty, "\033]0;");
|
2008-06-18 18:52:44 +00:00
|
|
|
tty_puts(tty, title);
|
|
|
|
tty_putc(tty, '\007');
|
|
|
|
}
|
|
|
|
|
2008-12-13 17:41:49 +00:00
|
|
|
void
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_emulate_repeat(
|
|
|
|
struct tty *tty, enum tty_code_code code, enum tty_code_code code1, u_int n)
|
|
|
|
{
|
|
|
|
if (tty_term_has(tty->term, code))
|
|
|
|
tty_putcode1(tty, code, n);
|
|
|
|
else {
|
|
|
|
while (n-- > 0)
|
|
|
|
tty_putcode(tty, code1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_write(struct tty *tty, struct screen *s, enum tty_cmd cmd, ...)
|
2008-12-13 17:41:49 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, cmd);
|
|
|
|
tty_vwrite(tty, s, cmd, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2007-11-27 19:23:34 +00:00
|
|
|
void
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_vwrite(struct tty *tty, struct screen *s, enum tty_cmd cmd, va_list ap)
|
2007-11-27 19:23:34 +00:00
|
|
|
{
|
2009-01-09 23:57:42 +00:00
|
|
|
if (tty->flags & TTY_FREEZE || tty->term == NULL)
|
2008-06-20 06:36:01 +00:00
|
|
|
return;
|
2008-09-25 20:08:57 +00:00
|
|
|
if (tty_cmds[cmd] != NULL)
|
|
|
|
tty_cmds[cmd](tty, s, ap);
|
|
|
|
}
|
2008-09-09 22:16:37 +00:00
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
void
|
|
|
|
tty_cmd_cursorup(struct tty *tty, unused struct screen *s, va_list ap)
|
|
|
|
{
|
|
|
|
u_int ua;
|
|
|
|
|
|
|
|
ua = va_arg(ap, u_int);
|
2009-01-10 01:51:22 +00:00
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_CUU, TTYC_CUU1, ua);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_cursordown(struct tty *tty, unused struct screen *s, va_list ap)
|
|
|
|
{
|
|
|
|
u_int ua;
|
|
|
|
|
|
|
|
ua = va_arg(ap, u_int);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, ua);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_cursorright(struct tty *tty, unused struct screen *s, va_list ap)
|
|
|
|
{
|
|
|
|
u_int ua;
|
|
|
|
|
|
|
|
ua = va_arg(ap, u_int);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_CUF, TTYC_CUF1, ua);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_cursorleft(struct tty *tty, unused struct screen *s, va_list ap)
|
|
|
|
{
|
|
|
|
u_int ua;
|
|
|
|
|
|
|
|
ua = va_arg(ap, u_int);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_CUB, TTYC_CUB1, ua);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_cmd_insertcharacter(struct tty *tty, unused struct screen *s, va_list ap)
|
2008-09-25 20:08:57 +00:00
|
|
|
{
|
|
|
|
u_int ua;
|
|
|
|
|
|
|
|
ua = va_arg(ap, u_int);
|
|
|
|
|
|
|
|
tty_reset(tty);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_ICH, TTYC_ICH1, ua);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_deletecharacter(struct tty *tty, unused struct screen *s, va_list ap)
|
|
|
|
{
|
|
|
|
u_int ua;
|
|
|
|
|
|
|
|
ua = va_arg(ap, u_int);
|
|
|
|
|
|
|
|
tty_reset(tty);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_DCH, TTYC_DCH1, ua);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_insertline(struct tty *tty, unused struct screen *s, va_list ap)
|
|
|
|
{
|
|
|
|
u_int ua;
|
|
|
|
|
|
|
|
ua = va_arg(ap, u_int);
|
|
|
|
|
|
|
|
tty_reset(tty);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_IL, TTYC_IL1, ua);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_deleteline(struct tty *tty, unused struct screen *s, va_list ap)
|
|
|
|
{
|
|
|
|
u_int ua;
|
|
|
|
|
|
|
|
ua = va_arg(ap, u_int);
|
|
|
|
|
|
|
|
tty_reset(tty);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_DL, TTYC_DL1, ua);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_clearline(struct tty *tty, struct screen *s, unused va_list ap)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
tty_reset(tty);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
if (tty_term_has(tty->term, TTYC_EL)) {
|
|
|
|
tty_putcode2(tty, TTYC_CUP, s->cy, 0);
|
|
|
|
tty_putcode(tty, TTYC_EL);
|
|
|
|
tty_putcode2(tty, TTYC_CUP, s->cy, s->cx);
|
2008-09-25 20:08:57 +00:00
|
|
|
} else {
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode2(tty, TTYC_CUP, s->cy, 0);
|
2008-09-25 20:08:57 +00:00
|
|
|
for (i = 0; i < screen_size_x(s); i++)
|
|
|
|
tty_putc(tty, ' ');
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode2(tty, TTYC_CUP, s->cy, s->cx);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_clearendofline(struct tty *tty, struct screen *s, unused va_list ap)
|
|
|
|
{
|
|
|
|
u_int i;
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
tty_reset(tty);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
if (tty_term_has(tty->term, TTYC_EL))
|
|
|
|
tty_putcode(tty, TTYC_EL);
|
2009-01-10 01:51:22 +00:00
|
|
|
else {
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode2(tty, TTYC_CUP, s->cy, s->cx);
|
2008-09-25 20:08:57 +00:00
|
|
|
for (i = s->cx; i < screen_size_x(s); i++)
|
|
|
|
tty_putc(tty, ' ');
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode2(tty, TTYC_CUP, s->cy, s->cx);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_clearstartofline(struct tty *tty, struct screen *s, unused va_list ap)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
tty_reset(tty);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
if (tty_term_has(tty->term, TTYC_EL1))
|
|
|
|
tty_putcode(tty, TTYC_EL1);
|
2009-01-10 01:51:22 +00:00
|
|
|
else {
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode2(tty, TTYC_CUP, s->cy, 0);
|
2008-09-25 20:08:57 +00:00
|
|
|
for (i = 0; i < s->cx + 1; i++)
|
|
|
|
tty_putc(tty, ' ');
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode2(tty, TTYC_CUP, s->cy, s->cx);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_cursormove(struct tty *tty, unused struct screen *s, va_list ap)
|
|
|
|
{
|
|
|
|
u_int ua, ub;
|
|
|
|
|
|
|
|
ua = va_arg(ap, u_int);
|
|
|
|
ub = va_arg(ap, u_int);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode2(tty, TTYC_CUP, ub, ua);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_cursormode(struct tty *tty, unused struct screen *s, va_list ap)
|
|
|
|
{
|
|
|
|
u_int ua;
|
|
|
|
|
|
|
|
ua = va_arg(ap, int);
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
if (ua && !(tty->flags & TTY_NOCURSOR))
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode(tty, TTYC_CNORM);
|
2008-09-25 20:08:57 +00:00
|
|
|
else
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode(tty, TTYC_CIVIS);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_reverseindex(
|
|
|
|
struct tty *tty, unused struct screen *s, unused va_list ap)
|
|
|
|
{
|
|
|
|
tty_reset(tty);
|
2009-01-09 23:57:42 +00:00
|
|
|
|
|
|
|
tty_putcode(tty, TTYC_RI);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_scrollregion(struct tty *tty, unused struct screen *s, va_list ap)
|
|
|
|
{
|
|
|
|
u_int ua, ub;
|
|
|
|
|
|
|
|
ua = va_arg(ap, u_int);
|
|
|
|
ub = va_arg(ap, u_int);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode2(tty, TTYC_CSR, ua, ub);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_insertmode(unused struct tty *tty, unused struct screen *s, va_list ap)
|
|
|
|
{
|
|
|
|
u_int ua;
|
|
|
|
|
|
|
|
ua = va_arg(ap, int);
|
|
|
|
|
|
|
|
#if 0
|
2009-01-09 23:57:42 +00:00
|
|
|
/* XXX */
|
2008-09-25 20:08:57 +00:00
|
|
|
if (ua)
|
|
|
|
tty_puts(tty, enter_insert_mode);
|
|
|
|
else
|
|
|
|
tty_puts(tty, exit_insert_mode);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_mousemode(struct tty *tty, unused struct screen *s, va_list ap)
|
|
|
|
{
|
|
|
|
u_int ua;
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
if (!tty_term_has(tty->term, TTYC_KMOUS))
|
2008-09-25 20:08:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
ua = va_arg(ap, int);
|
|
|
|
|
|
|
|
if (ua)
|
|
|
|
tty_puts(tty, "\033[?1000h");
|
|
|
|
else
|
|
|
|
tty_puts(tty, "\033[?1000l");
|
|
|
|
}
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
void
|
|
|
|
tty_cmd_kcursormode(
|
|
|
|
unused struct tty *tty, unused struct screen *s, unused va_list ap)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_kkeypadmode(
|
|
|
|
unused struct tty *tty, unused struct screen *s, unused va_list ap)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
void
|
|
|
|
tty_cmd_linefeed(struct tty *tty, unused struct screen *s, unused va_list ap)
|
|
|
|
{
|
|
|
|
tty_reset(tty);
|
|
|
|
|
|
|
|
tty_putc(tty, '\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_carriagereturn(
|
|
|
|
struct tty *tty, unused struct screen *s, unused va_list ap)
|
|
|
|
{
|
|
|
|
tty_reset(tty);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
if (tty_term_has(tty->term, TTYC_CR))
|
|
|
|
tty_putcode(tty, TTYC_CR);
|
2008-09-25 20:08:57 +00:00
|
|
|
else
|
|
|
|
tty_putc(tty, '\r');
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_bell(struct tty *tty, unused struct screen *s, unused va_list ap)
|
|
|
|
{
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode(tty, TTYC_BEL);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_clearendofscreen(struct tty *tty, struct screen *s, unused va_list ap)
|
|
|
|
{
|
|
|
|
u_int i, j;
|
|
|
|
|
|
|
|
tty_reset(tty);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
if (tty_term_has(tty->term, TTYC_EL)) {
|
2008-09-25 20:08:57 +00:00
|
|
|
for (i = s->cy; i < screen_size_y(s); i++) {
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode(tty, TTYC_EL);
|
2008-09-26 07:23:21 +00:00
|
|
|
if (i != screen_size_y(s) - 1)
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1);
|
2007-12-06 09:46:23 +00:00
|
|
|
}
|
2008-09-25 20:08:57 +00:00
|
|
|
} else {
|
|
|
|
for (i = s->cx; i < screen_size_y(s); i++)
|
|
|
|
tty_putc(tty, ' ');
|
|
|
|
for (j = s->cy; j < screen_size_y(s); j++) {
|
|
|
|
for (i = 0; i < screen_size_x(s); i++)
|
2007-12-06 09:46:23 +00:00
|
|
|
tty_putc(tty, ' ');
|
|
|
|
}
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode2(tty, TTYC_CUP, s->cy, s->cx);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_clearstartofscreen(struct tty *tty, struct screen *s, unused va_list ap)
|
|
|
|
{
|
|
|
|
u_int i, j;
|
|
|
|
|
|
|
|
tty_reset(tty);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode2(tty, TTYC_CUP, 0, 0);
|
|
|
|
if (tty_term_has(tty->term, TTYC_EL)) {
|
|
|
|
for (i = 0; i < s->cy; i++) {
|
|
|
|
tty_putcode(tty, TTYC_EL);
|
|
|
|
tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1);
|
|
|
|
}
|
|
|
|
tty_putcode2(tty, TTYC_CUP, s->cy, 0);
|
2008-09-25 20:08:57 +00:00
|
|
|
} else {
|
|
|
|
for (j = 0; j < s->cy; j++) {
|
2007-12-06 09:46:23 +00:00
|
|
|
for (i = 0; i < screen_size_x(s); i++)
|
|
|
|
tty_putc(tty, ' ');
|
2008-09-26 06:45:28 +00:00
|
|
|
}
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < s->cx; i++)
|
|
|
|
tty_putc(tty, ' ');
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode2(tty, TTYC_CUP, s->cy, s->cx);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_cmd_clearscreen(struct tty *tty, struct screen *s, unused va_list ap)
|
|
|
|
{
|
|
|
|
u_int i, j;
|
|
|
|
|
|
|
|
tty_reset(tty);
|
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode2(tty, TTYC_CUP, 0, 0);
|
|
|
|
if (tty_term_has(tty->term, TTYC_EL)) {
|
2008-09-25 20:08:57 +00:00
|
|
|
for (i = 0; i < screen_size_y(s); i++) {
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode(tty, TTYC_EL);
|
2008-09-26 07:23:21 +00:00
|
|
|
if (i != screen_size_y(s) - 1)
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1);
|
2007-12-03 10:47:27 +00:00
|
|
|
}
|
2008-09-25 20:08:57 +00:00
|
|
|
} else {
|
|
|
|
for (j = 0; j < screen_size_y(s); j++) {
|
|
|
|
for (i = 0; i < screen_size_x(s); i++)
|
2007-12-03 10:47:27 +00:00
|
|
|
tty_putc(tty, ' ');
|
|
|
|
}
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode2(tty, TTYC_CUP, s->cy, s->cx);
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-09-25 20:08:57 +00:00
|
|
|
tty_cmd_cell(struct tty *tty, unused struct screen *s, va_list ap)
|
2007-11-27 19:23:34 +00:00
|
|
|
{
|
2008-09-25 20:08:57 +00:00
|
|
|
struct grid_cell *gc;
|
|
|
|
u_int i, width;
|
|
|
|
u_char out[4];
|
|
|
|
|
|
|
|
gc = va_arg(ap, struct grid_cell *);
|
|
|
|
|
|
|
|
/* If this is a padding character, do nothing. */
|
|
|
|
if (gc->flags & GRID_FLAG_PADDING)
|
2007-11-27 19:23:34 +00:00
|
|
|
return;
|
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
/* Handle special characters. Should never come into this function.*/
|
|
|
|
if (gc->data < 0x20 || gc->data == 0x7f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Set the attributes. */
|
|
|
|
tty_attributes(tty, gc);
|
|
|
|
|
|
|
|
/* If not UTF8 multibyte, write directly. */
|
2008-11-16 13:28:59 +00:00
|
|
|
if (gc->data <= 0xff) {
|
2008-09-25 20:08:57 +00:00
|
|
|
tty_putc(tty, gc->data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the terminal doesn't support UTF8, write _s. */
|
|
|
|
if (!(tty->flags & TTY_UTF8)) {
|
|
|
|
width = utf8_width(gc->data);
|
|
|
|
while (width-- > 0)
|
|
|
|
tty_putc(tty, '_');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unpack UTF-8 and write it. */
|
|
|
|
utf8_split(gc->data, out);
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (out[i] == 0xff)
|
|
|
|
break;
|
|
|
|
tty_putc(tty, out[i]);
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_reset(struct tty *tty)
|
|
|
|
{
|
|
|
|
struct grid_cell *tc = &tty->cell;
|
|
|
|
|
|
|
|
tc->data = grid_default_cell.data;
|
|
|
|
if (memcmp(tc, &grid_default_cell, sizeof *tc) == 0)
|
|
|
|
return;
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2009-01-09 23:57:42 +00:00
|
|
|
if (tty_term_has(tty->term, TTYC_RMACS) && tc->attr & GRID_ATTR_CHARSET)
|
|
|
|
tty_putcode(tty, TTYC_RMACS);
|
|
|
|
tty_putcode(tty, TTYC_SGR0);
|
2008-09-25 20:08:57 +00:00
|
|
|
memcpy(tc, &grid_default_cell, sizeof *tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_attributes(struct tty *tty, const struct grid_cell *gc)
|
|
|
|
{
|
|
|
|
struct grid_cell *tc = &tty->cell;
|
|
|
|
u_char changed;
|
|
|
|
|
|
|
|
/* If any bits are being cleared, reset everything. */
|
|
|
|
if (tc->attr & ~gc->attr)
|
|
|
|
tty_reset(tty);
|
2007-11-27 19:23:34 +00:00
|
|
|
|
2008-09-08 22:03:56 +00:00
|
|
|
/* Filter out attribute bits already set. */
|
2008-09-25 20:08:57 +00:00
|
|
|
changed = gc->attr & ~tc->attr;
|
|
|
|
tc->attr = gc->attr;
|
2007-11-27 19:23:34 +00:00
|
|
|
|
2008-09-08 22:03:56 +00:00
|
|
|
/* Set the attributes. */
|
2009-01-09 23:57:42 +00:00
|
|
|
if (changed & GRID_ATTR_BRIGHT)
|
|
|
|
tty_putcode(tty, TTYC_BOLD);
|
|
|
|
if (changed & GRID_ATTR_DIM)
|
|
|
|
tty_putcode(tty, TTYC_DIM);
|
|
|
|
if (changed & GRID_ATTR_ITALICS)
|
|
|
|
tty_putcode(tty, TTYC_SMSO);
|
|
|
|
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)
|
|
|
|
tty_putcode(tty, TTYC_REV);
|
|
|
|
if (changed & GRID_ATTR_HIDDEN)
|
|
|
|
tty_putcode(tty, TTYC_INVIS);
|
|
|
|
if (changed & GRID_ATTR_CHARSET)
|
|
|
|
tty_putcode(tty, TTYC_SMACS);
|
2007-11-27 19:23:34 +00:00
|
|
|
|
2008-09-08 22:03:56 +00:00
|
|
|
/* Set foreground colour. */
|
2008-09-25 20:08:57 +00:00
|
|
|
if (gc->fg != tc->fg ||
|
|
|
|
(gc->flags & GRID_FLAG_FG256) != (tc->flags & GRID_FLAG_FG256)) {
|
|
|
|
tty_attributes_fg(tty, gc);
|
|
|
|
tc->fg = gc->fg;
|
|
|
|
}
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2008-09-08 22:03:56 +00:00
|
|
|
/* Set background colour. */
|
2008-09-26 06:45:28 +00:00
|
|
|
if (gc->bg != tc->bg ||
|
2008-09-25 20:08:57 +00:00
|
|
|
(gc->flags & GRID_FLAG_BG256) != (tc->flags & GRID_FLAG_BG256)) {
|
|
|
|
tty_attributes_bg(tty, gc);
|
|
|
|
tc->bg = gc->bg;
|
|
|
|
}
|
2008-09-08 22:03:56 +00:00
|
|
|
}
|
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
void
|
|
|
|
tty_attributes_fg(struct tty *tty, const struct grid_cell *gc)
|
2008-09-08 22:03:56 +00:00
|
|
|
{
|
|
|
|
char s[32];
|
2008-09-25 20:08:57 +00:00
|
|
|
u_char fg = gc->fg;
|
2008-09-08 22:03:56 +00:00
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
if (gc->flags & GRID_FLAG_FG256) {
|
|
|
|
if ((tty->term->flags & TERM_256COLOURS) ||
|
|
|
|
(tty->term_flags & TERM_256COLOURS)) {
|
2008-09-08 17:40:51 +00:00
|
|
|
xsnprintf(s, sizeof s, "\033[38;5;%hhum", fg);
|
|
|
|
tty_puts(tty, s);
|
2008-09-25 20:08:57 +00:00
|
|
|
return;
|
2008-09-08 17:40:51 +00:00
|
|
|
}
|
2008-10-09 22:00:33 +00:00
|
|
|
fg = colour_translate256(fg);
|
|
|
|
if (fg & 8) {
|
|
|
|
fg &= 7;
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode(tty, TTYC_BOLD);
|
2008-10-09 22:00:33 +00:00
|
|
|
tty->cell.attr |= GRID_ATTR_BRIGHT;
|
|
|
|
} else if (tty->cell.attr & GRID_ATTR_BRIGHT)
|
|
|
|
tty_reset(tty);
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
if (fg == 8 &&
|
|
|
|
!(tty->term->flags & TERM_HASDEFAULTS) &&
|
|
|
|
!(tty->term_flags & TERM_HASDEFAULTS))
|
2008-09-08 22:03:56 +00:00
|
|
|
fg = 7;
|
|
|
|
if (fg == 8)
|
|
|
|
tty_puts(tty, "\033[39m");
|
2009-01-09 23:57:42 +00:00
|
|
|
else
|
|
|
|
tty_putcode1(tty, TTYC_SETAF, fg);
|
2008-09-08 22:03:56 +00:00
|
|
|
}
|
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
void
|
|
|
|
tty_attributes_bg(struct tty *tty, const struct grid_cell *gc)
|
2008-09-08 22:03:56 +00:00
|
|
|
{
|
|
|
|
char s[32];
|
2008-09-25 20:08:57 +00:00
|
|
|
u_char bg = gc->bg;
|
2007-12-06 09:46:23 +00:00
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
if (gc->flags & GRID_FLAG_BG256) {
|
|
|
|
if ((tty->term->flags & TERM_256COLOURS) ||
|
|
|
|
(tty->term_flags & TERM_256COLOURS)) {
|
2008-09-08 17:40:51 +00:00
|
|
|
xsnprintf(s, sizeof s, "\033[48;5;%hhum", bg);
|
|
|
|
tty_puts(tty, s);
|
2008-09-25 20:08:57 +00:00
|
|
|
return;
|
2008-09-08 17:40:51 +00:00
|
|
|
}
|
2008-10-09 22:00:33 +00:00
|
|
|
bg = colour_translate256(bg);
|
|
|
|
if (bg & 8) {
|
|
|
|
/*
|
2008-10-09 22:03:36 +00:00
|
|
|
* Bold background; can't do this on standard
|
|
|
|
* terminals...
|
2008-10-09 22:00:33 +00:00
|
|
|
*/
|
2008-10-09 22:03:36 +00:00
|
|
|
#if 0
|
2008-10-09 22:00:33 +00:00
|
|
|
xsnprintf(s, sizeof s, "\033[%hhum", 92 + bg);
|
|
|
|
tty_puts(tty, s);
|
2009-01-10 01:51:22 +00:00
|
|
|
return;
|
|
|
|
#endif
|
2008-10-09 22:03:36 +00:00
|
|
|
bg &= 7;
|
2008-10-09 22:00:33 +00:00
|
|
|
}
|
2008-09-08 22:03:56 +00:00
|
|
|
}
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
if (bg == 8 &&
|
|
|
|
!(tty->term->flags & TERM_HASDEFAULTS) &&
|
|
|
|
!(tty->term_flags & TERM_HASDEFAULTS))
|
2008-09-08 22:03:56 +00:00
|
|
|
bg = 0;
|
|
|
|
if (bg == 8)
|
|
|
|
tty_puts(tty, "\033[49m");
|
2009-01-10 01:51:22 +00:00
|
|
|
else
|
2009-01-09 23:57:42 +00:00
|
|
|
tty_putcode1(tty, TTYC_SETAB, bg);
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|