Is there a way to setting Line Breaks to '\n' ? #17865

Closed
opened 2026-01-31 05:56:42 +00:00 by claunia · 8 comments
Owner

Originally created by @Tancen on GitHub (Jul 5, 2022).

My pseudo console receive commands from the Linux terminal real-time, It cannot process '\n' well on key 'Enter' pressed. So, I scanned each input character and replaced '\n' with '\r\n' on Linux for windows pseudo console works well. But, The solution isn't beautiful on some text pasted, Because characters '\r\n' will be replaced with '\r\r\n'.
Is there a way to setting Line Breaks to '\n' ? Thanks.

Originally created by @Tancen on GitHub (Jul 5, 2022). My pseudo console receive commands from the Linux terminal real-time, It cannot process '\n' well on key 'Enter' pressed. So, I scanned each input character and replaced '\n' with '\r\n' on Linux for windows pseudo console works well. But, The solution isn't beautiful on some text pasted, Because characters '\r\n' will be replaced with '\r\r\n'. Is there a way to setting Line Breaks to '\n' ? Thanks.
claunia added the Issue-QuestionNeeds-TriageNeeds-Tag-FixResolution-Answered labels 2026-01-31 05:56:43 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Jul 5, 2022):

I think we're gonna need more info on the specifics of your scenario here. How newlines are handled are usually dependent on the line discipline of the connected client application. This is likely different for a win32 console application vs a linux application running under WSL.

Can you give us some specific repro steps/?

@zadjii-msft commented on GitHub (Jul 5, 2022): I think we're gonna need more info on the specifics of your scenario here. How newlines are handled are usually dependent on the line discipline of the connected client application. This is likely different for a win32 console application vs a linux application running under WSL. Can you give us some specific repro steps/?
Author
Owner

@Tancen commented on GitHub (Jul 6, 2022):

I think we're gonna need more info on the specifics of your scenario here. How newlines are handled are usually dependent on the line discipline of the connected client application. This is likely different for a win32 console application vs a linux application running under WSL.

Can you give us some specific repro steps/?

Sorry, For example, the pseudo console launched 'cmd.exe' at first. key 'Enter' pressed after characters 'dir' typed on linux terminal, data 'dir\n' received on windows and be written in pseudo console, the pseudo console doesn't output result for the command 'dir'. it expects 'dir\r\n', not 'dir\n'.

@Tancen commented on GitHub (Jul 6, 2022): > I think we're gonna need more info on the specifics of your scenario here. How newlines are handled are usually dependent on the line discipline of the connected client application. This is likely different for a win32 console application vs a linux application running under WSL. > > Can you give us some specific repro steps/? Sorry, For example, the pseudo console launched 'cmd.exe' at first. key 'Enter' pressed after characters 'dir' typed on linux terminal, data 'dir\n' received on windows and be written in pseudo console, the pseudo console doesn't output result for the command 'dir'. it expects 'dir\r\n', not 'dir\n'.
Author
Owner

@zadjii-msft commented on GitHub (Jul 6, 2022):

Well, that makes perfect sense. There are two different streams here - input and output. \n works just fine as input to indicate an enter. On output, however, you'll want both the \r and the \n, because they do different things as output. \r takes the cursor back to the start of the row, while \n takes the cursor down a row. Technically, to go to the start of the next line, you need both an \r and an \n. In general, conpty actually does leverage that difference quite a bit, to make sure the cursor in the conpty stays in sync with the hosting terminal in an efficient manner.

@zadjii-msft commented on GitHub (Jul 6, 2022): Well, that makes perfect sense. There are two different streams here - input and output. `\n` works just fine as input to indicate an <kbd>enter</kbd>. On output, however, you'll want both the `\r` and the `\n`, because they do different things as output. `\r` takes the cursor back to the start of the row, while `\n` takes the cursor down a row. Technically, to go to the _start_ of the _next_ line, you need both an `\r` and an `\n`. In general, conpty actually does leverage that difference quite a bit, to make sure the cursor in the conpty stays in sync with the hosting terminal in an efficient manner.
Author
Owner

@Tancen commented on GitHub (Jul 6, 2022):

Well, that makes perfect sense. There are two different streams here - input and output. \n works just fine as input to indicate an enter. On output, however, you'll want both the \r and the \n, because they do different things as output. rtakes the cursor back to the start of the row, while\ntakes the cursor down a row. Technically, to go to the start of the next line, you need both an\rand an\n. In general, conpty actually does leverage that difference quite a bit, to make sure the cursor in the conpty stays in sync with the hosting terminal in an efficient manner.

Yes. So, please 'cmd.exe' to give settings(or another way) to make a command such as 'dir\n' work like 'dir\r\n'(If Windows terminal will be compatible with UNIX-like terminal).

@Tancen commented on GitHub (Jul 6, 2022): > Well, that makes perfect sense. There are two different streams here - input and output. `\n` works just fine as input to indicate an enter. On output, however, you'll want both the `\r` and the `\n`, because they do different things as output. `r`takes the cursor back to the start of the row, while`\n`takes the cursor down a row. Technically, to go to the _start_ of the _next_ line, you need both an`\r`and an`\n`. In general, conpty actually does leverage that difference quite a bit, to make sure the cursor in the conpty stays in sync with the hosting terminal in an efficient manner. Yes. So, please 'cmd.exe' to give settings(or another way) to make a command such as 'dir\n' work like 'dir\r\n'(If Windows terminal will be compatible with UNIX-like terminal).
Author
Owner

@237dmitry commented on GitHub (Jul 6, 2022):

So, please 'cmd.exe' to give settings(or another way)

Use your favorite scripting or more serious programming language in order to convert UNIX and WINDOWS line breaks by the fly.
There is not any settings to change system wide line breaking. Cmd.exe is one of Windows shells, Windows Terminal is an application to launch it.

@237dmitry commented on GitHub (Jul 6, 2022): > So, please 'cmd.exe' to give settings(or another way) Use your favorite scripting or more serious programming language in order to convert UNIX and WINDOWS line breaks by the fly. There is not any settings to change system wide line breaking. Cmd.exe is one of Windows shells, Windows Terminal is an application to launch it.
Author
Owner

@Tancen commented on GitHub (Jul 6, 2022):

So, please 'cmd.exe' to give settings(or another way)

Use your favorite scripting or more serious programming language in order to convert UNIX and WINDOWS line breaks by the fly. There is not any settings to change system wide line breaking. Cmd.exe is one of Windows shells, Windows Terminal is an application to launch it.

As I described in my question, it's so hard to resolve the problem that pasting and typing compatibility (input stream).

@Tancen commented on GitHub (Jul 6, 2022): > > So, please 'cmd.exe' to give settings(or another way) > > Use your favorite scripting or more serious programming language in order to convert UNIX and WINDOWS line breaks by the fly. There is not any settings to change system wide line breaking. Cmd.exe is one of Windows shells, Windows Terminal is an application to launch it. As I described in my question, it's so hard to resolve the problem that pasting and typing compatibility (input stream).
Author
Owner

@237dmitry commented on GitHub (Jul 6, 2022):

key 'Enter' pressed after characters 'dir' typed on linux terminal, data 'dir\n' received on windows and be written in pseudo console, the pseudo console doesn't output result for the command 'dir'. it expects 'dir\r\n', not 'dir\n'.

Just tried, connected with ssh from linux-computer to windows one. dir worked as expected.

@237dmitry commented on GitHub (Jul 6, 2022): > key 'Enter' pressed after characters 'dir' typed on linux terminal, data 'dir\n' received on windows and be written in pseudo console, the pseudo console doesn't output result for the command 'dir'. it expects 'dir\r\n', not 'dir\n'. Just tried, connected with ssh from linux-computer to windows one. `dir` worked as expected.
Author
Owner

@Tancen commented on GitHub (Jul 7, 2022):

key 'Enter' pressed after characters 'dir' typed on linux terminal, data 'dir\n' received on windows and be written in pseudo console, the pseudo console doesn't output result for the command 'dir'. it expects 'dir\r\n', not 'dir\n'.

Just tried, connected with ssh from linux-computer to windows one. dir worked as expected.

Thanks, I will consider it.

@Tancen commented on GitHub (Jul 7, 2022): > > key 'Enter' pressed after characters 'dir' typed on linux terminal, data 'dir\n' received on windows and be written in pseudo console, the pseudo console doesn't output result for the command 'dir'. it expects 'dir\r\n', not 'dir\n'. > > Just tried, connected with ssh from linux-computer to windows one. `dir` worked as expected. Thanks, I will consider it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#17865