Add a helper function to get the terminal flags.

pull/2172/head
nicm 2020-04-16 14:03:51 +00:00
parent b2443aa2f9
commit 4744aa43af
2 changed files with 27 additions and 18 deletions

1
tmux.h
View File

@ -1957,6 +1957,7 @@ int tty_open(struct tty *, char **);
void tty_close(struct tty *);
void tty_free(struct tty *);
void tty_set_flags(struct tty *, int);
int tty_get_flags(struct tty *);
void tty_write(void (*)(struct tty *, const struct tty_ctx *),
struct tty_ctx *);
void tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *);

44
tty.c
View File

@ -74,7 +74,7 @@ static void tty_default_attributes(struct tty *, struct window_pane *,
u_int);
#define tty_use_margin(tty) \
((tty->term->flags|tty->term_flags) & TERM_DECSLRM)
(tty_get_flags(tty) & TERM_DECSLRM)
#define tty_pane_full_width(tty, ctx) \
((ctx)->xoff == 0 && screen_size_x((ctx)->wp->screen) >= (tty)->sx)
@ -478,6 +478,14 @@ tty_set_flags(struct tty *tty, int flags)
tty_puts(tty, "\033[?69h"); /* DECLRMM */
}
int
tty_get_flags(struct tty *tty)
{
if (tty->term != NULL)
return (tty->term->flags|tty->term_flags);
return (tty->term_flags);
}
void
tty_raw(struct tty *tty, const char *s)
{
@ -575,7 +583,7 @@ tty_putc(struct tty *tty, u_char ch)
{
const char *acs;
if ((tty->term->flags & TERM_NOXENL) &&
if ((tty_get_flags(tty) & TERM_NOXENL) &&
ch >= 0x20 && ch != 0x7f &&
tty->cy == tty->sy - 1 &&
tty->cx + 1 >= tty->sx)
@ -601,7 +609,7 @@ tty_putc(struct tty *tty, u_char ch)
* where we think it should be after a line wrap - this
* means it works on sensible terminals as well.
*/
if (tty->term->flags & TERM_NOXENL)
if (tty_get_flags(tty) & TERM_NOXENL)
tty_putcode2(tty, TTYC_CUP, tty->cy, tty->cx);
} else
tty->cx++;
@ -611,7 +619,7 @@ tty_putc(struct tty *tty, u_char ch)
void
tty_putn(struct tty *tty, const void *buf, size_t len, u_int width)
{
if ((tty->term->flags & TERM_NOXENL) &&
if ((tty_get_flags(tty) & TERM_NOXENL) &&
tty->cy == tty->sy - 1 &&
tty->cx + len >= tty->sx)
len = tty->sx - tty->cx - 1;
@ -1167,7 +1175,7 @@ tty_clear_area(struct tty *tty, struct window_pane *wp, u_int py, u_int ny,
* background colour isn't default (because it doesn't work
* after SGR 0).
*/
if (((tty->term->flags|tty->term_flags) & TERM_DECFRA) &&
if ((tty_get_flags(tty) & TERM_DECFRA) &&
!COLOUR_DEFAULT(bg)) {
xsnprintf(tmp, sizeof tmp, "\033[32;%u;%u;%u;%u$x",
py + 1, px + 1, py + ny, px + nx);
@ -1429,14 +1437,14 @@ tty_draw_line(struct tty *tty, struct window_pane *wp, struct screen *s,
void
tty_sync_start(struct tty *tty)
{
if ((tty->term->flags|tty->term_flags) & TERM_SYNC)
if (tty_get_flags(tty) & TERM_SYNC)
tty_puts(tty, "\033P=1s\033\\");
}
void
tty_sync_end(struct tty *tty)
{
if ((tty->term->flags|tty->term_flags) & TERM_SYNC)
if (tty_get_flags(tty) & TERM_SYNC)
tty_puts(tty, "\033P=2s\033\\");
}
@ -1890,7 +1898,7 @@ tty_cmd_cells(struct tty *tty, const struct tty_ctx *ctx)
ctx->xoff + ctx->ocx + ctx->num > ctx->ox + ctx->sx)) {
if (!ctx->wrapped ||
!tty_pane_full_width(tty, ctx) ||
(tty->term->flags & TERM_NOXENL) ||
(tty_get_flags(tty) & TERM_NOXENL) ||
ctx->xoff + ctx->ocx != 0 ||
ctx->yoff + ctx->ocy != tty->cy + 1 ||
tty->cx < tty->sx ||
@ -1951,7 +1959,7 @@ tty_cell(struct tty *tty, const struct grid_cell *gc, struct window_pane *wp)
const struct grid_cell *gcp;
/* Skip last character if terminal is stupid. */
if ((tty->term->flags & TERM_NOXENL) &&
if ((tty_get_flags(tty) & TERM_NOXENL) &&
tty->cy == tty->sy - 1 &&
tty->cx == tty->sx - 1)
return;
@ -2110,7 +2118,7 @@ tty_cursor_pane_unless_wrap(struct tty *tty, const struct tty_ctx *ctx,
{
if (!ctx->wrapped ||
!tty_pane_full_width(tty, ctx) ||
(tty->term->flags & TERM_NOXENL) ||
(tty_get_flags(tty) & TERM_NOXENL) ||
ctx->xoff + cx != 0 ||
ctx->yoff + cy != tty->cy + 1 ||
tty->cx < tty->sx ||
@ -2447,14 +2455,14 @@ tty_check_fg(struct tty *tty, struct window_pane *wp, struct grid_cell *gc)
/* Is this a 24-bit colour? */
if (gc->fg & COLOUR_FLAG_RGB) {
/* Not a 24-bit terminal? Translate to 256-colour palette. */
if ((tty->term->flags|tty->term_flags) & TERM_RGBCOLOURS)
if (tty_get_flags(tty) & TERM_RGBCOLOURS)
return;
colour_split_rgb(gc->fg, &r, &g, &b);
gc->fg = colour_find_rgb(r, g, b);
}
/* How many colours does this terminal have? */
if ((tty->term->flags|tty->term_flags) & TERM_256COLOURS)
if (tty_get_flags(tty) & TERM_256COLOURS)
colours = 256;
else
colours = tty_term_number(tty->term, TTYC_COLORS);
@ -2496,14 +2504,14 @@ tty_check_bg(struct tty *tty, struct window_pane *wp, struct grid_cell *gc)
/* Is this a 24-bit colour? */
if (gc->bg & COLOUR_FLAG_RGB) {
/* Not a 24-bit terminal? Translate to 256-colour palette. */
if ((tty->term->flags|tty->term_flags) & TERM_RGBCOLOURS)
if (tty_get_flags(tty) & TERM_RGBCOLOURS)
return;
colour_split_rgb(gc->bg, &r, &g, &b);
gc->bg = colour_find_rgb(r, g, b);
}
/* How many colours does this terminal have? */
if ((tty->term->flags|tty->term_flags) & TERM_256COLOURS)
if (tty_get_flags(tty) & TERM_256COLOURS)
colours = 256;
else
colours = tty_term_number(tty->term, TTYC_COLORS);
@ -2564,7 +2572,7 @@ tty_colours_fg(struct tty *tty, const struct grid_cell *gc)
/* Is this an aixterm bright colour? */
if (gc->fg >= 90 && gc->fg <= 97) {
if (tty->term_flags & TERM_256COLOURS) {
if (tty_get_flags(tty) & TERM_256COLOURS) {
xsnprintf(s, sizeof s, "\033[%dm", gc->fg);
tty_puts(tty, s);
} else
@ -2596,7 +2604,7 @@ tty_colours_bg(struct tty *tty, const struct grid_cell *gc)
/* Is this an aixterm bright colour? */
if (gc->bg >= 90 && gc->bg <= 97) {
if (tty->term_flags & TERM_256COLOURS) {
if (tty_get_flags(tty) & TERM_256COLOURS) {
xsnprintf(s, sizeof s, "\033[%dm", gc->bg + 10);
tty_puts(tty, s);
} else
@ -2652,7 +2660,7 @@ tty_try_colour(struct tty *tty, int colour, const char *type)
* Also if RGB is set, setaf and setab do not support the 256
* colour palette so use the sequences directly there too.
*/
if ((tty->term_flags & TERM_256COLOURS) ||
if ((tty_get_flags(tty) & TERM_256COLOURS) ||
tty_term_has(tty->term, TTYC_RGB))
goto fallback_256;
@ -2660,7 +2668,7 @@ tty_try_colour(struct tty *tty, int colour, const char *type)
* If the terminfo entry has 256 colours and setaf and setab
* exist, assume that they work correctly.
*/
if (tty->term->flags & TERM_256COLOURS) {
if (tty_get_flags(tty) & TERM_256COLOURS) {
if (*type == '3') {
if (!tty_term_has(tty->term, TTYC_SETAF))
goto fallback_256;