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

get-history | Out-ConsoleGridView with multi-line commands causes issues #58

Closed
tig opened this issue Mar 11, 2020 · 15 comments
Closed
Labels
bug Something isn't working Module-ConsoleGuiTools This issue is about Microsoft.PowerShell.ConsoleGuiTools

Comments

@tig
Copy link
Collaborator

tig commented Mar 11, 2020

Start with:

$someJson = @'
{
   "foo" : true
}
'@

Then

get-history | Out-ConsoleGridView

Results in something ugly like this:

image

Powershell 7.0.

@tig tig changed the title get-history with multi-line commands causes issues get-history | Out-ConsoleGridView with multi-line commands causes issues Mar 11, 2020
@TylerLeonhardt TylerLeonhardt added bug Something isn't working Module-ConsoleGuiTools This issue is about Microsoft.PowerShell.ConsoleGuiTools labels Mar 11, 2020
@TylerLeonhardt
Copy link
Member

Looks like we just need to check if there are any newlines in the string here
https://github.com/PowerShell/GraphicalTools/blob/2aac3357e17e2f09b771cf4a49614fd02adcce96/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs#L168-L176

and add an "..." just like the output of Get-History does.

if (strings[i].Contains(Environment.NewLine)
{
    builder.Append(strings[i].Split(Environment.NewLine)[0]);
    builder.Append("...");
}

@TylerLeonhardt
Copy link
Member

@tig any interest in contributing?

@tig
Copy link
Collaborator Author

tig commented Mar 11, 2020

Maybe. I have source cloned and can build ;-).

Noted Contribution Guide is 404: https://powershell.github.io/GraphicalTools/CONTRIBUTING.html

Also, can you point me at instructions for how to debug this using VS code?

I set a BP on the line you pointed to and hit Debug in Code but hit issues that I don't understand (noob at using VS Code to debug; I generally use VS Studio).

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Mar 11, 2020

apologies for the 404! I'll get that fixed.

@tig take a look at this section of the README for building.

In order to debug in VS Code, start a PowerShell process and import your local build of ConsoleGuiTools. Then in VS Code with the repo opened, go to the debug pane and select ".NET Core Attach" and hit play or F5. Then attach to the pwsh process that imported the module.

Once you run Out-ConsoleGridView, your breakpoint should get hit.

@tig
Copy link
Collaborator Author

tig commented Mar 11, 2020

How do I know which process is which?

image

@tig
Copy link
Collaborator Author

tig commented Mar 11, 2020

Nevermind. Found it $pid.

@tig
Copy link
Collaborator Author

tig commented Mar 11, 2020

Is there some way to not have to kill the Windows Terminal session hosting pwsh every build/debug cycle? I've tried just starting a pwsh.exe instance from the command line, but that doesn't seem to free up the loaded cmdlet. I have to kill Terminal.

@TylerLeonhardt
Copy link
Member

You have to kill the pwsh.exe that imported the module because dlls can't be unloaded.

What I usually do is:

  • open pwsh.exe
  • in that pwsh.exe, run pwsh (thus nesting powershell)
  • import the module and do debugging
  • run exit to exit the nested PowerShell and run pwsh again

That way your window doesn't close... just the pwsh process within.

@tig
Copy link
Collaborator Author

tig commented Mar 11, 2020

Ready to do a PR. before I do, here's the strategy I took...

Your suggestion was to check for Environment.Newline and just do an ellipsis.

First, in my example (not sure of others where there's multi-line commands) I'm seeing only \n' and not \r\nasEnvironment.NewLineas defined for Windows. So I am checking for\n` only.

Second, just appending an ellipsis to the line is not very satisfyingly. In my example this would result in the command being displayed as:

$someJson = @'

Instead, I'm doing this:

            strings[i] = strings[i].Replace("\n", @"\n");

            // If the string won't fit in the column, append an ellipsis.
            if (strings[i].Length > colWidths[i])
            {

Which lets the 'command too long' code deal gracefully with a command where newlines are encoded with the escape sequence.

Thus the output looks like this:

image

Cool?

@SteveL-MSFT
Copy link
Member

I think following PowerShell syntax, it may make more sense to replace \n with `n. Otherwise, this seems like a good improvement.

@TylerLeonhardt
Copy link
Member

I agree with @SteveL-MSFT

@tig
Copy link
Collaborator Author

tig commented Mar 11, 2020

Got it. Found https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_special_characters?view=powershell-7

tig added a commit to tig/GraphicalTools that referenced this issue Mar 11, 2020
tig added a commit to tig/GraphicalTools that referenced this issue Mar 11, 2020
@iSazonov
Copy link

"\r" and "\n" are not single control codes. Ideally we should escape output sting and mask all control characters and escape sequences.

@tig
Copy link
Collaborator Author

tig commented Mar 12, 2020

"\r" and "\n" are not single control codes. Ideally we should escape output sting and mask all control characters and escape sequences.

I actually tried that (using Regex.Escape) and it didn't work well. That said, Regex.Escape uses c/c++ style escaping, not PowerShell style. I vote leave it as-is for now as it fixes the UI-breaking problem caused by newlines.

@TylerLeonhardt
Copy link
Member

Yes, we can be iterative here and fix the newline characters first since they will be seen a lot more than others

TylerLeonhardt added a commit that referenced this issue Apr 18, 2020
* Fixed #58: Multi-line commands rendering wrong

* Fixed #58 - Newlines in commands render incorrectly

* Added debug instructions to readme

* Update src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Co-Authored-By: Tyler James Leonhardt <tylerl0706@gmail.com>

* simplified stripping of newline/linefeed

* fixes Filter TextView and Apply button don't honor horizontal resizing

* reverted move to terminal.gui 0.81.0

Co-authored-by: Tyler James Leonhardt <tylerl0706@gmail.com>
TylerLeonhardt added a commit that referenced this issue Apr 18, 2020
* Fixed #58: Multi-line commands rendering wrong

* Fixed #58 - Newlines in commands render incorrectly

* Added debug instructions to readme

* Update src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Co-Authored-By: Tyler James Leonhardt <tylerl0706@gmail.com>

* simplified stripping of newline/linefeed

* Upgrading to Terminal.gui 0.81.0 and its depencency on Nstack 0.14.0

Co-authored-by: Tyler James Leonhardt <tylerl0706@gmail.com>
TylerLeonhardt added a commit that referenced this issue Apr 19, 2020
* Fixed #58: Multi-line commands rendering wrong

* Fixed #58 - Newlines in commands render incorrectly

* Added debug instructions to readme

* Update src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Co-Authored-By: Tyler James Leonhardt <tylerl0706@gmail.com>

* simplified stripping of newline/linefeed

* fixed exit UI via StatusBar instead of Menu

* fixes Filter TextView and Apply button don't honor horizontal resizing

* removed commented out code

* Add StatusBar label explainging that SPACE Marks Items

* fixed spelling of delegate

* removed Apply button

Co-authored-by: Tyler James Leonhardt <tylerl0706@gmail.com>
TylerLeonhardt added a commit that referenced this issue May 13, 2020
* Fixed #58: Multi-line commands rendering wrong

* Fixed #58 - Newlines in commands render incorrectly

* Added debug instructions to readme

* Update src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Co-Authored-By: Tyler James Leonhardt <tylerl0706@gmail.com>

* simplified stripping of newline/linefeed

* ENTER now moves to list if on filter

Co-authored-by: Tyler James Leonhardt <tylerl0706@gmail.com>
TylerLeonhardt added a commit that referenced this issue Sep 27, 2020
* Fixed #58: Multi-line commands rendering wrong

* Fixed #58 - Newlines in commands render incorrectly

* Added debug instructions to readme

* Update src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Co-Authored-By: Tyler James Leonhardt <tylerl0706@gmail.com>

* simplified stripping of newline/linefeed

* fixes to support gui.cs 0.89.3

* enhanced docs

* formatting

* partialy updated docs

Co-authored-by: Tyler James Leonhardt <tylerl0706@gmail.com>
TylerLeonhardt added a commit that referenced this issue Sep 27, 2020
* Fixed #58: Multi-line commands rendering wrong

* Fixed #58 - Newlines in commands render incorrectly

* Added debug instructions to readme

* Update src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Co-Authored-By: Tyler James Leonhardt <tylerl0706@gmail.com>

* simplified stripping of newline/linefeed

* fixes to support gui.cs 0.89.3

* enhanced docs

* formatting

* partialy updated docs

* fixed Single mode

* fixed bug with filtering

* updated build to also run ocgv

* fixed f7 docs

* fixed comment regarding selection mode formatting

Co-authored-by: Tyler James Leonhardt <tylerl0706@gmail.com>
TylerLeonhardt added a commit that referenced this issue Sep 28, 2020
* Fixed #58: Multi-line commands rendering wrong

* Fixed #58 - Newlines in commands render incorrectly

* Added debug instructions to readme

* Update src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Co-Authored-By: Tyler James Leonhardt <tylerl0706@gmail.com>

* simplified stripping of newline/linefeed

* fixes to support gui.cs 0.89.3

* enhanced docs

* formatting

* partialy updated docs

* fixed Single mode

* fixed bug with filtering

* updated build to also run ocgv

* fixed f7 docs

* fixed comment regarding selection mode formatting

* Adds -Filter

* undid spell check cahnge

* undid spell check cahnge

* undid spell check cahnge

* removed orig file

* per tylers feedback

* updated .md

* fixed md

* Updated to pull FINAL gui.cs v0.90 release

* updated psd to 0.60.0 and added release notes

* fixed typo; added tags; hopefully this will unsick the mac build

* fixed another typo

Co-authored-by: Tyler James Leonhardt <tylerl0706@gmail.com>
TylerLeonhardt added a commit that referenced this issue Sep 29, 2020
* Fixed #58: Multi-line commands rendering wrong

* Fixed #58 - Newlines in commands render incorrectly

* Added debug instructions to readme

* Update src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Co-Authored-By: Tyler James Leonhardt <tylerl0706@gmail.com>

* simplified stripping of newline/linefeed

* update to new Terminal.gui package; no code changes

Co-authored-by: Tyler James Leonhardt <tylerl0706@gmail.com>
TylerLeonhardt added a commit that referenced this issue Oct 3, 2020
* Fixed #58: Multi-line commands rendering wrong

* Fixed #58 - Newlines in commands render incorrectly

* Added debug instructions to readme

* Update src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Co-Authored-By: Tyler James Leonhardt <tylerl0706@gmail.com>

* simplified stripping of newline/linefeed

* made column spacing tigher

* update to new Terminal.gui package; no code changes

* removed excess padding on right

* removed excess rows at bottom

* status bar wsa occluding window

* fixed build scripts to only build ocgv

* use built-in command in build.ps1

* fixed the other one too

Co-authored-by: Tyler James Leonhardt <tylerl0706@gmail.com>
andyleejordan added a commit that referenced this issue Aug 22, 2022
* Fixed #58: Multi-line commands rendering wrong
* Fixed #58 - Newlines in commands render incorrectly
* Added debug instructions to readme
* simplified stripping of newline/linefeed
* made column spacing tighter
* removed excess padding on right
* removed excess rows at bottom
* status bar wsa occluding window
* fixed build scripts to only build ocgv
* refactored to make logic more obvious
* removed orig files
* Updated references to latest Terminal.Gui
* Fixed #131 and upgraded to terminal.gui 1.6, pwsh 7.2, and net60
* supported .net and reverted change
* Fixes #131 - Out-ConsoleGridView doesn't handle ANSI escape sequences correctly
* removed border when minui is enabled
* re-implemented feature post merge screw up
* improve VS code build and debug support
* On exit, ensure only visible marked items are output
* Fixes 87
* Fixing crash when MinUi PR is merged
* Tweaked build to have a better test at end
* removed merge artifacts
* exclude .orig files (merge artifacts)

Co-authored-by: Tyler James Leonhardt <tylerl0706@gmail.com>
Co-authored-by: Andy Jordan <2226434+andschwa@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Module-ConsoleGuiTools This issue is about Microsoft.PowerShell.ConsoleGuiTools
Projects
None yet
Development

No branches or pull requests

4 participants