vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Enable PSReadline support in the integrated console (syntax highlighting, keyboard navigation)

Open daviwil opened this issue 9 years ago • 133 comments

PSReadline is not supported in the integrated console at this time. A non-trivial amount of work is needed to make PowerShell Editor Services and PSReadline play nicely together so this could take some time.

Features this will enable:

  • Ctrl+Arrow keys, etc (keyboard navigation of the input line)
  • Syntax highlighting of input text
  • Multi-line text input (writing a function definition in the console across multiple lines)

daviwil avatar Mar 14 '17 14:03 daviwil

Same "endless prompt loop" with that build.

sba923 avatar Oct 03 '18 04:10 sba923

@rjmholt I went ahead and VPN'd to my work computer and it works just fine even with 6.0.2. Not sure why my home PC wasn't cooperating.

Work computer info: "powershell.powerShellExePath": "C:\Program Files\PowerShell\6.0.2\pwsh.exe",

Name                           Value
----                           -----
PSVersion                      5.1.15063.1155
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.15063.1155
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


    Directory: C:\Users\XXXXX\.vscode-insiders\extensions\ms-vscode.powershell-2.0.0\modules\PowerShellEditorServices\bin


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        10/2/2018  11:58 PM                6.0
d-----        10/2/2018  11:58 PM                Desktop
-a----        10/2/2018  11:58 PM           9052 libdisablekeyecho.dylib
-a----        10/2/2018  11:58 PM           8840 libdisablekeyecho.so
-a----        10/2/2018  11:58 PM         396800 Microsoft.PowerShell.EditorServices.dll
-a----        10/2/2018  11:58 PM          35328 Microsoft.PowerShell.EditorServices.Host.dll
-a----        10/2/2018  11:58 PM           8572 Microsoft.PowerShell.EditorServices.Host.pdb
-a----        10/2/2018  11:58 PM         129100 Microsoft.PowerShell.EditorServices.pdb
-a----        10/2/2018  11:58 PM         252416 Microsoft.PowerShell.EditorServices.Protocol.dll
-a----        10/2/2018  11:58 PM          69612 Microsoft.PowerShell.EditorServices.Protocol.pdb
-a----        10/2/2018  11:58 PM         639488 Newtonsoft.Json.dll
-a----        10/2/2018  11:58 PM         118272 Serilog.dll
-a----        10/2/2018  11:58 PM           8704 Serilog.Sinks.Async.dll
-a----        10/2/2018  11:58 PM          31744 Serilog.Sinks.Console.dll
-a----        10/2/2018  11:58 PM          26624 Serilog.Sinks.File.dll
-a----        10/2/2018  11:58 PM           4096 UnixConsoleEcho.dll


    Directory: C:\Users\XXXXX\.vscode-insiders\extensions\ms-vscode.powershell-2.0.0\modules\PowerShellEditorServices\bin\6.0


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        10/2/2018  11:58 PM          29840 System.IO.Pipes.AccessControl.dll
-a----        10/2/2018  11:58 PM         104584 System.Security.AccessControl.dll
-a----        10/2/2018  11:58 PM          82576 System.Security.Principal.Windows.dll


    Directory: C:\Users\XXXXX\.vscode-insiders\extensions\ms-vscode.powershell-2.0.0\modules\PowerShellEditorServices\bin\Desktop


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        10/2/2018  11:58 PM          25744 System.IO.Pipes.AccessControl.dll
-a----        10/2/2018  11:58 PM          39048 System.Security.AccessControl.dll
-a----        10/2/2018  11:58 PM          23688 System.Security.Principal.Windows.dll

VSCode Info
Version: 1.28.0-insider (system setup)
Commit: 85d970acdee48f6dcecf909a0faeb3c6882217a9
Date: 2018-10-02T22:27:52.997Z
Electron: 2.0.9
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

scotthardwick avatar Oct 03 '18 05:10 scotthardwick

I have been trying it out all morning at work and it is FANTASTIC. Thanks to all who put their hard work into this. I must admit that the missing ability to paste multi-line code into VSCode's terminal had really been keeping me unhappy and wandering back to ISE, so this really makes my day.

A few minor and not really critical (to me) questions about a few of the KeyHandler functions. Should CopyOrCancelLine, AddLine, BackwardDeleteLine, ForwardDeleteLine, ScrollDisplayUpLine, and ScrollDisplayDownLine be working?

CopyOrCancelLine - I get ^C AddLine - Just acts like AcceptLine aka Enter BackwardDeleteLine - Takes me to the top of the terminal history (hijacked somewhere by another shortcut?) ForwardDeleteLine - Does nothing ScrollDisplayUpLine - scrolls up a screen instead of a line ScrollDisplayDownLine - scrolls down a screen instead of a line

Oh and note that oddly ScrollDisplayDown will let you keep going page after page beyond your actual terminal text and then you have to page up just as many to get back!

Again, many thanks to everyone! I have been telling all my coworkers it is time to finally ditch ISE forever now.

scotthardwick avatar Oct 03 '18 17:10 scotthardwick

If you want Back/ForwardDeleteLine to work, add this to your keybindings.json file:

    {
        "key": "ctrl+home",
        "command": "-workbench.action.terminal.scrollToTop",
        "when": "terminalFocus"
    },
    {
        "key": "ctrl+end",
        "command": "-workbench.action.terminal.scrollToBottom",
        "when": "terminalFocus"
    }

For ScrollDisplayUp/DownLine, I just the built-in kbd shortcuts ctrl+alt+PageUp/Down. In theory, you could use these keybindings to make ctrl+PageUp/Down work but the ctrl is not getting through, so PSRL sees just PageUp/Down.

    {
        "key": "ctrl+pageup",
        "command": "-workbench.action.previousEditor"
    },
    {
        "key": "ctrl+pageup",
        "command": "workbench.action.previousEditor",
        "when": "!terminalFocus"
    },
    {
        "key": "ctrl+pageup",
        "command": "-workbench.action.previousEditor"
    },
    {
        "key": "ctrl+pagedown",
        "command": "workbench.action.nextEditor",
        "when": "!terminalFocus"
    }

The same happens with AddLine - only the Enter is getting to PSRL. You can see this by pressing Alt+Shift+/ and then pressing any keyboard chord. PSRL will tell you what it sees.

BTW this all happens in the regular PowerShell integrated terminal w/PSRL so it's not specific to PSIC.

rkeithhill avatar Oct 05 '18 01:10 rkeithhill

Working fairly well for me, FYI here are the settings to get the PSReadline terminal to match the default Dark+ theme, and match the default powershell console colors otherwise (I commented out background to match most themes more easily)

Should I submit this to be default as a separate PR (for Dark+ at least)? Would make it look a lot cleaner and better for new users for a seamless experience.

"workbench.colorCustomizations": {
    "[Default Dark+]": {
        //Dark+ Console Theme
        //"terminal.background": "#0c0c0c",
        "terminal.ansiBlack": "#000000",
        "terminal.ansiBlue": "#569cd6",
        "terminal.ansiGreen": "#608b4e",
        "terminal.ansiCyan": "#ce9178",
        "terminal.ansiRed": "#f44747",
        "terminal.ansiMagenta": "#646695",
        "terminal.ansiYellow": "#d7ba7d",
        "terminal.ansiWhite": "#d4d4d4",
        "terminal.ansiBrightBlack": "#808080",
        "terminal.ansiBrightBlue": "#9cdcfe",
        "terminal.ansiBrightGreen": "#b5cea8",
        "terminal.ansiBrightCyan": "#4EC9B0",
        "terminal.ansiBrightRed": "#d16969",
        "terminal.ansiBrightMagenta": "#c586c0",
        "terminal.ansiBrightYellow": "#dcdcaa",
        "terminal.ansiBrightWhite": "#d4d4d4",
    },
    //"terminal.background": "#012456",
    "terminal.foreground": "#cccccc",
    "terminal.ansiBlack": "#0c0c0c",
    "terminal.ansiBlue": "#0037da",
    "terminal.ansiGreen": "#13a10e",
    "terminal.ansiCyan": "#3a96dd",
    "terminal.ansiRed": "#c50f1f",
    "terminal.ansiMagenta": "#881798",
    "terminal.ansiYellow": "#c19c00",
    "terminal.ansiWhite": "#cccccc",
    "terminal.ansiBrightBlack": "#767676",
    "terminal.ansiBrightBlue": "#3b78ff",
    "terminal.ansiBrightGreen": "#16c60c",
    "terminal.ansiBrightCyan": "#61d6d6",
    "terminal.ansiBrightRed": "#e74856",
    "terminal.ansiBrightMagenta": "#b4009e",
    "terminal.ansiBrightYellow": "#f9f1a5",
    "terminal.ansiBrightWhite": "#f2f2f2",
},

"editor.tokenColorCustomizations": {
    "[Default Dark+]": {
        "comments": "#608b4e"
    }
},

JustinGrote avatar Oct 06 '18 02:10 JustinGrote

Hi everyone, we now have an AppVeyor artefact that you can download directly here.

To get the most up-to-date build of the 2.0.0 extension, go to the branches page, and next to the 2.0.0 branch there should be a green ✔️. Click on that and on the right of the AppVeyor build there should be a Details link. Click on that and on the new screen above the console there should be an Artifacts tab. That will have the latest VSIX in it. I can't give a generic link to that, since it's build-specific, but hopefully you'll be able to find it.

We're still exploring the best way to have a "release" of the v2 extension while still (1) honouring our commitment to have a support window for the 1.x extension and (2) continuing to do work that we could only do with a major version increment before stabilising it.

rjmholt avatar Oct 09 '18 02:10 rjmholt

I hate to say, but the "endless Enter loop" issue is still there with that 2.0.0 candidate...

sba923 avatar Oct 09 '18 05:10 sba923

Yes, it's the same build. But now builds will be available in a consistent place as soon as they are committed rather than requiring a manual build.

@sba923 To solve the endless loop, we'll need more information to reproduce it. I hit it once, but it resolved. Can you please open a new issue for the looping problem and provide the system information described in the troubleshooting doc.

rjmholt avatar Oct 09 '18 05:10 rjmholt

thanks, @rjmholt!!

scrthq avatar Oct 09 '18 05:10 scrthq

That package seems to contain errors?

From the log file... 2018-10-09 10:05:59 - Microsoft.VisualStudio.ExtensionManager.InvalidExtensionManifestException: Element 'Identity' has invalid value for attribute 'Version' ---> System.FormatException: Input string was not in a correct format. at System.Version.VersionResult.SetFailure(ParseFailureKind failure, String argument)

pezmannen avatar Oct 09 '18 08:10 pezmannen

@pezmannen To install it in VSCode press F1 and start typing Install from VSIX.

SeeminglyScience avatar Oct 09 '18 11:10 SeeminglyScience

@pezmannen seems like Version contains a semver which isn't a valid System.Version

SteveL-MSFT avatar Oct 10 '18 02:10 SteveL-MSFT

@pezmannen VSCode shares its file extension (.vsix) with Visual Studio. On Windows, running it from the browser or executing it directly will attempt to load it into Visual Studio, which will fail since the actual format is different.

To install the VSIX in VSCode, you need to either

  • Run code --install-extension ./path/to/PowerShell-insiders.vsix from PowerShell
  • Open VSCode, press F1 and type Install from VSIX
  • Use the ... context menu under VSCode's Extensions view and select Install from VSIX...

The link in this comment has further instructions.

rjmholt avatar Oct 10 '18 03:10 rjmholt

I've opened #1570 about the endless prompt loop.

sba923 avatar Oct 10 '18 04:10 sba923

Hi everyone, we now have an AppVeyor artefact that you can download directly here.

To get the most up-to-date build of the 2.0.0 extension, go to the branches page, and next to the 2.0.0 branch there should be a green ✔️. Click on that and on the right of the AppVeyor build there should be a Details link. Click on that and on the new screen above the console there should be an Artifacts tab. That will have the latest VSIX in it. I can't give a generic link to that, since it's build-specific, but hopefully you'll be able to find it.

We're still exploring the best way to have a "release" of the v2 extension while still (1) honouring our commitment to have a support window for the 1.x extension and (2) continuing to do work that we could only do with a major version increment before stabilising it.

@rjmholt Do both the 1.9.x and 2.x insider releases support PSReadLine? I see there are frequent releases of the 1.9.x branch but the 2.x hasn't seen an updated build since some time in October. I guess my question should be, "Which branch should be be testing if we want to work with PSReadLine support?"

gwojan avatar Nov 29 '18 18:11 gwojan

TL;DR:

Which branch should be be testing if we want to work with PSReadLine support?

2.0.0


Only 2.0.0 supports PSReadLine, because supporting PSReadLine involves breaking changes. It is the reason there is a 2.0.0 branch.

The 2.0.0 branch is downstream of the 1.x/master branch -- the changes in master will come into 2.0.0, but that work needs to be done manually and I'm currently juggling a few other things. I'm hoping to work on that in the next couple of weeks.

rjmholt avatar Nov 29 '18 18:11 rjmholt

I've tested the build from https://ci.appveyor.com/api/buildjobs/ma1a8og5h1d0g5cu/artifacts/PowerShell-insiders.vsix and I still get the "endless loop on prompt" behavior...

sba923 avatar Nov 29 '18 19:11 sba923

TL;DR:

Which branch should be be testing if we want to work with PSReadLine support?

2.0.0

Only 2.0.0 supports PSReadLine, because supporting PSReadLine involves breaking changes. It is the reason there is a 2.0.0 branch.

@rjmholt Awesome! I've installed the latest v.2.0 build and it looks like it's fixed a couple of issues I was having with Vi mode. 😄

Is there any chance we'll get support for chords like Ctrl+Shift+Esc?

gwojan avatar Nov 30 '18 14:11 gwojan

@gwojan, ah I’m also a Vi mode user but because it’s less popular and quite different, it’s got a few more kinks in it.

PSReadLine itself lives here. Fixes and features in the actual PSReadLine experience come from there.

rjmholt avatar Nov 30 '18 16:11 rjmholt

@gwojan, ah I’m also a Vi mode user but because it’s less popular and quite different, it’s got a few more kinks in it.

PSReadLine itself lives here. Fixes and features in the actual PSReadLine experience come from there.

@rjmholt Thanks. I keep mine updated with the latest and greatest. 😉

BTW, I opened a new issue after installing the v2.0 extension this morning Node module infected with trojan.

gwojan avatar Nov 30 '18 16:11 gwojan