-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Minimize writing ANSI escape sequences in PSReadline #4110
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&r 8000 dquo;, 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
Conversation
Instead of changing Console.*groundColor on every character, only set the color when the color changes - this avoids writing out ANSI escape sequences after every character. Fixes PowerShell#4075
Console.BackgroundColor = buffer[i].BackgroundColor; | ||
var nextForegroundColor = buffer[i].ForegroundColor; | ||
var nextBackgroundColor = buffer[i].BackgroundColor; | ||
if (lastForegroundColor != nextForegroundColor) |
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.
Small nitpick, but it seems that if (nextForegroundColor != lastForegroundColor)
is slightly more correct improving readability
{ | ||
Console.ForegroundColor = lastForegroundColor = nextForegroundColor; | ||
} | ||
if (lastBackgroundColor != nextBackgroundColor) |
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 as above
8000
|
||
Console.Write(buffer[i].UnicodeChar); | ||
} | ||
|
||
Console.BackgroundColor = backgroundColor; | ||
Console.ForegroundColor = foregroundColor; | ||
if (backgroundColor != lastBackgroundColor) |
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.
Pretty much everywhere else you have foreground first, then background. Another nitpick, but I would reorder these two if
statements
Instead of changing Console.*groundColor on every character, only set
the color when the color changes - this avoids writing out ANSI escape
sequences after every character.
Fixes #4075