console doesn't support xterm-256color's "Esc E" for newline #19138

Closed
opened 2026-01-31 06:34:49 +00:00 by claunia · 3 comments
Owner

Originally created by @hsenag on GitHub (Dec 25, 2022).

When I try to use the control sequence \EE ("Esc E") on a recent WSL,

ganesh@DESKTOP-VCELNMA:~$ echo -e 'foo\EEbar'
foobar

Whereas in native Linux terminals I've tried, and PuTTy, I get:

[ganesh@paxton:~]$ echo -e 'foo\EEbar'
foo
bar

This has recently become a problem for me because it's listed as the sequence for a newline (nel) for xterm-256color in recent versions of the ncurses terminfo database (follow the link to xterm-new and then xterm-p370). It's also documented as an Xterm control sequence here.

From browsing the changelog I think this was added in early 2021 and has recently made its way into Ubuntu - it's not there in Ubuntu 20.04 and is there in Ubuntu 22.04. One way to see if it's listed on a particular machine is to run infocmp -x -1 xterm-256color | grep nel.

It goes wrong for me in practice with tools that use the Haskell terminfo library, which has this code to look up how to produce a newline. If nel isn't listed, then the fallback option works fine, but if it is listed then it tries to use \EE as instructed. This means that tools like ghci (the Haskell REPL) do this:

ghci> 5+510

instead of the expected.

ghci> 5+5
10

It can be reproduced without running a Linux shell by this .cmd file (rename to remove the .txt after downloading). You can see other control sequences do work by changing the E on the final echo line, for example changing it to an M invokes ri (scroll backwards). Of course without the WSL angle there's no particular reason to expect a random xterm control sequence to work in console.

Apologies if I've got completely the wrong end of the stick here about the problem, I didn't know anything much about how terminals actually communicate until I started digging into this problem. Now that I understand the issue better there should be various workarounds available (like setting TERM to something different).

Originally created by @hsenag on GitHub (Dec 25, 2022). When I try to use the control sequence `\EE` ("Esc E") on a recent WSL, ``` ganesh@DESKTOP-VCELNMA:~$ echo -e 'foo\EEbar' foobar ``` Whereas in native Linux terminals I've tried, and PuTTy, I get: ``` [ganesh@paxton:~]$ echo -e 'foo\EEbar' foo bar ``` This has recently become a problem for me because it's listed as the sequence for a newline (`nel`) for `xterm-256color` in recent versions of the [ncurses terminfo database](https://invisible-island.net/ncurses/terminfo.src.html#tic-xterm-256color) (follow the link to `xterm-new` and then `xterm-p370`). It's also documented as an Xterm control sequence [here](https://xfree86.org/current/ctlseqs.html). From browsing the changelog I think this was [added in early 2021](https://invisible-island.net/ncurses/NEWS.html#t20210220) and has recently made its way into Ubuntu - it's not there in Ubuntu 20.04 and is there in Ubuntu 22.04. One way to see if it's listed on a particular machine is to run `infocmp -x -1 xterm-256color | grep nel`. It goes wrong for me in practice with tools that use the Haskell terminfo library, which has [this code](https://github.com/judah/terminfo/blob/0d07a5eb737c206dd823e4ffd4f89b5a9b0f2d2f/System/Console/Terminfo/Cursor.hs#L170-L179) to look up how to produce a newline. If `nel` isn't listed, then the fallback option works fine, but if it is listed then it tries to use `\EE` as instructed. This means that tools like ghci (the Haskell REPL) do this: ``` ghci> 5+510 ``` instead of the expected. ``` ghci> 5+5 10 ``` It can be reproduced without running a Linux shell by [this `.cmd` file](https://github.com/microsoft/terminal/files/10299611/foo.cmd.txt) (rename to remove the `.txt` after downloading). You can see other control sequences do work by changing the `E` on the final `echo` line, for example changing it to an `M` invokes `ri` (scroll backwards). Of course without the WSL angle there's no particular reason to expect a random xterm control sequence to work in console. Apologies if I've got completely the wrong end of the stick here about the problem, I didn't know anything much about how terminals actually communicate until I started digging into this problem. Now that I understand the issue better there should be various workarounds available (like setting `TERM` to something different).
claunia added the Needs-TriageNeeds-Tag-Fix labels 2026-01-31 06:34:49 +00:00
Author
Owner

@237dmitry commented on GitHub (Dec 25, 2022):

In Powershell works

PS > "foo`eEbar"    # pwsh
foo
bar

PS > "foo$([char]27)Ebar"    # powershell
foo
bar

In Command Prompt works too ( where ^[ is keyboard keys Ctrl+[ ):

C:\> echo foo^[Ebar
foo
bar
@237dmitry commented on GitHub (Dec 25, 2022): In Powershell works ```powershell PS > "foo`eEbar" # pwsh foo bar PS > "foo$([char]27)Ebar" # powershell foo bar ``` In Command Prompt works too ( where `^[` is keyboard keys `Ctrl+[` ): ``` C:\> echo foo^[Ebar foo bar ```
Author
Owner

@j4james commented on GitHub (Dec 25, 2022):

@hsenag We added support for NEL (ESC E) way back in 2020 (see PR #3271), but it's possible you have a version of Windows that doesn't include that patch - you didn't say what version you're using. The notes on PR #3271 say it was released in build 19603, so if you have a version earlier than that you'll need to upgrade. Alternatively you can use Windows Terminal, which will always get the most recent features and fixes, without having to upgrade the whole operating system.

@j4james commented on GitHub (Dec 25, 2022): @hsenag We added support for `NEL` (`ESC E`) way back in 2020 (see PR #3271), but it's possible you have a version of Windows that doesn't include that patch - you didn't say what version you're using. The notes on PR #3271 say it was released in build 19603, so if you have a version earlier than that you'll need to upgrade. Alternatively you can use Windows Terminal, which will always get the most recent features and fixes, without having to upgrade the whole operating system.
Author
Owner

@hsenag commented on GitHub (Dec 25, 2022):

Thanks! And sorry for forgetting about the version info. Having had this on an older install of Windows, I recently reproduced this on a fresh install with what I thought was all the updates, version 19045.2364, but I now notice my system has been failing to download an update and I hadn't realised. I'll sort that out and try again.

@hsenag commented on GitHub (Dec 25, 2022): Thanks! And sorry for forgetting about the version info. Having had this on an older install of Windows, I recently reproduced this on a fresh install with what I thought was all the updates, version 19045.2364, but I now notice my system has been failing to download an update and I hadn't realised. I'll sort that out and try again.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19138