0

I typically have a lot of windows open on a lot of different computers. I want to have the .bash_profile on each machine set the foreground and background color to a color that is specific for that machine.

I use mintty on Cygwin, and iTerm on the Mac, and sometimes xterm or aterm or gnome-terminal.

If I change the foreground and background colors in the program's specific GUI, they stick, and going into EMACS or doing a ls with the --color option doesn't change it.

But if I use the ANSI sequence to set the foreground and background color to a 24-bit color, as soon as EMACS or ls tries to put something in a different color, the colors of my terminal reverts back to the default foreground and background color.

Is there any way to change the default foreground and background color with an ESCAPE SEQUENCE, rather than with the GUI?

vy32
  • 28,461
  • 37
  • 122
  • 246

1 Answers1

2

There is, but it's only reliably implemented (and documented) in xterm. That's the "dynamic colors" feature which the xtermcontrol program uses:

The 10 colors (below) which may be set or queried using 1 0 through 1 9 are denoted dynamic colors, since the corresponding control sequences were the first means for setting xterm's colors dynamically, i.e., after it was started. They are not the same as the ANSI colors. These controls may be disabled using the allowColorOps resource. At least one parameter is expected for Pt. Each successive parameter changes the next color in the list. The value of Ps tells the starting point in the list. The colors are specified by name or RGB specification as per XParseColor.

If a "?" is given rather than a name or RGB specification, xterm replies with a control sequence of the same form which can be used to set the corresponding dynamic color. Because more than one pair of color number and specification can be given in one control sequence, xterm can make more than one reply.

For the other terminals, they recognize parts of the feature, but incompletely, and do not provide documentation (other than their source code) — ymmv

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105