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];
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);
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. */
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);