Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bash command to clear the VSCode integrated terminal scrollback on Windows 10? #116664

Closed
denishowe opened this issue Feb 15, 2021 · 9 comments
Closed
Assignees
Labels
*out-of-scope Posted issue is not in scope of VS Code terminal General terminal issues that don't fall under another label under-discussion Issue is under discussion for relevance, priority, approach upstream Issue identified as 'upstream' component related (exists outside of VS Code)

Comments

@denishowe
Copy link

Issue Type: Bug

I'm happily running Git bash in VSCode on Windows with:

"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",

The "Terminal: Clear" command (workbench.action.terminal.clear, which I have bound to Control-L) clears not only the screen but also the scrollback buffer, as expected, so trying to scroll up does nothing because there is nothing to show.

How can I reproduce this with a shell command?

The clear command does not clear the scrollback, neither does reset. These commands work by outputting escape sequences to the screen. Since the terminal thinks it is "TERM = xterm-256color", the relevant escape sequence should be the one output by the shell command printf "\e[3J" which works on all other xterm emulations (and is part of clear's output). In VSCode it does not clear the scrollback but, oddly, resurrects one screenful of previously cleared scrollback.

VS Code version: Code 1.53.2 (622cb03, 2021-02-11T11:48:04.245Z)
OS version: Windows_NT x64 10.0.19042

System Info
Item Value
CPUs Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz (8 x 3392)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.96GB (10.40GB free)
Process Argv --crash-reporter-id 13260536-d995-489d-8f04-2bc386bb128a
Screen Reader no
VM 0%
Extensions (4)
Extension Author (truncated) Version
vscode-eslint dba 2.1.14
seito-openfile Fr4 1.8.7
gc-excelviewer Gra 3.0.41
org-mode vsc 1.0.0
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
pythonvspyt617cf:30253240
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492cf:30256860
vstry244cf:30256637
pythonvsdeb440:30248342
pythonvsded773:30248341
pythonvspyt600cf:30251589

@Tyriar
Copy link
Member

Tyriar commented Feb 17, 2021

Related to xtermjs/xterm.js#106

Not sure we can do anything about this as I believe we handle the sequence we're given correctly.

@Tyriar Tyriar added terminal General terminal issues that don't fall under another label under-discussion Issue is under discussion for relevance, priority, approach labels Feb 17, 2021
@Tyriar
Copy link
Member

Tyriar commented Feb 17, 2021

You can check what VS Code receives from the pty by logging escape sequences https://github.com/microsoft/vscode/wiki/Terminal-Issues#enabling-escape-sequence-logging

@denishowe
Copy link
Author

Thanks Tyriar. I executed this command in bash:

sleep 2; printf "(\e[3J)"; sleep 99

I cleared the dev console during the sleep 2. During the sleep 99, the console showed:

xterm.js: parsing data ()�[0K

Something deleted my \e[3J.

workbench.action.terminal.clear clears scrollback but also shows nothing in dev console.

@Tyriar
Copy link
Member

Tyriar commented Oct 13, 2021

Looks like something is going wrong with the emulation here that causes your sequence to get stripped out? When you run printf it would go through git bash and then through conpty before reaching the process, and those layers are passed through again when coming the other direction. You could try:

  • Updating Windows
  • Updating git bash
  • Trying in Windows Terminal (if it's fixed, we should get the fix in a newer release of Windows)

@Tyriar Tyriar added *out-of-scope Posted issue is not in scope of VS Code upstream Issue identified as 'upstream' component related (exists outside of VS Code) labels Oct 13, 2021
@TYTheBeast
Copy link

Although this is a really old issue, it's still relevant. Even today, no matter whether I'm running cmd, Powershell 7, Git Bash or any other profile, their respective clear command only clears one screenful of the terminal, without actually clearing the scrollback buffer.

@Tyriar
Copy link
Member

Tyriar commented Mar 1, 2023

@TYTheBeast that's tracked in xtermjs/xterm.js#1727

@danyg
Copy link

danyg commented Jan 25, 2024

Workarround that worked for me in zsh in mac
add to your ~/.zshrc the following line

alias clear='printf "\e[3J"; clear'

I guess similar approaches can be done with other shells.
for windows shells you might be able to create a bat in the PATH that overrides cls? not sure.

HTH

@mike-clark-8192
Copy link

mike-clark-8192 commented Feb 20, 2024

Under cmd.exe inside VSCode, none of the "clear" termcodes will clear the scrollback, even though at least a few of them probably should.

In fact, the plain old 'cls' command should clear the scrollback, as it does under the classic cmd window, and also the new Windows Terminal. But, it does not. Here is a .bat file that tests/exercises the various 'clear' terminal control codes. Running this inside VSCode will not result in a scrollback clear, whereas in Windows Terminal, it will.

@echo off
setlocal enableextensions

call :testit "[3J" "erase scrollback"         || exit /b
call :testit "[2J" "erase all"                || exit /b
call :testit "[1J" "erase above"              || exit /b
call :testit "[0J" "erase below"              || exit /b
call :testit "[J"  "erase below (alternate)"  || exit /b
call :testit "c"   "reset term"               || exit /b
echo Done.

goto :eof
:testit
REM this loop will probably reach the scrollback on most window sizes
for /l %%F in (30,1,37) do (
    for /l %%B in (40,1,47) do (
        call :echoe "\x1b[%%F;%%Bm%%F;%%B\x1b[0m"
    )
)
echo. & echo.
set /p "_=Press enter to test %1 (%~2): "
if "%_%"=="q" exit /b 1
call :echoe \x1b%1
echo Sending of %1 (%~2) is complete.
if "%~1"=="c" exit /b && REM "(exit because c is the last test)"
set /p "_=Press enter to move on to the next test."
exit /b 0
goto :eof

goto :eof
:echoe
setlocal
set "arg=%~1"
set "arg=%arg:\x=0x%"
forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c <nul set /p _=%arg%"
goto :eof

@D3Pheonix
Copy link

for me, it works:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
*out-of-scope Posted issue is not in scope of VS Code terminal General terminal issues that don't fall under another label under-discussion Issue is under discussion for relevance, priority, approach upstream Issue identified as 'upstream' component related (exists outside of VS Code)
Projects
None yet
Development

No branches or pull requests

8 participants
@denishowe @danyg @Tyriar @TYTheBeast @meganrogge @mike-clark-8192 @D3Pheonix and others