-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix formatting, vt100 support, help uri and positional parameter issues for Markdown cmdlets #7329
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
Fix formatting, vt100 support, help uri and positional parameter issues for Markdown cmdlets #7329
Conversation
…meter issues for Markdown cmdlets * Formatting changes moved from types file to formatting file. * Add logic to check VT100 support before adding VT100 escape sequences. * Add online help uris. * Add positional parameters for Convert-FromMarkdown and Set-MarkdownOption
| public string FormatHeader2(string headerText) | ||
| { | ||
| return string.Concat(Esc, options.Header2, headerText, endSequence); | ||
| if (options.EnableVT100Encoding) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot of similar code, perhaps have a helper that does the EnableVT100Encoding check and concats or just returns the string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed for header types. For others the code is slightly different for each so kept it as is.
|
Usually we use [Alias("PSPath", "LP")]for LiteralPath parameters. |
iSazonov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a comment
| /// </summary> | ||
| protected override void BeginProcessing() | ||
| { | ||
| mdOption = SessionState.PSVariable.GetValue("MarkdownOptionInfo", new MarkdownOptionInfo()) as MarkdownOptionInfo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about "MarkdownOptionInfo" -> "PSMarkdownOptionInfo"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer MarkdownOptionInfo since the cmdlet is Get-MarkdownOption. @daxian-dbw your thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for any variables that are part of PowerShell itself, it should have the PS prefix to avoid name collision. So this should be PSMarkdownOptionInfo. cc @joeyaiello
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable MarkdownOptionInfo should be saved in the module scope of the Utility module, instead of the current scope of the current session state. Doing the latter will make the persistence of markdown option unreliable/inconsistent.
And, did you consider other options to persist the markdown option? I don't have an alternative off the top of my mind, but would like to check if you considered anything else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SteveL-MSFT if we agree it should be moved to the module state, does it matter?
As for persistence, I think it's okay to tell people to put this stuff in their profile until we hear why that's not good enough (seems to work just fine for PSReadline).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daxian-dbw The committee feedback was to have it in session state so it is valid throughout the session. The preferences can be set in profile for persistence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK to have it in session state, but it should be the module session state of Microsoft.PowerShell.Utility instead of the currently active session state, which could be the global session state or another module's session state. And the scope to save the variable should be the module scope, not the current scope.
For example, if I'm running Set-MarkdownOptions in a function from another module, then the variable will be saved in the function scope under the session state of that module, which will be lost once the function finishes execution.
|
👍 for positional parameter support. When |
|
@SteveL-MSFT please have another look. |
| { | ||
| mdOption = SessionState.PSVariable.GetValue("MarkdownOptionInfo", new MarkdownOptionInfo()) as MarkdownOptionInfo; | ||
|
|
||
| if (!this.Host.UI.SupportsVirtualTerminal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.Host can be null if the cmdlet is invoked in a runspace without a PSHost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
| /// </summary> | ||
| protected override void BeginProcessing() | ||
| { | ||
| mdOption = SessionState.PSVariable.GetValue("MarkdownOptionInfo", new MarkdownOptionInfo()) as MarkdownOptionInfo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for any variables that are part of PowerShell itself, it should have the PS prefix to avoid name collision. So this should be PSMarkdownOptionInfo. cc @joeyaiello
|
On macOS using the Terminal app, it doesn't seem to display the VT100 inverted sequence so the text becomes unreadable since the color is supposed to be black on inverted background but just appears as black. A basic web search doesn't find anything on how to support this so we may need to special case macOS to use some other colors. |
|
I take back part of what I said. Inverse works for Headers like # headerBut this only renders as black text on black background `text` |
|
@PaulHigin @SteveL-MSFT @daxian-dbw Please have another look. |
| protected override void BeginProcessing() | ||
| { | ||
| mdOption = SessionState.PSVariable.GetValue("MarkdownOptionInfo", new MarkdownOptionInfo()) as MarkdownOptionInfo; | ||
| mdOption = SessionState.PSVariable.GetValue("PSMarkdownOptionInfo", new PSMarkdownOptionInfo()) as PSMarkdownOptionInfo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as in #7329 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
| private const string Header6Dark = "[4;97m"; | ||
| private const string CodeDark = "[48;2;155;155;155;38;2;30;30;30m"; | ||
|
|
||
| private const string CodeMacOS = "[107;95m"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add a comment why we are special casing macOS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment.
| throw new InvalidOperationException(); | ||
| } | ||
|
|
||
| if (this.Host != null && this.Host.UI.SupportsVirtualTerminal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.Host.UI.SupportsVirtualTerminal is not needed twice here. But it seems like the logic should be:
mdOption.EnableVT100Encoding = mdOption.EnableVT100Encoding && (this.Host != null) && (this.Host.UI.SupportsVirtualTerminal);
If there is no host I assume EnableVT100Encoding option should be disabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PaulHigin improved it a bit by using nullable bool.
|
@PaulHigin @SteveL-MSFT @daxian-dbw Please have a look. |
|
|
||
| // supportsVT100 == null if the host is null. | ||
| // supportsVT100 == false if host does not support VT100. | ||
| if (supportsVT100 == null || supportsVT100 == false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit. I think you can just do if (supportsVT100 != true) here.
PaulHigin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
@adityapatwardhan can you review the CodeFactor issues? |
|
@SteveL-MSFT I have fixed a few CodeFactor issues. Others are either following a pattern which already exists or a rule we want to disable. @daxian-dbw Can you have another look? |
daxian-dbw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more comment. Otherwise look good to me.
| It "Verify PSMarkdownOptionInfo is defined in module scope" { | ||
|
|
||
| $mod = Get-Module Microsoft.PowerShell.Utility | ||
| $options = & $mod { $PSMarkdownOptionInfo } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better add one check for $PSMarkdownOptionInfo -eq $null before this line, to make sure that the variable is not leaked into the global scope or current scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
@daxian-dbw Is your #7329 (comment) closed? |
|
@daxian-dbw Ready to merge? |
|
@iSazonov Yes, it has been changed to use the module scope to save the variable. |
Fix #7283
PR Summary
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests