-
Notifications
You must be signed in to change notification settings - Fork 240
Add LengthInBufferCells back to EditorServicesConsolePSHostRawUserInterface
#1606
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
Conversation
Fixes #840 for the preview.
...Interface` These changes were accidentally forgotten in the rewrite and needed to be added back.
d39f0f7 to
474b850
Compare
@SeeminglyScience Do you know how we could add a regression test for this?
Do we have any tests where we have a PSHost that wraps SMA's ConsoleHost?
If yes, then running something like this:
[pscustomobject]@{ a = "`e[30mtest`e[0m" } | Format-Table @{ Width = 4; Expression = 'a' } | Out-Default
and then reading what is sent to PSHost.UI.WriteLine, ensuring it does not include ellipses, would work. A bit awkward but doable.
and then reading what is sent to
PSHost.UI.WriteLine, ensuring it does not include ellipses, would work. A bit awkward but doable.
Any idea how to do this part? I've got a test that starts up everything and runs the command as if via F8 (so same as typing into the integrated console), but I can only seem to get the results. Not sure if that's going to be different than what PSHost.UI has. Also, I don't see ellipses in the Preview extension when I run this manually, but I do see 'test' being dropped (and it's there in a normal pwsh session).
Any idea how to do this part? I've got a test that starts up everything and runs the command as if via
F8(so same as typing into the integrated console), but I can only seem to get the results. Not sure if that's going to be different than what PSHost.UI has.
Yeah so when it hits the UI it'll have already gone through the formatter. The results are just the raw unformatted objects. For certain things you can also use Out-String as that'll also go through the formatter, but it eats ansi escape sequences and doesn't ask the host for buffer cell length.
Hm, well this is as far as I got with the test and I think I'm going to postpone getting a test for this so we can just get the fix in:
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using System.Collections.Generic; using System.Management.Automation; using System.Threading; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution; using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host; using Xunit; namespace Microsoft.PowerShell.EditorServices.Test.Console { public class PSHostTests : IDisposable { private readonly PsesInternalHost _psesHost; public PSHostTests() { _psesHost = PsesHostFactory.Create(NullLoggerFactory.Instance); } public void Dispose() { _psesHost.StopAsync().GetAwaiter().GetResult(); } [Trait("Category", "LengthInBufferCells")] [Fact] public void HasLengthInBufferCells() { var script = @"[pscustomobject]@{ a = ""`e[30mtest`e[0m"" } | Format-Table @{ Width = 4; Expression = 'a' } | Out-Default"; IReadOnlyList<string> results = _psesHost.InvokePSCommand<string>( new PSCommand().AddScript(script), new PowerShellExecutionOptions { WriteInputToHost = true, WriteOutputToHost = true, ThrowOnError = false, InterruptCurrentForeground = true }, CancellationToken.None); Assert.NotEmpty(results); } } }
Part of #1677
Fixes #1603.
These changes were accidentally forgotten in the rewrite and needed to be added back.
@SeeminglyScience Do you know how we could add a regression test for this?