mirror of https://github.com/martanne/abduco
Improve terminal restoring
Instead of simply moving the cursor to the bottom of the screen
use the alternate screen buffer i.e. the smcup/rmcup capabilities.
This is currently hardcoded to the xterm originated \e[?1047{h,l}
sequence. I also patched dvtm to support these.
This commit is contained in:
parent
16d76139db
commit
76bae5939f
16
abduco.c
16
abduco.c
|
|
@ -113,7 +113,7 @@ typedef struct {
|
||||||
static Server server = { .running = true, .exit_status = -1, .host = "@localhost" };
|
static Server server = { .running = true, .exit_status = -1, .host = "@localhost" };
|
||||||
static Client client;
|
static Client client;
|
||||||
static struct termios orig_term, cur_term;
|
static struct termios orig_term, cur_term;
|
||||||
bool has_term;
|
static bool has_term, alternate_buffer;
|
||||||
|
|
||||||
static struct sockaddr_un sockaddr = {
|
static struct sockaddr_un sockaddr = {
|
||||||
.sun_family = AF_UNIX,
|
.sun_family = AF_UNIX,
|
||||||
|
|
@ -194,7 +194,6 @@ static bool recv_packet(int socket, Packet *pkt) {
|
||||||
static void info(const char *str, ...) {
|
static void info(const char *str, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, str);
|
va_start(ap, str);
|
||||||
fprintf(stderr, "\033[999H");
|
|
||||||
if (str) {
|
if (str) {
|
||||||
fprintf(stderr, "%s: %s: ", server.name, server.session_name);
|
fprintf(stderr, "%s: %s: ", server.name, server.session_name);
|
||||||
vfprintf(stderr, str, ap);
|
vfprintf(stderr, str, ap);
|
||||||
|
|
@ -409,19 +408,8 @@ static bool attach_session(const char *name, const bool terminate) {
|
||||||
sigaction(SIGWINCH, &sa, NULL);
|
sigaction(SIGWINCH, &sa, NULL);
|
||||||
sa.sa_handler = SIG_IGN;
|
sa.sa_handler = SIG_IGN;
|
||||||
sigaction(SIGPIPE, &sa, NULL);
|
sigaction(SIGPIPE, &sa, NULL);
|
||||||
atexit(client_restore_terminal);
|
|
||||||
|
|
||||||
cur_term = orig_term;
|
|
||||||
cur_term.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF);
|
|
||||||
cur_term.c_oflag &= ~(OPOST);
|
|
||||||
cur_term.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
|
|
||||||
cur_term.c_cflag &= ~(CSIZE|PARENB);
|
|
||||||
cur_term.c_cflag |= CS8;
|
|
||||||
cur_term.c_cc[VLNEXT] = _POSIX_VDISABLE;
|
|
||||||
cur_term.c_cc[VMIN] = 1;
|
|
||||||
cur_term.c_cc[VTIME] = 0;
|
|
||||||
tcsetattr(STDIN_FILENO, TCSADRAIN, &cur_term);
|
|
||||||
|
|
||||||
|
client_setup_terminal();
|
||||||
int status = client_mainloop();
|
int status = client_mainloop();
|
||||||
client_restore_terminal();
|
client_restore_terminal();
|
||||||
if (status == -1) {
|
if (status == -1) {
|
||||||
|
|
|
||||||
32
client.c
32
client.c
|
|
@ -21,15 +21,35 @@ static bool client_recv_packet(Packet *pkt) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void client_show_cursor(void) {
|
|
||||||
printf("\033[?25h");
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void client_restore_terminal(void) {
|
static void client_restore_terminal(void) {
|
||||||
if (has_term)
|
if (has_term)
|
||||||
tcsetattr(STDIN_FILENO, TCSADRAIN, &orig_term);
|
tcsetattr(STDIN_FILENO, TCSADRAIN, &orig_term);
|
||||||
client_show_cursor();
|
if (alternate_buffer) {
|
||||||
|
printf("\033[?1049l");
|
||||||
|
fflush(stdout);
|
||||||
|
alternate_buffer = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void client_setup_terminal(void) {
|
||||||
|
atexit(client_restore_terminal);
|
||||||
|
|
||||||
|
cur_term = orig_term;
|
||||||
|
cur_term.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF);
|
||||||
|
cur_term.c_oflag &= ~(OPOST);
|
||||||
|
cur_term.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
|
||||||
|
cur_term.c_cflag &= ~(CSIZE|PARENB);
|
||||||
|
cur_term.c_cflag |= CS8;
|
||||||
|
cur_term.c_cc[VLNEXT] = _POSIX_VDISABLE;
|
||||||
|
cur_term.c_cc[VMIN] = 1;
|
||||||
|
cur_term.c_cc[VTIME] = 0;
|
||||||
|
tcsetattr(STDIN_FILENO, TCSADRAIN, &cur_term);
|
||||||
|
|
||||||
|
if (!alternate_buffer) {
|
||||||
|
printf("\033[?1049h\033[H");
|
||||||
|
fflush(stdout);
|
||||||
|
alternate_buffer = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int client_mainloop(void) {
|
static int client_mainloop(void) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue