martanne / abduco

abduco provides session management i.e. it allows programs to be run independently from its controlling terminal. That is programs can be detached - run in the background - and then later reattached. Together with dvtm it provides a simpler and cleaner alternative to tmux or screen.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remotely run a command in running session an additional command on attach

typkrft opened this issue · comments

Effectively I am trying to figure out if there's a way to automate echo -e '\x1b[?1002h\x1b[?1006h'; to re-enable mouse support when connect to nvim. I've tried abduco -a nvim; echo -e '\x1b[?1002h\x1b[?1006h'; but it doesn't work.

Hi typkrft, I'm not sure if this will help with your mouse support, but for running a command remotely, you can pipe it to abudco:

$ echo -e '\x1b[?1002h\x1b[?1006h' | abduco -a nvim

Keep in mind that this will send \x1b[?1002h\x1b[?1006h to the session.

You could also run it with the -p flag:

abduco -p -a nvim
echo -e '\x1b[?1002h\x1b[?1006h'

This will execute echo -e '\x1b[?1002h\x1b[?1006h' inside your abduco session.

Hey thanks for the response. I don't have a p flag or see one documented. Am I missing something? I am running the latest release.

Edit:
Never Mind I just found it in the repository. It looks like I need to build it from souce instead of using brew. I'll check it out thanks!

2nd Edit:
Sadly both of your examples work, but it doesn't appear to benefit my use case. It looks like this needs to happen after it's attached and visible.

Do you have a link to documentation about how echo -e '\x1b[?1002h\x1b[?1006h' should work?
I do not have nvim installed but would like to find out if I can reproduce/test your issue.

I do not have documentation unfortunately. It's apparently an escape sequence (most?) terminals use to enable mouse support. I found it here actually #26 (comment). I am not using xterm, but this sequence seem to work in kitty, which is what I am using.

For what it's worth this does seem to be handled "properly" by tmux. Speaking from an end user perspective, I'm not sure how it's implemented.

So I played around a little and found those stackoverflow questions:

Both helped me understand a bit what is going on with the escape sequence. But I was not able to enable/re-enable mouse support for vim with these escape sequences. I did had success sending :mouse=a to vim, like described in #26 (comment), but this doesn't feel right.

I think the problem is that echo -e '\x1b[?1002h\x1b[?1006h' | abduco -p test is sending the escape sequence as input to the terminal and for it to become effective, it needs it as output.

Makes sense. Thanks for looking into this. I don't know if I'm kind of an edge case or not but it might be useful to add this complexity to the program if the developers are interested. It's not the end of the world though.

I wonder if this hinders anything else maybe I could just fork it and look at the source to see if I can always send it by default on attachment. I'm not sure how tmux handles this yet. I'll do some more digging when I have time.

Simply adding this printf("\x1b[?1002h\x1b[?1006h"); in client_setup_terminal seems to resolve the issue. I'm not sure if there is any logic or checks I should be doing first or if this is the only/best place to put it.

static void client_setup_terminal(void) {
	if (!has_term)
		return;
	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, TCSANOW, &cur_term);
	printf("\x1b[?1002h\x1b[?1006h");

	if (!alternate_buffer) {
		printf("\033[?1049h\033[H");
		fflush(stdout);
		alternate_buffer = true;
	}
}

https://github.com/typkrft/abduco/blob/307dfe94d423a0204b6aec7e4f9590e965cecdfb/client.c

That looks good. I will check out your PR #50.