From 135583c073954887b83eaa45617fe99826882d1b Mon Sep 17 00:00:00 2001 From: Ryan Gambord Date: Thu, 18 Aug 2022 12:57:11 -0700 Subject: [PATCH] Added silent reconnect feature --- abduco.1 | 3 +++ abduco.c | 6 +++++- client.c | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/abduco.1 b/abduco.1 index c122308..5006e8f 100644 --- a/abduco.1 +++ b/abduco.1 @@ -115,6 +115,9 @@ options. Be quiet, do not print informative messages. .It Fl r Read-only session, user input is ignored. +.IT F1 s +Silently Attach/Detach without switching to/from alternate buffer. Useful for automatically reconnecting +persistent SSH connections that don't want to alter terminal state when reconnecting. .It Fl v Print version information and exit. .El diff --git a/abduco.c b/abduco.c index b56e6f4..fc790cb 100644 --- a/abduco.c +++ b/abduco.c @@ -98,6 +98,7 @@ struct Client { enum { CLIENT_READONLY = 1 << 0, CLIENT_LOWPRIORITY = 1 << 1, + CLIENT_NOALTBUF = 1 << 1, } flags; Client *next; }; @@ -223,7 +224,7 @@ static void die(const char *s) { } static void usage(void) { - fprintf(stderr, "usage: abduco [-a|-A|-c|-n] [-p] [-r] [-q] [-l] [-f] [-e detachkey] name command\n"); + fprintf(stderr, "usage: abduco [-a|-A|-c|-n] [-p] [-r] [-q] [-l] [-f] [-s] [-e detachkey] name command\n"); exit(EXIT_FAILURE); } @@ -633,6 +634,9 @@ int main(int argc, char *argv[]) { case 'r': client.flags |= CLIENT_READONLY; break; + case 's': + client.flags |= CLIENT_NOALTBUF; + break; case 'l': client.flags |= CLIENT_LOWPRIORITY; break; diff --git a/client.c b/client.c index 3d6d82b..56cc2b4 100644 --- a/client.c +++ b/client.c @@ -25,7 +25,7 @@ static void client_restore_terminal(void) { if (!has_term) return; tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_term); - if (alternate_buffer) { + if (!(client.flags & CLIENT_NOALTBUF) && alternate_buffer) { printf("\033[?25h\033[?1049l"); fflush(stdout); alternate_buffer = false; @@ -48,7 +48,7 @@ static void client_setup_terminal(void) { cur_term.c_cc[VTIME] = 0; tcsetattr(STDIN_FILENO, TCSANOW, &cur_term); - if (!alternate_buffer) { + if (!(client.flags & CLIENT_NOALTBUF) && !alternate_buffer) { printf("\033[?1049h\033[H"); fflush(stdout); alternate_buffer = true;