-
Is it possible to change the colors or theme of the terminal from a powershell script? Say I wanted to change the background color to red if the last command had an error and then back to the theme's default if the next command succeeded? If I can't just change the colors, is it possible to change themes programatically to achieve the same thing? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Probably the easiest way to do this would be with the
Then to switch back to the default background color, you could do this:
|
Beta Was this translation helpful? Give feedback.
-
Thanks! I got confused for a bit because the code above did nothing but it turns out I needed terminal 1.15 and I was running 1.14. |
Beta Was this translation helpful? Give feedback.
Probably the easiest way to do this would be with the
DECAC
escape sequence, which controls which palettes entries are used for the foreground and background colors. The defaults for foreground and background are usually 261 and 262, and the red from your chosen color scheme will be 1, so to switch the background to red (1), while keeping the default foreground (261), you'd use a command like this:Then to switch back to the default background color, you could do this: