Managing the "internalBorder" background color in rxvt-unicode

While by no means an “essential” setting for many users, the internalBorder setting in rxvt-unicode can go a long way towards making the terminal more readable or simply looking more the way you want. It adds some padding between the edge of the terminal window and the start of the text, both at the top/bottom and the left/right of the window. This is especially useful if you use a tiling window manager and do not otherwise have spacing between windows.

The (arguably) venerable xterm terminal emulator has a similar property called BorderWidth.

Setting the Internal Border Size

To set the internal border, simply add the setting below to your Xresources file. In this case it sets the border to five pixels.

URxvt.internalBorder: 5

You should be able to use xrdb -load filename (replace existing properties) or xrdb -merge filename (merge with existing properties) to load the settings without restarting X Windows. You will need to open a new terminal window to see the effects.

Changing the Background Color

If you set the background color of your terminal dynamically with a script such as base16-shell or pywal, you may notice that the background color of the internal border of the rxvt-unicode window is not set.

The internal border looks for the number 708 in the escape sequence used for setting colors, whereas the sequence for setting the normal background color uses 11. For example, to set the background color to a nice grey color (#c3c3c3), you can run the command:

printf '\033]11;rgb:c3/c3/c3\007'

The internal border background color can be set to the same value using:

printf '\033]708;rgb:c3/c3/c3\007'

In terms of the base16-shell scripts, one option is to modify the template, copying the line that sets the background to also set the internal border background color (the default.moustache file here). In that case you’ll need to rebuild the scripts using one of the builders as shown here.

You can also use a shell command utilizing sed like the one below to copy the line that sets the background color in the scripts and create a new line to set the internal border color.

Example Shell Command:

for script in ${BASE16_SCRIPTS_DIRECTORY}/*.sh; do
    sed -i 's/printf \$printf_template_var 11 \$color_background/&\
    \printf $printf_template_var 708 \$color_background/' ${script}

Modification Result:

printf $printf_template_var 10 $color_foreground
printf $printf_template_var 11 $color_background
printf $printf_template_var 708 $color_background

Note that the base16-shell scripts have special handling for iTerm2 and tmux, so if you use either of those tools, you should also update those sections accordingly.