[dev] Good Morning, and a question about st (italic mode switches color).

From: Ingo Krabbe <ikrabbe.ask_AT_gmail.com>
Date: Wed, 5 Oct 2016 13:37:33 +0200

Hey suckless developers,

first let me thank you for your great work. dwm and st have become my main linux tools as a base to control nearly everything, as long I don't switch to my plan9 virtual machine and do things in rc terminals or acme windows.

But today a bug in st burned some hours. So let me tell you the short story: The main systems I use have a plain gentoo installed, because that's a good way to keep a system up-to-date, once you got familiar with gentoo at all. I'm not sure yet if OpenRC is really much better than systemd, though, so if I would need to choose today I might switch to a plain debian, that I often use on servers.

Gentoo has a little trick to display manual pages, using a `MANPAGER=/usr/bin/manpager` command, that is a simple command compiled from the attached manpager.c command, which does nothing more then the shell script

    LESS_TERMCAP_mb='' # BLINK [5;31m
    LESS_TERMCAP_md='' # BOLD [1;34m
    LESS_TERMCAP_us='' # UNDERLINE [4;36m
    LESS_TERMCAP_so='' # ITALIC [3;90m
    #export LESS_TERMCAP_{mb,md,me,us,ue,so,se}
    exec less

without the _so and _se lines. But I like this italic setup, so I added the standout mode.

To do such switches in a more readable, suckless way one should actually use tput, imho, to switch the modes and select the colors:

    ITALIC_BLACK=`tput sitm; tput setaf 0`

That works with xterm, but with st it selects a yellow color, which is a bit disturbing, as I use a light background and I cannot read yellow.

So the basic bug is, that "sitm" (start italic mode) also affects the color. Actually it only affects "setaf 0". Most other colors aren't affected, which you can quick check with:

    for i in `seq 0 255`
    do tput setaf $i
        tput sitm
        echo -n "Test it!"
        tput ritm
        echo "Test it!"

Maybe thats a problem of the terminfo file. I didn't checked that yet, but maybe someone else already had such a problem too, so I wanted to ask first if that is considered a bug and if someone might already have a handy solution to it.

Actually "tput ncf" says "3", which means that the italic attribute cannot be used with colors. But that is a lie. I would say, the italic attribute can only be used with colors.

Best Regards,


 * Wrapper to help enable colorized man page output.
 * Only works with PAGER=less
 * https://bugs.gentoo.org/184604
 * https://unix.stackexchange.com/questions/108699/documentation-on-less-termcap-variables
 * Copyright 2003-2015 Gentoo Foundation
 * Distributed under the terms of the GNU General Public License v2

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define COLOR(c, b) "\e[" #c ";" #b "m"

#define _SE(termcap, col) setenv("LESS_TERMCAP_" #termcap, col, 0)
#define SE(termcap, c, b) _SE(termcap, COLOR(c, b))

static int usage(void)
                "manpager: display man pages with color!\n"
                "\texport MANPAGER=manpager\n"
                "\tman man\n"
                "To control the colorization, set these env vars:\n"
                "\tLESS_TERMCAP_mb - start blinking\n"
                "\tLESS_TERMCAP_md - start bolding\n"
                "\tLESS_TERMCAP_me - stop bolding\n"
                "\tLESS_TERMCAP_us - start underlining\n"
                "\tLESS_TERMCAP_ue - stop underlining\n"
                "\tLESS_TERMCAP_so - start standout (reverse video)\n"
                "\tLESS_TERMCAP_se - stop standout (reverse video)\n"
                "You can do so by doing:\n"
                "\texport LESS_TERMCAP_md=\"$(printf '\\e[1;36m')\"\n"
                "Run 'less --help' or 'man less' for more info"
        return 0;

int main(int argc, char *argv[])
        if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))
                return usage();

        /* Blinking. */
        SE(mb, 5, 31); /* Start. */

        /* Bolding. */
        SE(md, 1, 34); /* Start. */
        SE(me, 0, 0); /* Stop. */

        /* Underlining. */
        SE(us, 4, 36); /* Start. */
        SE(ue, 0, 0); /* Stop. */

#if 0
        /* Standout (reverse video). */
        SE(so, 1, 32); /* Start. */
        SE(se, 0, 0); /* Stop. */

        argv[0] = getenv("PAGER") ? : "less";
        execvp(argv[0], argv);
        perror("could not launch PAGER");
        return 1;
Received on Wed Oct 05 2016 - 13:37:33 CEST

This archive was generated by hypermail 2.3.0 : Wed Oct 05 2016 - 13:48:11 CEST