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

Integrated Terminal icons break positioning after ClearScreen #4280

Closed
6 tasks done
ninmonkey opened this issue Nov 22, 2022 · 11 comments
Closed
6 tasks done

Integrated Terminal icons break positioning after ClearScreen #4280

ninmonkey opened this issue Nov 22, 2022 · 11 comments
Assignees
Labels
Area-Extension Terminal Issue-Bug A bug to squash. Resolution-External Will close automatically.

Comments

@ninmonkey
Copy link

ninmonkey commented Nov 22, 2022

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

Terminal Integration icons lose their positioning after clearing screen. ctrl+l .
I have the default binding where the PSReadLine function is ClearScreen

image

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

1.73.1
6261075646f055b99068d3688932416f2346dd3b
x64

Extension Version

Steps to Reproduce

  • Open a fresh Powershell Extension terminal
  • Enter a few commands
  • Hit ctrl+l
  • scroll up and down

It seems to stay broken until you reload

Visuals

vscode ┐ PsIntegratedTerm ┐ jumping offsets - 2022-10e3

Logs

No response

@ninmonkey ninmonkey added the Issue-Bug A bug to squash. label Nov 22, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label Nov 22, 2022
@andyleejordan
Copy link
Member

Does this repro outside of the extension terminal?

@ninmonkey
Copy link
Author

ninmonkey commented Nov 23, 2022

Does this repro outside of the extension terminal?

Yes. This new gif is from the non-extension term.

I noticed something new: When it's broken, some jumps go out of order when hitting the ctrl+up/down keys.
I had assumed it searched the text for the new prompt ansi escapes -- Or if it does, maybe the UI has a cached state that isn't marked as dirty?

If you can see this horizontal gray bar

image

Watch it move on the bottom right corner of the gif

vscode ┐ PsIntegratedTerm ┐ jumping offsets - B - 2022-10e2

@andyleejordan
Copy link
Member

Ahh, good find, thank you. I imagine we're doing something in our clear screen implementation that acts like a command, but I certainly missed adding an escape sequence there.

@andyleejordan andyleejordan self-assigned this Nov 23, 2022
@andyleejordan andyleejordan added Area-Extension Terminal and removed Needs: Triage Maintainer attention needed! labels Nov 23, 2022
@andyleejordan
Copy link
Member

Oh, hm...we don't have a custom ClearScreen implementation any more, unless powershell.integratedConsole.forceClearScrollbackBuffer is set. What I'm seeing on my Mac is that both Ctrl-L and Clear-Host in both the extension terminal and Code's integrated terminal essentially delete scrollback history, which is clearly not what you're expecting here, and not what I see happen in the Terminal.

@andyleejordan
Copy link
Member

Yeah, in Code's extension terminal, I only get the behavior you see when I sets terminal.integrated.allowChords, which is allowing the Ctrl-L through to PSReadLine; but that setting is not affecting the Extension Terminal. So what does VS Code do when it intercepts that...(and what are we doing either way?)

@andyleejordan
Copy link
Member

Screenshot 2022-11-23 at 11 53 03 AM

Are you sure you don't see this in a regular VS Code integrated terminal? I seem to be able to repro it there. That's using PowerShell 7.3 on Windows, not in the extension but in a Code integrated terminal, hitting Ctrl-L, and the dots are losing their locations.

@andyleejordan
Copy link
Member

andyleejordan commented Nov 23, 2022

Yes. This new gif is from the non-extension term.

Oh! I read this wrong. So it isn't an extension terminal issue. Ok! I can work with @Tyriar and @SeeminglyScience to figure out how we can fix this. My bet since PSReadLine's ClearScreen implementation is sending the clear screen terminal sequence and then invoking the prompt, we're "missing" that prompt invocation, since Code's shell integration wraps PSConsoleHostReadLine to send it, and in our host we add it in our own InvokeReadLine wrapper.

I suppose we could intercept Ctrl-L somehow, or override ClearScreen, either way we need to know that the user asked PSReadLine to clear the screen and then handle updating shell integration.

@andyleejordan
Copy link
Member

@ninmonkey can you execute:

Set-PSReadLineKeyHandler -Chord "Ctrl+l" -ScriptBlock {
	[Console]::Write("$([char]0x1b)]633;C`a")
	[Microsoft.PowerShell.PSConsoleReadLine]::ClearScreen()
}

and then see if everything works as expected with Ctrl+l? Seems to on my end!

@Tyriar
Copy link
Contributor

Tyriar commented Nov 23, 2022

We're tracking this in microsoft/vscode#166864, it's not clear to me whether this is a pwsh, conpty or our issue. I believe we clear the decorations when certain erase in display sequences happen.

@andyleejordan andyleejordan added the Resolution-External Will close automatically. label Nov 23, 2022
@ghost ghost closed this as completed Nov 23, 2022
@ghost
Copy link

ghost commented Nov 23, 2022

This issue has been marked as external. It has been automatically closed for housekeeping purposes.

@ninmonkey
Copy link
Author

Weird, I have force clear off. here's some settings

settings.json .
terminal.integrated.persistentSessionReviveProcess never
terminal.integrated.allowChords true
terminal.integrated.sendKeybindingsToShell true
powershell.integratedConsole.forceClearScrollbackBuffer false

New debug tool -- Easier virtual environments

Recent patches make it a lot easier to create mini-virtual environments, without doing anything crazy.

[object[]]$c_args = '--extensions-dir', $addons_dir, '--user-data-dir', $user_data_dir, '--profile', 'pwsh-debug', '--add', (Get-Item $Path)
& code.cmd @c_args

don't have a custom ClearScreen implementation any more, unl
unless it lintercepts that...(and what are we doing either way?)

The description mentions the language server, maybe that's causing unexpected behavior?

Use the vscode API to clear the terminal since that's the only reliable way to clear the scrollback buffer. Turn this on if you're use to 'Clear-Host' clearing scroll history as wellclear-terminal-via-lsp.

I don't remember exactly why I have terminal.integrated.sendKeybindingsToShell enabled, my guess is it had to do with getting console keybings to work. Or it could be from when terminal panes were first movable into editor tabs -- Some or most of those aren't required anymore

  • alt+enter , shift+enter, ctrl+enter
  • ctrl+c, ctrl+v *in the past you had to prevent VSCode's binding for filepaths had non-ascii runes. Also when pasting multiple lines as a single command

What to Test?

Do you recommend anything I can test for?, for this issue or others? I can get more data on potential errors or traces and log captures -- If I know what to look for.

  • Do you know how to capture the ansi escapes being sent to the term?
  • I wanted to dig into them for clues on whether the prompt-location-ansi-escapes were being generated as expected, or if it was coming from another level

So I'm wondering where to start, I think

  • I'd need to build the dotnet c# Pwsh SDK, to be able to inspect what PSReadLine is doing ?
  • Or by running and building the vs-code typescript extension
  • Or jumping into the language server

for completeness here's some loosely related settings

settings.json .
terminal.integrated.smoothScrolling True
powershell.integratedConsole.focusConsoleOnExecute True
powershell.integratedConsole.forceClearScrollbackBuffer False
powershell.integratedConsole.showOnStartup True
powershell.integratedConsole.useLegacyReadLine False
terminal.integrated.allowChords True
terminal.integrated.customGlyphs True
terminal.integrated.sendKeybindingsToShell True
terminal.integrated.shellIntegration.history 200
terminal.integrated.shellIntegration.decorationsEnabled both
terminal.integrated.defaultLocation editor
terminal.integrated.persistentSessionReviveProcess never
powershell.helpCompletion BlockComment

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Extension Terminal Issue-Bug A bug to squash. Resolution-External Will close automatically.
Projects
None yet
Development

No branches or pull requests

3 participants