When working on several different servers at once, or with different user accounts, it is helpful to be able to visually identify the terminal windows by using different color schemes. This can help you to avoid accidentally typing commands into the wrong window, for example running an intensive program on the production server when you meant to run it on the development server. a4 can dynamically update the foreground, background, and full color schemes by matching with text in each terminal's title bar.
Using Color Rules
Below is the general syntax for all ColorRules in a4.ini files. The pattern of each rule is compared, in order, with the text in each terminal's title bar. When the first match is made, the specified ColorScheme is applied as well as optional foreground and background color overrides (-1 keeps the default ColorScheme foreground color). As a special case, a line containing just a single '=' character in the ColorRules section clears all previously defined rules.
[ColorRules] <pattern> = <colorscheme name> [<fg color|-1> [<bg color>]]
As a full example, let's take an application "bar" that has separate servers for development, testing, and production. To begin, let's give each server a unique color scheme.
[ColorRules] @bardev = gruvbox-dark @bartst = solarized-dark @barprd = redsands
Application "bar" is run from a privileged service account, "barsvc", and there is also some work that must be done as root. We'd like to be able to quickly identify if we're logged in with a privileged user account. Let's keep the same general server color schemes and modify the foreground text color to orange for user "barsvc", and red if we sudo to the root user account. The rules are checked in order, so it's important to put the more specific user account patterns before the more general server name patterns.
[ColorRules] root@bardev = gruvbox-dark red barsvc@bardev = gruvbox-dark orange @bardev = gruvbox-dark root@bartst = solarized-dark red barsvc@bartst = solarized-dark orange @bartst = solarized-dark root@barprd = redsands red barsvc@barprd = redsands orange @barprd = redsands
As a last step, let's add a production disaster recovery server "barprddr" and give it the same colors as active production but with a 10% darker background color. These rules have to go before the active production rules because the more general "barprd" pattern matches both servers.
[ColorRules] root@bardev = gruvbox-dark red barsvc@bardev = gruvbox-dark orange @bardev = gruvbox-dark root@bartst = solarized-dark red barsvc@bartst = solarized-dark orange @bartst = solarized-dark root@barprddr = redsands red 0x521914 barsvc@barprddr = redsands orange 0x521914 @barprddr = redsands -1 0x521914 root@barprd = redsands red barsvc@barprd = redsands orange @barprd = redsands