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
PowerShell on osx - how to force to be completely monochrome #3918
Comments
This comment was marked as resolved.
This comment was marked as resolved.
One proposal is to have the PowerShell core's $PSStyle.OutputRendering controlled by NO_COLOR, and then PSReadLine governed by terminfo. Given .bashrc on Debian systems uses 'xterm-256color' as the determination on whether to use colours, then PSReadLine could do similar and if terminfo says the current terminal has more than 16 colours it could use colours, if 16 or less then it should be monochrome. We note that macOS does not support "xterm-mono" in its terminfo database. Setting TERM is global for a session so affects other programs including 'pico' and 'nano'.
|
@rhubarb-geek-nz, I just noticed that you can use Note that making PSReadline respect Apart from that, it would be great if PSReadLine - in the absence of explicit color configuration for it (i.e. This would more directly give you what you want - readability - while not having to forgo color support. |
I would certainly like a monochrome option somehow. I often remove the default alias to "ls" in bash because I find it hard to read blue text on a black background, let alone yellow on white. The great thing about monochrome is that it is (a) high contrast (b) the user's preference of colours. |
Understood. I think that both things are worth implementing:
|
I think that PSReadline should understand |
Good point, @237dmitry. What My only question is: Would users ever want to control this preference separately for output (already implemented in PowerShell) vs. interactive input? |
Perhaps, they may want NO_COLOR for all rendering of output because they are copying and pasting output tables and results into a document or a report, but want the colour during editing of commands to assist with syntax highlighting and auto-completion. |
|
I am not sure what you mean. Environment variables like LANG and TZ have traditionally affected the output of commands. Likewise TERM affects how editors drive the terminal console. Aliases are purely internal to shells themselves and do not affect actual programs. It is the shell interpreting an alias that appends the argument --color to an invocation of ls, not the executing of /bin/ls or /usr/bin/ls. Debian's .bashrc has similar to
So it determines the prompt based on the TERM environment variable. Likewise it conditionally sets up the alias of ls based on the executability of /usr/bin/dircolors
|
I meant that this variable is not for global use so that the terminal becomes completely monochrome, but for launching individual utilities. If I add And not of all utilities understand As for pwsh, not everything is so smooth with it, because many users, unlike you, use profiles for shell configuration. And this is normal use, that's what $profile is for. |
I certainly agree that NO_COLOR is not supported by every application, no-color-.org shows a list of a hundred or so programs that do (PowerShell is listed!). Likewise many applications ignore TERM. NO_COLOR is new and TERM is relayed by One of the principles of UNIX software is mechanism, not policy. Do we provide a mechanism to support monochrome, and if so is it a standard? The policy is something different which we cannot enforce, who sets the variable (if that is the mechanism) in the first place and who else also abides by it. Having the mechanism of supporting NO_COLOR does mean that I could change my .bashrc to set it depending on the TERM variable value, along with not setting the aliases for ls. That would be me implementing my policy. In reality I don't customise machines .bashrc or profiles because life is really too short and I deal with hundreds of real and virtual machines and don't have time for customising each. However setting my TERM to be a simple "xterm" or similar does allow me to get by. |
That's why we need to target pwsh so that the core and modules understand each other. To prevent PSReadline from being colorful when $PSStyle.OutputRendering is set to "PlainText". This is a single directive and works fine, even though it is primarily intended to output the results of a command to a file so that there are no esc-sequences in it. For me, until this is implemented, I would just write a function that defines the colors in |
I can't set the colours in Set-PSReadlineOption because they are not static, the macOS terminal changes automatically between dark mode and light mode depending on the time of day, and I might have one window open as "Man Page" and the other as "Homebrew". |
On MacOS Terminal in the different themes `e[37m just gave white text as per the ANSI escape sequence specification. |
You have to configure terminal function set-mono {
$PSStyle.OutputRendering = "PlainText"
Set-PSReadlineOption -Color @{
Command = "`e[37m"
Comment = "`e[37m"
ContinuationPrompt = "`e[37m"
Default = "`e[37m"
Emphasis = "`e[37m"
Error = "`e[37m"
InlinePrediction = "`e[37m"
Keyword = "`e[37m"
ListPrediction = "`e[37m"
ListPredictionSelected = "`e[7m"
ListPredictionTooltip = "`e[37m"
Member = "`e[37m"
Number = "`e[37m"
Operator = "`e[37m"
Parameter = "`e[37m"
Selection = "`e[7m"
String = "`e[37m"
Type = "`e[37m"
Variable = "`e[37m"
}
} |
Or just use a shell that works monochrome out of the box, eg bash or zsh, and only use PowerShell to execute scripts. The default terminal on MacOS gives you ( during the day ) black text on a white background. You should not have to reconfigure that to run PowerShell. |
We can workaround bug 49780 by disabling colour outputs entirely, and removing the PSReadLine module. See: PowerShell/PSReadLine#3918 and PowerShell/PowerShell#21160 for context.
Prerequisites
Exception report
See PowerShell on osx how to force to be completely monochrome
Should be able to easily use PowerShell on a monochrome terminal, ideally respecting the TERM environment variable.
Screenshot
Environment data
Steps to reproduce
Open a terminal on macOS of type "Man Page", use pwsh
Typed text will be yellow on a yellow background
Expected behavior
Typed text should be visible no matter the type of terminal or colours used by the terminal
Actual behavior
Typed text is always yellow, hard to read on white or yellow backgrounds.
The text was updated successfully, but these errors were encountered: