8000 Fix help paging issues on macOS/Linux and with custom pager that takes arguments by rkeithhill · Pull Request #9033 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
TravisEz13 merged 6 commits intoPowerShell:masterfrom
rkeithhill:rkeithhill/fix-help-formatting-for-less
Apr 10, 2019
Merged

Fix help paging issues on macOS/Linux and with custom pager that takes arguments#9033
TravisEz13 merged 6 commits intoPowerShell:masterfrom
rkeithhill:rkeithhill/fix-help-formatting-for-less

Conversation

@rkeithhill
Copy link
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

This fixes PowerShell#7175 by using Out-String to properly wrap text before
sending to less or the user specified PAGER.
@rkeithhill 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
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.

Copy link
Collaborator Author
@rkeithhill rkeithhill Mar 3, 2019

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

Copy link
Contributor
@RDIL RDIL left a comment

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
Collaborator
vexx32 commented Mar 4, 2019

@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
Collaborator
vexx32 commented Mar 4, 2019

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
Collaborator Author

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

@iSazonov
Copy link
Collaborator
iSazonov commented Mar 9, 2019

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

@pougetat
Copy link

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

@stale
Copy link
stale bot commented Apr 9, 2019

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
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 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 iSazonov added this to the 7.0.0-preview.1 milestone Apr 9, 2019
@iSazonov iSazonov requested a review from SteveL-MSFT April 9, 2019 17:44
$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
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
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
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
Collaborator Author

Choose a reason for hiding this comment

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

Done

7D46 Copy link
Member
@TravisEz13 TravisEz13 left a comment

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 TravisEz13 merged commit d05737a into PowerShell:master Apr 10, 2019
@iSazonov
Copy link
Collaborator

@rkeithhill Thanks for fixing the paging issues.

@rkeithhill rkeithhill deleted the rkeithhill/fix-help-formatting-for-less branch May 5, 2019 18:14
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

0