mirror of
				https://github.com/tmux/tmux.git
				synced 2025-10-26 12:27:15 +00:00 
			
		
		
		
	Add a helper function to get the terminal flags.
This commit is contained in:
		
							
								
								
									
										1
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								tmux.h
									
									
									
									
									
								
							| @@ -1957,6 +1957,7 @@ int	tty_open(struct tty *, char **); | |||||||
| void	tty_close(struct tty *); | void	tty_close(struct tty *); | ||||||
| void	tty_free(struct tty *); | void	tty_free(struct tty *); | ||||||
| void	tty_set_flags(struct tty *, int); | void	tty_set_flags(struct tty *, int); | ||||||
|  | int	tty_get_flags(struct tty *); | ||||||
| void	tty_write(void (*)(struct tty *, const struct tty_ctx *), | void	tty_write(void (*)(struct tty *, const struct tty_ctx *), | ||||||
| 	    struct tty_ctx *); | 	    struct tty_ctx *); | ||||||
| void	tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *); | void	tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *); | ||||||
|   | |||||||
							
								
								
									
										44
									
								
								tty.c
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								tty.c
									
									
									
									
									
								
							| @@ -74,7 +74,7 @@ static void	tty_default_attributes(struct tty *, struct window_pane *, | |||||||
| 		    u_int); | 		    u_int); | ||||||
|  |  | ||||||
| #define tty_use_margin(tty) \ | #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) \ | #define tty_pane_full_width(tty, ctx) \ | ||||||
| 	((ctx)->xoff == 0 && screen_size_x((ctx)->wp->screen) >= (tty)->sx) | 	((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 */ | 		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 | void | ||||||
| tty_raw(struct tty *tty, const char *s) | tty_raw(struct tty *tty, const char *s) | ||||||
| { | { | ||||||
| @@ -575,7 +583,7 @@ tty_putc(struct tty *tty, u_char ch) | |||||||
| { | { | ||||||
| 	const char	*acs; | 	const char	*acs; | ||||||
|  |  | ||||||
| 	if ((tty->term->flags & TERM_NOXENL) && | 	if ((tty_get_flags(tty) & TERM_NOXENL) && | ||||||
| 	    ch >= 0x20 && ch != 0x7f && | 	    ch >= 0x20 && ch != 0x7f && | ||||||
| 	    tty->cy == tty->sy - 1 && | 	    tty->cy == tty->sy - 1 && | ||||||
| 	    tty->cx + 1 >= tty->sx) | 	    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 | 			 * where we think it should be after a line wrap - this | ||||||
| 			 * means it works on sensible terminals as well. | 			 * 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); | 				tty_putcode2(tty, TTYC_CUP, tty->cy, tty->cx); | ||||||
| 		} else | 		} else | ||||||
| 			tty->cx++; | 			tty->cx++; | ||||||
| @@ -611,7 +619,7 @@ tty_putc(struct tty *tty, u_char ch) | |||||||
| void | void | ||||||
| tty_putn(struct tty *tty, const void *buf, size_t len, u_int width) | 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->cy == tty->sy - 1 && | ||||||
| 	    tty->cx + len >= tty->sx) | 	    tty->cx + len >= tty->sx) | ||||||
| 		len = tty->sx - tty->cx - 1; | 		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 | 		 * background colour isn't default (because it doesn't work | ||||||
| 		 * after SGR 0). | 		 * after SGR 0). | ||||||
| 		 */ | 		 */ | ||||||
| 		if (((tty->term->flags|tty->term_flags) & TERM_DECFRA) && | 		if ((tty_get_flags(tty) & TERM_DECFRA) && | ||||||
| 		    !COLOUR_DEFAULT(bg)) { | 		    !COLOUR_DEFAULT(bg)) { | ||||||
| 			xsnprintf(tmp, sizeof tmp, "\033[32;%u;%u;%u;%u$x", | 			xsnprintf(tmp, sizeof tmp, "\033[32;%u;%u;%u;%u$x", | ||||||
| 			    py + 1, px + 1, py + ny, px + nx); | 			    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 | void | ||||||
| tty_sync_start(struct tty *tty) | 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\\"); | 		tty_puts(tty, "\033P=1s\033\\"); | ||||||
| } | } | ||||||
|  |  | ||||||
| void | void | ||||||
| tty_sync_end(struct tty *tty) | 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\\"); | 		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)) { | 	    ctx->xoff + ctx->ocx + ctx->num > ctx->ox + ctx->sx)) { | ||||||
| 		if (!ctx->wrapped || | 		if (!ctx->wrapped || | ||||||
| 		    !tty_pane_full_width(tty, ctx) || | 		    !tty_pane_full_width(tty, ctx) || | ||||||
| 		    (tty->term->flags & TERM_NOXENL) || | 		    (tty_get_flags(tty) & TERM_NOXENL) || | ||||||
| 		    ctx->xoff + ctx->ocx != 0 || | 		    ctx->xoff + ctx->ocx != 0 || | ||||||
| 		    ctx->yoff + ctx->ocy != tty->cy + 1 || | 		    ctx->yoff + ctx->ocy != tty->cy + 1 || | ||||||
| 		    tty->cx < tty->sx || | 		    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; | 	const struct grid_cell	*gcp; | ||||||
|  |  | ||||||
| 	/* Skip last character if terminal is stupid. */ | 	/* 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->cy == tty->sy - 1 && | ||||||
| 	    tty->cx == tty->sx - 1) | 	    tty->cx == tty->sx - 1) | ||||||
| 		return; | 		return; | ||||||
| @@ -2110,7 +2118,7 @@ tty_cursor_pane_unless_wrap(struct tty *tty, const struct tty_ctx *ctx, | |||||||
| { | { | ||||||
| 	if (!ctx->wrapped || | 	if (!ctx->wrapped || | ||||||
| 	    !tty_pane_full_width(tty, ctx) || | 	    !tty_pane_full_width(tty, ctx) || | ||||||
| 	    (tty->term->flags & TERM_NOXENL) || | 	    (tty_get_flags(tty) & TERM_NOXENL) || | ||||||
| 	    ctx->xoff + cx != 0 || | 	    ctx->xoff + cx != 0 || | ||||||
| 	    ctx->yoff + cy != tty->cy + 1 || | 	    ctx->yoff + cy != tty->cy + 1 || | ||||||
| 	    tty->cx < tty->sx || | 	    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? */ | 	/* Is this a 24-bit colour? */ | ||||||
| 	if (gc->fg & COLOUR_FLAG_RGB) { | 	if (gc->fg & COLOUR_FLAG_RGB) { | ||||||
| 		/* Not a 24-bit terminal? Translate to 256-colour palette. */ | 		/* 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; | 			return; | ||||||
| 		colour_split_rgb(gc->fg, &r, &g, &b); | 		colour_split_rgb(gc->fg, &r, &g, &b); | ||||||
| 		gc->fg = colour_find_rgb(r, g, b); | 		gc->fg = colour_find_rgb(r, g, b); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/* How many colours does this terminal have? */ | 	/* 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; | 		colours = 256; | ||||||
| 	else | 	else | ||||||
| 		colours = tty_term_number(tty->term, TTYC_COLORS); | 		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? */ | 	/* Is this a 24-bit colour? */ | ||||||
| 	if (gc->bg & COLOUR_FLAG_RGB) { | 	if (gc->bg & COLOUR_FLAG_RGB) { | ||||||
| 		/* Not a 24-bit terminal? Translate to 256-colour palette. */ | 		/* 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; | 			return; | ||||||
| 		colour_split_rgb(gc->bg, &r, &g, &b); | 		colour_split_rgb(gc->bg, &r, &g, &b); | ||||||
| 		gc->bg = colour_find_rgb(r, g, b); | 		gc->bg = colour_find_rgb(r, g, b); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/* How many colours does this terminal have? */ | 	/* 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; | 		colours = 256; | ||||||
| 	else | 	else | ||||||
| 		colours = tty_term_number(tty->term, TTYC_COLORS); | 		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? */ | 	/* Is this an aixterm bright colour? */ | ||||||
| 	if (gc->fg >= 90 && gc->fg <= 97) { | 	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); | 			xsnprintf(s, sizeof s, "\033[%dm", gc->fg); | ||||||
| 			tty_puts(tty, s); | 			tty_puts(tty, s); | ||||||
| 		} else | 		} else | ||||||
| @@ -2596,7 +2604,7 @@ tty_colours_bg(struct tty *tty, const struct grid_cell *gc) | |||||||
|  |  | ||||||
| 	/* Is this an aixterm bright colour? */ | 	/* Is this an aixterm bright colour? */ | ||||||
| 	if (gc->bg >= 90 && gc->bg <= 97) { | 	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); | 			xsnprintf(s, sizeof s, "\033[%dm", gc->bg + 10); | ||||||
| 			tty_puts(tty, s); | 			tty_puts(tty, s); | ||||||
| 		} else | 		} 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 | 		 * Also if RGB is set, setaf and setab do not support the 256 | ||||||
| 		 * colour palette so use the sequences directly there too. | 		 * 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)) | 		    tty_term_has(tty->term, TTYC_RGB)) | ||||||
| 			goto fallback_256; | 			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 | 		 * If the terminfo entry has 256 colours and setaf and setab | ||||||
| 		 * exist, assume that they work correctly. | 		 * exist, assume that they work correctly. | ||||||
| 		 */ | 		 */ | ||||||
| 		if (tty->term->flags & TERM_256COLOURS) { | 		if (tty_get_flags(tty) & TERM_256COLOURS) { | ||||||
| 			if (*type == '3') { | 			if (*type == '3') { | ||||||
| 				if (!tty_term_has(tty->term, TTYC_SETAF)) | 				if (!tty_term_has(tty->term, TTYC_SETAF)) | ||||||
| 					goto fallback_256; | 					goto fallback_256; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 nicm
					nicm