SendInput with newlines in it outputs the text backward #20322

Closed
opened 2026-01-31 07:10:13 +00:00 by claunia · 6 comments
Owner

Originally created by @PankajBhojwani on GitHub (Aug 1, 2023).

Originally assigned to: @PankajBhojwani on GitHub.

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
Originally created by @PankajBhojwani on GitHub (Aug 1, 2023). Originally assigned to: @PankajBhojwani on GitHub. ### 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 <img width="357" alt="image" src="https://github.com/microsoft/terminal/assets/26824113/85f62b7c-5749-4671-8bac-eb37318bce4a"> ### Actual Behavior The actual output is reversed, and goes c->b->a <img width="353" alt="image" src="https://github.com/microsoft/terminal/assets/26824113/d428823a-a653-479e-ab2e-2a3b9849dc5e">
Author
Owner

@PankajBhojwani commented on GitHub (Aug 1, 2023):

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 commented on GitHub (Aug 1, 2023): Update: with command prompt instead we get: <img width="160" alt="image" src="https://github.com/microsoft/terminal/assets/26824113/0809fa5f-2dd5-4036-b233-b9e7aab21a6b"> I.e. the text is in the correct order but there's no new lines at all
Author
Owner

@DHowett commented on GitHub (Aug 1, 2023):

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

@DHowett commented on GitHub (Aug 1, 2023): Sooo this is actually adjacent to a paste issue we had! You want `\r` or both `\r\n`.
Author
Owner

@lhecker commented on GitHub (Aug 2, 2023):

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

@lhecker commented on GitHub (Aug 2, 2023): Should `sendInput` maybe just behave like `ENABLE_PROCESSED_INPUT` is enabled? Edit: Oh, but that might make sending precise inputs harder... hmm...
Author
Owner

@zadjii-msft commented on GitHub (Aug 2, 2023):

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 commented on GitHub (Aug 2, 2023): My thought is that `InputStateMachineEngine::_DoControlCharacter` attempts to translate `\n` to <kbd>ctrl+j</kbd>. But that doesn't _seem_ like what's happening, because <kbd>ctrl+j</kbd> 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 - <kbd>ctrl+enter</kbd> doesn't do anything there.
Author
Owner

@HDJINJIN commented on GitHub (Aug 22, 2023):

@

@HDJINJIN commented on GitHub (Aug 22, 2023): @
Author
Owner

@zadjii-msft commented on GitHub (Sep 4, 2024):

closing: just put a \r\n instead of a \n (maybe just a \r)

@zadjii-msft commented on GitHub (Sep 4, 2024): closing: just put a `\r\n` instead of a `\n` (maybe just a `\r`)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20322