Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
typkrft opened this issue Aug 1, 2021 · 8 comments

Comments

@typkrft
Copy link

typkrft commented Aug 1, 2021

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.

@fgerling
Copy link

fgerling commented Aug 1, 2021

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.

@typkrft
Copy link
Author

typkrft commented Aug 1, 2021

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.

@fgerling
Copy link

fgerling commented Aug 2, 2021

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.

@typkrft
Copy link
Author

typkrft commented Aug 2, 2021

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.

@fgerling
Copy link

fgerling commented Aug 2, 2021

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.

@typkrft
Copy link
Author

typkrft commented Aug 2, 2021

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.

@typkrft
Copy link
Author

typkrft commented Aug 2, 2021

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

@fgerling
Copy link

fgerling commented Aug 2, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants