Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
andyleejordan merged 1 commit into master from andschwa/fix-1603
Nov 3, 2021

Conversation

@andyleejordan
Copy link
Member

@andyleejordan andyleejordan commented Oct 29, 2021

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?

SeeminglyScience reacted with heart emoji
Copy link
Member Author

Fixes #840 for the preview.

...Interface`
These changes were accidentally forgotten in the rewrite and needed to
be added back.
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.

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

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.

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);
 }
 }
}
SeeminglyScience reacted with thumbs up emoji

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

Reviewers

@rjmholt rjmholt Awaiting requested review from rjmholt

@SeeminglyScience SeeminglyScience Awaiting requested review from SeeminglyScience

Assignees

No one assigned

Projects

No open projects
Status: Done

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Changes from #1571 are missing from preview

AltStyle によって変換されたページ (->オリジナル) /