Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If your terminal emulator supports Background Color Erase (BCE), you could use an "erase display" escape sequence to set the display's background color. For example, this sets the background to red in bash:</p> <pre><code>tput setab 1; tput clear </code></pre> <p><code>tput setab 1</code> sets the "ANSI Background Color" to 1 (Red). <code>put clear</code> clears the screen, usually by emitting the codes to move the cursor to the top/left corner and clear the display. If you don't want to erase the entire display, you can just erase from the current line to the end of the display:</p> <pre><code>tput setab 1; tput ed </code></pre> <p>If your terminal emulator supports BCE, various commands that clear portions of the display will fill the cleared area with the current background color. You can tell if your terminal emulator supports BCE using <code>tput</code>:</p> <pre><code>tput bce &amp;&amp; echo Yes || echo No </code></pre> <p>This will display "Yes" if BCE is supported.</p> <p>To make use of this, you can use shell functions (or script files) to wrap the commands you want to set the color for. e.g., in bash this will set the display to blue when running ssh:</p> <pre><code>ssh () { trap 'tput sgr0; tput ed' RETURN; tput setab 4; tput ed command ssh $*; } </code></pre> <p>Using <code>trap</code> ensures it resets the background color (and other text attributes) when the function returns. I've used <code>tput ed</code> here, so it only affects the background color of the lines output while running the ssh command. You can use <code>tput clear</code> if you'd rather fill the entire display and you don't mind erasing the current contents at the start (and/or end) of the command.</p> <p>Of course, if anything you do with the remote host changes the background color, it will override your color.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload