Skip to content

Fix help paging issues on macOS/Linux and with custom pager that takes arguments - #9033

Merged
Travis Plunk (TravisEz13) merged 6 commits into
PowerShell:masterfrom
rkeithhill:rkeithhill/fix-help-formatting-for-less
Apr 10, 2019
Merged

Travis Plunk (TravisEz13) merged 6 commits into
PowerShell:masterfrom
rkeithhill:rkeithhill/fix-help-formatting-for-less

Conversation

@rkeithhill

Copy link
Copy Markdown
Collaborator

PR Summary

Fix #7175 by using Out-String -Stream -Width before piping to an application. This improves the help experience on macOS and Linux by ensuring lines of help text wrap properly for the given console width.

Fix #8912 by using the PS tokenizer to separate the pager command from arguments if both are specified in $env:PAGER. Also ensures that there is no PowerShell interpretation of arguments to an application by using the stop parsing operator.

PR Context

The current reading experience of all help topics on macOS and Linux is sub-par giving PowerShell Core a bit of a black eye on those platforms. See #7175 for images of what this looks like.

Specify a custom pager with arguments works in v6.1 but is broken in v6.2. This PR fixes this issue - #8912.

PR Checklist

@rkeithhill
Keith Hill (rkeithhill) force-pushed the rkeithhill/fix-help-formatting-for-less branch from c29f5d7 to 790d2e3 Compare March 3, 2019 08:23
# Tokenize the specified $env:PAGER value. Ignore tokenizing errors since any errors may be valid
# argument syntax for the paging utility.
$errs = $null
$tokens = [System.Management.Automation.PSParser]::Tokenize($env:PAGER, [ref]$errs)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect that Tokenizer is very fast and more fast than Get-Command. So we could always call it and then Get-Command. This simplify code.
We need look $errs and write useful message to user.
Also we could use try-catch for Get-Command and running the command to write more useful messages to user.

@rkeithhill Keith Hill (rkeithhill) Mar 3, 2019 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should expose tokenizer errors. We are only using the tokenizer when piping help output to applications. The arguments passed to those applications could very well fail to tokenize by PowerShell. For instance, say an app took an argument like @{HEAD-1}, perfectly valide for the app but gens a tokenizer error:

Missing '=' operator after key in hash literal.

For debugging, I propose we leave the __PSPAGER_ARGS env var so the user can inspect it to see exactly what args we are passing to a pager application.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should expose tokenizer errors.

No expose. I think we could use this to create more useful message to user if it is possible.

@RDIL Reece Dunham (RDIL) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSharp brace style issues

@vexx32

Copy link
Copy Markdown
Collaborator

Reece Dunham (@RDIL) all of those are within a string which is actually PowerShell embedded into the C# code, so they should follow PowerShell style. :)

@vexx32

Copy link
Copy Markdown
Collaborator

If for nothing else, because it'll help you pick all the nuances up that much faster! 🙂

I had to triple check that, too, because something didn't look quite right, so don't feel bad. I stared at it for a good ten minutes before I realized what was going on. 😄

@rkeithhill

Copy link
Copy Markdown
Collaborator Author

I suppose it is unlikely that this will make it in for the 6.2 release, eh?

@iSazonov

Copy link
Copy Markdown
Collaborator

Yes, GA-6.2 was already forked. In next milestone perhaps we'll convert the function to cmdlet.

@pougetat

Copy link
Copy Markdown

Keith Hill (@rkeithhill) Sorry about this one. I see your PR will fix the issue I introduced.

@stale

stale Bot commented Apr 9, 2019

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days.
Thank you for your contributions.
Community members are welcome to grab these works.

@stale stale Bot added the Stale label Apr 9, 2019
@rkeithhill

Copy link
Copy Markdown
Collaborator Author

This PR needs some more review and to be targeted for some milestone - 6.2.1 or 7. I do not wish to see this closed as it addresses a real issue.

@stale stale Bot removed the Stale label Apr 9, 2019
@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Apr 9, 2019
@iSazonov Ilya (iSazonov) added this to the 7.0.0-preview.1 milestone Apr 9, 2019
$customPagerCommand = $tokens[0].Content
if (!(Get-Command $customPagerCommand -ErrorAction Ignore)) {
# Custom pager command is invalid, issue a warning.
Write-Warning ""Ignoring invalid custom-paging utility command line specified in `$env:PAGER: $env:PAGER""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more that it was not found? Can we update the message?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can update the message. How about: ""Custom-paging utility command not found. Ignoring command specified in `$env:PAGER: $env:PAGER""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that looks better.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@TravisEz13 Travis Plunk (TravisEz13) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one minor issue. Tell me if you want me to address it before I merge.

@TravisEz13
Travis Plunk (TravisEz13) merged commit d05737a into PowerShell:master Apr 10, 2019
@iSazonov

Copy link
Copy Markdown
Collaborator

Keith Hill (@rkeithhill) Thanks for fixing the paging issues.

@rkeithhill
Keith Hill (rkeithhill) deleted the rkeithhill/fix-help-formatting-for-less branch May 5, 2019 18:14
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
…s arguments (PowerShell#9033)

* Pipe help system output through Out-String -Width when not using more

This fixes PowerShell#7175 by using Out-String to properly wrap text before
sending to less or the user specified PAGER.

* Set the string output width when sending help to pager app

Fix PowerShell#7175

* Fix PowerShell#8912 by using PS tokenize to get custom pager cmd & args

* Fix macOS/Linux test failures

* It appears that while running in tests, ConsoleWidth is 0, set min val

* Address PR feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passing parameters to $env:PAGER is broken in 6.2.0-preview.4 Line wrapping in PS Core in-the-box help does not indent appropriately

7 participants