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

Possible to send CTRL-C into? #13

Open
jesseleite opened this issue Oct 24, 2018 · 6 comments
Open

Possible to send CTRL-C into? #13

jesseleite opened this issue Oct 24, 2018 · 6 comments

Comments

@jesseleite
Copy link
Contributor

Hey yo, is it possible to send something like CTRL-C into? I was having trouble sending through to a shell running less +F.

Awesome work on shtuff btw!

@jfly
Copy link
Owner

jfly commented Oct 24, 2018

We internally we use pexpects .send method to send keys to the running process. https://stackoverflow.com/a/11299721/1739415 says you might be able to call sendcontrol instead: https://pexpect.readthedocs.io/en/stable/api/pexpect.html?highlight=sendcontrol#pexpect.spawn.sendcontrol. It also looks like sendcontrol is a simple wrapper around send, so it's probably possible to concoct the right control codes yourself. I wonder if something like this would work:

$ shtuff into foo -n $'\003'

Where "foo" is the name of some shell running less or something.

@jesseleite
Copy link
Contributor Author

Yep that works, thanks!

I wonder if it'd be worth supporting tmux-like syntax in the future, like ^c, C-c, Enter, etc.? I believe they have a -l option for sending literal characters. Example:

shtuff into foo -n '^c vim Enter'

...would use string replace on certain keywords to send a CTRL-C, then open vim.

shtuff into foo -n -l '^c vim Enter'

...would send those literal characters, as it does in the current version.

@jfly
Copy link
Owner

jfly commented Oct 25, 2018

Interesting.

I'm not opposed, but in terms of Unix philosophy, this almost feels like it should be a different tool's job.

Also, if we defaulted to ^c sending ctrl-c that would be a backwards incompatible change, which is fine (we only have 3 users), but just thought I'd mention it.

@jesseleite
Copy link
Contributor Author

Could always do the opposite and leave default behaviour too. Maybe something like -s to parse 'special keys'?

I get the unix philosophy, but something both tmux and screen have going for UX is allowing ^c, rather than forcing the user to have to go look up that ASCII code 😌

@FatBoyXPC
Copy link
Collaborator

FatBoyXPC commented Oct 25, 2018

How does screen stuff handle this? I don't know if I want to over-commit to tmux or screen features, but if they both do something sane here, then it might be worth bringing in.

@jfly makes a good point about Unix philosophy, but I do think that having an option to send control characters is at least related to what this package does. I don't say that to mean that shtuff needs to do the character parsing, we could find a different package for that or write it and let shtuff depend on it.

@jfly
Copy link
Owner

jfly commented Oct 25, 2018

we could find a different package for that or write it and let shtuff depend on it

Or if we can't find one, we can create one =)

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

3 participants