\033[J has wrong specification, CSI 1 J & \x1B[0J should change behavior, CSI 2 J wrong with colors #66

Closed
opened 2026-01-30 21:41:17 +00:00 by claunia · 6 comments
Owner

Originally created by @mobluse on GitHub (Feb 6, 2018).

Originally assigned to: @zadjii-msft on GitHub.

  • Your Windows build number: (Type ver at a Windows Command Prompt)
    Microsoft Windows [Version 10.0.17083.1000]

  • What you're doing and what's happening: (Copy & paste specific commands and their output, or include screen shots)
    In Ubuntu I test with some lines on the console and these commands on last row:
    printf "\e[1;1H\e[0J"
    printf "\e[1;1H\e[1J"
    printf "\e[1;1H\e[2J"
    printf "\e[1;1H\e[J"

  • What's wrong / what should be happening instead:
    \e[1J & \e[0J should change behavior.
    \e[J does the right thing but the specification that default for xterm is 1 is probably wrong.
    \e[1;1H\e[J should do similar as \e[2J but now \e[2J doesn't seem to print spaces because background colors are not respected.
    Note the difference on the top row between printf "\e[1;1H\e[44m\e[2J" and printf "\e[1;1H\e[44m\e[J". Especially if the terminal is newly started.
    In WSLTTY 1.8.3 (based on PuTTY) there is no difference.

"For each of the sequences, the default value for if it is omitted is 1. For the following commands, the parameter has 3 valid values:

  • 0 erases from the beginning of the line/display up to and including the current cursor position
  • 1 erases from the current cursor position (inclusive) to the end of the line/display
  • 2 erases the entire line/display"

https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#span-idtextmodificationspanspan-idtextmodificationspanspan-idtextmodificationspantext-modification

"Clears part of the screen. If n is 0 (or missing), clear from cursor to end of screen. If n is 1, clear from cursor to beginning of the screen. If n is 2, clear entire screen (and moves cursor to upper left on DOS ANSI.SYS)."
https://en.wikipedia.org/wiki/ANSI_escape_code

"J ED Erase display (default: from cursor to end of display).
ESC [ 1 J: erase from start to cursor.
ESC [ 2 J: erase whole display."
man console_codes

"CSI Ps J Erase in Display (ED).
Ps = 0 -> Erase Below (default).
Ps = 1 -> Erase Above.
Ps = 2 -> Erase All."
http://invisible-island.net/xterm/ctlseqs/ctlseqs.html

This is partly related to #41.

Originally created by @mobluse on GitHub (Feb 6, 2018). Originally assigned to: @zadjii-msft on GitHub. * Your Windows build number: (Type `ver` at a Windows Command Prompt) Microsoft Windows [Version 10.0.17083.1000] * What you're doing and what's happening: (Copy & paste specific commands and their output, or include screen shots) In Ubuntu I test with some lines on the console and these commands on last row: `printf "\e[1;1H\e[0J"` `printf "\e[1;1H\e[1J"` `printf "\e[1;1H\e[2J"` `printf "\e[1;1H\e[J"` * What's wrong / what should be happening instead: \e[1J & \e[0J should change behavior. \e[J does the right thing but the specification that default for xterm is 1 is probably wrong. \e[1;1H\e[J should do similar as \e[2J but now \e[2J doesn't seem to print spaces because background colors are not respected. Note the difference on the top row between `printf "\e[1;1H\e[44m\e[2J"` and `printf "\e[1;1H\e[44m\e[J"`. Especially if the terminal is newly started. In WSLTTY 1.8.3 (based on PuTTY) there is no difference. "For each of the sequences, the default value for <n> if it is omitted is 1. For the following commands, the parameter <n> has 3 valid values: - 0 erases from the beginning of the line/display up to and including the current cursor position - 1 erases from the current cursor position (inclusive) to the end of the line/display - 2 erases the entire line/display" https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#span-idtextmodificationspanspan-idtextmodificationspanspan-idtextmodificationspantext-modification "Clears part of the screen. If n is 0 (or missing), clear from cursor to end of screen. If n is 1, clear from cursor to beginning of the screen. If n is 2, clear entire screen (and moves cursor to upper left on DOS ANSI.SYS)." https://en.wikipedia.org/wiki/ANSI_escape_code "J ED Erase display (default: from cursor to end of display). ESC [ 1 J: erase from start to cursor. ESC [ 2 J: erase whole display." `man console_codes` "CSI Ps J Erase in Display (ED). Ps = 0 -> Erase Below (default). Ps = 1 -> Erase Above. Ps = 2 -> Erase All." http://invisible-island.net/xterm/ctlseqs/ctlseqs.html This is partly related to #41.
claunia added the Product-ConhostWork-Item labels 2026-01-30 21:41:17 +00:00
Author
Owner

@mobluse commented on GitHub (Feb 8, 2018):

Some of these problems are fixed in Microsoft Windows [Version 10.0.17093.1000], but this remains:
\e[1;1H\e[J should do similar as \e[2J but now \e[2J doesn't seem to print spaces because background colors are not respected.
Note the difference on the top row between printf "\e[H\e[44m\e[2J" and printf "\e[H\e[44m\e[J". Especially if the terminal is newly started.
In WSLTTY 1.8.4 there is no difference. Also note what happens in Ubuntu for WSL in Cmd.exe vs in WSLtty when clear is issued several times.

@mobluse commented on GitHub (Feb 8, 2018): Some of these problems are fixed in Microsoft Windows [Version 10.0.17093.1000], but this remains: \e[1;1H\e[J should do similar as \e[2J but now \e[2J doesn't seem to print spaces because background colors are not respected. Note the difference on the top row between `printf "\e[H\e[44m\e[2J"` and `printf "\e[H\e[44m\e[J"`. Especially if the terminal is newly started. In WSLTTY 1.8.4 there is no difference. Also note what happens in Ubuntu for WSL in Cmd.exe vs in WSLtty when `clear` is issued several times.
Author
Owner

@zadjii-msft commented on GitHub (Feb 13, 2018):

Filed a bug to investigate more

@zadjii-msft commented on GitHub (Feb 13, 2018): Filed a bug to investigate more
Author
Owner

@mobluse commented on GitHub (Apr 24, 2018):

The cursor should not be moved when doing printf "\e[2J" according to xterm, but in Ubuntu for WSL in Cmd.exe it is moved to the upper left corner. This is probably due to compatibility with ANSI.SYS, but it breaks compatibility with xterm.

@mobluse commented on GitHub (Apr 24, 2018): The cursor should not be moved when doing `printf "\e[2J"` according to `xterm`, but in Ubuntu for WSL in Cmd.exe it is moved to the upper left corner. This is probably due to compatibility with ANSI.SYS, but it breaks compatibility with `xterm`.
Author
Owner

@zadjii-msft commented on GitHub (Apr 26, 2018):

Okay yea, this is definitely a regression. It worked fine before, but I think I regressed it in RS4 when I made Erase All move the viewport down below the emitted text, instead of clearing the viewport in place. I'll just need to:

  • restore the relative cursor position
  • update the text attributes on the new viewport to whatever the currently active ones are.

Additionally, it does look like those MSDN docs are wrong.

  • update the docs to reflect that 0 is the default erase operation.
@zadjii-msft commented on GitHub (Apr 26, 2018): Okay yea, this is definitely a regression. It worked fine before, but I think I regressed it in RS4 when I made Erase All move the viewport down below the emitted text, instead of clearing the viewport in place. I'll just need to: * [x] restore the relative cursor position * [x] update the text attributes on the new viewport to whatever the currently active ones are. Additionally, it does look like those MSDN docs are wrong. * [ ] update the docs to reflect that 0 is the default erase operation.
Author
Owner

@zadjii-msft commented on GitHub (Apr 26, 2018):

The code changes are all ready, so they just need to be code reviewed and checked in. Thanks!

@zadjii-msft commented on GitHub (Apr 26, 2018): The code changes are all ready, so they just need to be code reviewed and checked in. Thanks!
Author
Owner

@DHowett-MSFT commented on GitHub (Feb 6, 2019):

reviewed and checked in

This happened some time ago, so I'm going to close this!
Thanks!

@DHowett-MSFT commented on GitHub (Feb 6, 2019): > reviewed and checked in This happened some time ago, so I'm going to close this! Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#66