terminal icon indicating copy to clipboard operation
terminal copied to clipboard

SendInput with newlines in it outputs the text backward

Open PankajBhojwani opened this issue 2 years ago • 5 comments

Windows Terminal version

latest build of main

Windows build number

No response

Other Software

Powershell 7

Steps to reproduce

Make a 'sendInput' command with newlines in the settings json, example:

            "command": 
            {
                "action": "sendInput",
                "input": "a\nb\nc"
            },
            "name": "test sendinput"

Invoke the command in terminal

Expected Behavior

The text output should be a, then b, then c as below

image

Actual Behavior

The actual output is reversed, and goes c->b->a

image

PankajBhojwani avatar Aug 01 '23 21:08 PankajBhojwani

Update: with command prompt instead we get: image

I.e. the text is in the correct order but there's no new lines at all

PankajBhojwani avatar Aug 01 '23 21:08 PankajBhojwani

Sooo this is actually adjacent to a paste issue we had! You want \r or both \r\n.

DHowett avatar Aug 01 '23 22:08 DHowett

Should sendInput maybe just behave like ENABLE_PROCESSED_INPUT is enabled? Edit: Oh, but that might make sending precise inputs harder... hmm...

lhecker avatar Aug 02 '23 12:08 lhecker

My thought is that InputStateMachineEngine::_DoControlCharacter attempts to translate \n to ctrl+j. But that doesn't seem like what's happening, because ctrl+j is bound to MenuComplete (at least, on my machine). I'd probably need to step through it more precisely.

Key Function Description
Ctrl+Enter InsertLineAbove Inserts a new empty line above the current line without attempting to execute the input

Now, that's pretty dang close to what we're seeing. That would also explain why nothing happens in CMD - ctrl+enter doesn't do anything there.

zadjii-msft avatar Aug 02 '23 13:08 zadjii-msft

@

HDJINJIN avatar Aug 22 '23 00:08 HDJINJIN