summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/shared/ptyfwd.c13
-rw-r--r--src/shared/ptyfwd.h10
2 files changed, 19 insertions, 4 deletions
diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c
index f6082580a3..654e719180 100644
--- a/src/shared/ptyfwd.c
+++ b/src/shared/ptyfwd.c
@@ -389,6 +389,9 @@ static int pty_forward_ansi_process(PTYForward *f, size_t offset) {
if (!f->background_color)
return 0;
+ if (FLAGS_SET(f->flags, PTY_FORWARD_DUMB_TERMINAL))
+ return 0;
+
for (size_t i = offset; i < f->out_buffer_full; i++) {
char c = f->out_buffer[i];
@@ -484,7 +487,11 @@ static int do_shovel(PTYForward *f) {
assert(f);
- if (f->out_buffer_size == 0) {
+ if (f->out_buffer_size == 0 && !FLAGS_SET(f->flags, PTY_FORWARD_DUMB_TERMINAL)) {
+ /* If the output hasn't been allocated yet, we are at the beginning of the first
+ * shovelling. Hence, possibly send some initial ANSI sequences. But do so only if we are
+ * talking to an actual TTY. */
+
if (f->background_color) {
/* Erase the first line when we start */
f->out_buffer = background_color_sequence(f);
@@ -792,6 +799,10 @@ int pty_forward_new(
f->master = master;
+ /* Disable color/window title setting unless we talk to a good TTY */
+ if (!isatty_safe(f->output_fd) || get_color_mode() == COLOR_OFF)
+ f->flags |= PTY_FORWARD_DUMB_TERMINAL;
+
if (ioctl(f->output_fd, TIOCGWINSZ, &ws) < 0)
/* If we can't get the resolution from the output fd, then use our internal, regular width/height,
* i.e. something derived from $COLUMNS and $LINES if set. */
diff --git a/src/shared/ptyfwd.h b/src/shared/ptyfwd.h
index 3f0d7811a2..f87becd030 100644
--- a/src/shared/ptyfwd.h
+++ b/src/shared/ptyfwd.h
@@ -10,13 +10,17 @@
typedef struct PTYForward PTYForward;
typedef enum PTYForwardFlags {
- PTY_FORWARD_READ_ONLY = 1,
+ /* Only output to STDOUT, never try to read from STDIN */
+ PTY_FORWARD_READ_ONLY = 1 << 0,
/* Continue reading after hangup? */
- PTY_FORWARD_IGNORE_VHANGUP = 2,
+ PTY_FORWARD_IGNORE_VHANGUP = 1 << 1,
/* Continue reading after hangup but only if we never read anything else? */
- PTY_FORWARD_IGNORE_INITIAL_VHANGUP = 4,
+ PTY_FORWARD_IGNORE_INITIAL_VHANGUP = 1 << 2,
+
+ /* Don't tint the background, or set window title */
+ PTY_FORWARD_DUMB_TERMINAL = 1 << 3,
} PTYForwardFlags;
typedef int (*PTYForwardHandler)(PTYForward *f, int rcode, void *userdata);