Skip to content

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

Merged
merged 1 commit into from
Nov 3, 2021

Conversation

andyleejordan
Copy link
Member

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?

@andyleejordan
Copy link
Member Author

Fixes #840 for the preview.

…Interface`

These changes were accidentally forgotten in the rewrite and needed to
be added back.
@SeeminglyScience
Copy link
Collaborator

@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.

@andyleejordan
Copy link
Member Author

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).

@SeeminglyScience
Copy link
Collaborator

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.

@andyleejordan
Copy link
Member Author

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);
        }
    }
}

@andyleejordan andyleejordan merged commit bb542fe into master Nov 3, 2021
@andyleejordan andyleejordan deleted the andschwa/fix-1603 branch November 3, 2021 20:11
@andyleejordan
Copy link
Member Author

Part of #1677

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Changes from #1571 are missing from preview
2 participants