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

Add support for send-input subcommand #9368

Open
ngmariusz opened this issue Mar 3, 2021 · 7 comments
Open

Add support for send-input subcommand #9368

ngmariusz opened this issue Mar 3, 2021 · 7 comments
Labels
Area-Commandline wt.exe's commandline arguments Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Milestone

Comments

@ngmariusz
Copy link

you can execute when creating tab

exp:
wt.exe -w 2 sp -V wsl.exe zsh -ic "l\; /bin/zsh"

but there is not way to execute when it's already created or i do sth wrong?

Environment

21322.1000
Windows 10 Feature Experience Pack 321.2906.0.3
wsl2
Linux DESKTOP-RRHRJSC 4.19.128-microsoft-standard #1 .... x86_64 x86_64 x86_64 GNU/Linux
Windows Terminal Preview 1.7.572.0

Steps to reproduce

wsl
wt.exe -w 2 focus-tab -t 3 /bin/bash -c 'ls'

Expected behavior

executes /bin/bash -c 'ls' in focused tab

or

introduce -exec flag that executes passed string

wt.exe -w 2 focus-tab -t 3 -exec "/bin/bash -c 'ls'"

Actual behavior

only focuses tab

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Mar 3, 2021
@zadjii-msft
Copy link
Member

So, if I'm reading this correctly, what you're really looking for is the sendInput action, but as a subcommand on the commandline? So that when you already have an existing terminal instance, you could do

wt -w send-input ls

to send "ls" to the active pane. That makes sense to me. It's something we've been back and forth on in the past - I've been a little hesitant to allow other processes to "inject" input into terminal instances like this. That being said, we're not really pursuing mixed elevation anymore, so now I'm less worried about this.

What I am worried about is how we encode special characters. Not all shells support multi-line input, so putting a raw \n into the input might be tricky. It's easier to encode in json where you can just literally say "ls\n". A flag to say "please follow this input string with a \n" isn't a terrible idea, but then what if you want multiple commands? What if you want an arrow key? So we'd need to have a good way of encoding escape character in the input (regardless of shell).

@zadjii-msft zadjii-msft added Area-Commandline wt.exe's commandline arguments Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. labels Mar 3, 2021
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Mar 3, 2021
@zadjii-msft zadjii-msft added this to the Terminal Backlog milestone Mar 3, 2021
@zadjii-msft zadjii-msft changed the title windows terminal preview - can NOT execute command after tab focus Add support for send-input subcommand Mar 3, 2021
@ngmariusz
Copy link
Author

Yes, thank you "send-input" is much better name;

As i understand encoding/escaping is well know problem

no long ago i was trying this ${selectedText} in vscode tasks ( https://code.visualstudio.com/docs/editor/variables-reference )
and it bited me couple of times but eventually i figured that out, we are developers after all ;)

...so perhaps accepting "multiline / etc input" in a smart way is yet another feature? and we could try how idea is working out in a wild.

to add more context of my use case

i'd like to have one monitor of multiple opened terminals only and pushing to chosen one with my ide shortcuts from another monitor

until remote control was released my scenario was

1. create command in editor (as i usually have there more context than terminal history) 
2. select 
3. copy 
4. change to desired terminal window (mostly with alt+tab 1-n times until got wanted one )
5. select desired tab
6. Paste
7. Go  back (mostly with alt+tab 1-n times until got wanted one)

with remote control currently i have

1. create command in editor (as i usually have there more context than terminal history) 
2. select 
3. copy 
4. with single shortcut -> select desired tab with know window id and tab index             
5. -
6. Paste
7. Go back (mostly with alt+tab 1-n times until got wanted one)

it's better but i need

1. create command in editor (as i usually have there more context than terminal history) 
2. select 
3. with single shortcut -> select desired tab with know window id and tab index and execute my selected string there        
4. -               
5. -
6. -
7. -  

there are also scenarios when command is derived entirely from context so if you'd create shortcut for this in your IDE you could

1. -
2. -
3. with single shortcut -> select desired tab with know window id and tab index and execute command is derived entirely from context there        
4. -               
5. -
6. -
7. -

i hope it's worth pursuing

also

it helps alot with work ergonomic ( and wrist pain ;) )

@DHowett DHowett removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Mar 13, 2021
@zadjii-msft zadjii-msft modified the milestones: Terminal Backlog, Backlog Jan 4, 2022
@joswr1ght
Copy link

I'm not terribly concerned about multiline input, since you can stack multiple send-input commands to achieve the same goal. Perhaps it is a little less graceful, but it would allow for behavior similar to the current split-pane [commandline] syntax where \n is implied. The caller has to consider the requirements for whether the profile accepts any special characters sent.

I don't really see a use case for sending arrow keys as input (famous last words perhaps). My thinking is that this extends the precedent for functionality set by split-pane [commandline] for a lot of added flexibility.

@3N4N
Copy link

3N4N commented Jul 18, 2023

This feature would be similar to tmux's send-keys action. It could be used in several ways, but I use it to send text from Vim to a REPL, basically setting up an ad-hoc IDE. (Yes Vim has embedded terminal now, but it cannot really replace a fully-functioning terminal.)

Wezterm also has a similar feature. It's called send-text.

@noheromen
Copy link

Any progress on this feature? I would like to have it too. Thanks

@zadjii-msft
Copy link
Member

Nope. We'll make sure to update this thread when there is. In the meantime, might I recommend the Subscribe button?
image
That way you'll be notified of any updates to this thread, without needlessly pinging everyone on this thread ☺️


I'm also still not sure how confident I feel about the ability for arbitrary exes to send arbitrary keystrokes to random shells. Maybe I'd feel more confident if it was an opt-in thing. Like, you need to turn on a special setting first to say "yep, I'm gonna do some scripting now" - though, if it was just in the settings.json, there's literally nothing that prevents malicious.exe from just changing the settings file itself.

@einarpersson
Copy link

I have really enjoyed working with WSL2 as a combination of Windows and Linux, but not being able to programmatically control the terminal app itself (including sending arbitrary input to it) feels limiting right now in a time of automation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Commandline wt.exe's commandline arguments Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

No branches or pull requests

7 participants