<<< Date Index >>>     <<< Thread Index >>>

bkgdtest: a test for the extra spaces at the end of lines



This was buried deep in a thread, so I am reposting for wider publication.

Several people have complained that when selected text in the pager that there is extra space at the end of pasted blocks. This test program is to help diagnose the problem.

me
/*
 * A test program which demostrates the various modes that the Mutt pager uses
 * when dealing with color.
 *
 * Compile with:
 *
 * for ncurses:  gcc -std=c99  bkgdtest.c -lncurses
 * for slang:  gcc -std=c99 -DUSE_SLANG=1 bkgdtest.c -lslang
 *
 * When using slang, or a $TERM with no "bce" capability [1], the line with the
 * yellow background color which extends to the right margin will contain the
 * extra spaces when copying.  This is what Mutt is currently doing.
 *
 * [1] $TERM is screen, xterm-color, or iTerm under OSX are known problems
 *
 * Author: Michael Elkins <me@xxxxxxxxxxx>
 * Date:   2010-08-09
 */

#include <stdlib.h>

#ifdef USE_SLANG
#include <slcurses.h>
#define bkgdset(x) do {} while(0)
#define tigetflag(x) 0
#define use_default_colors() do {} while(0)
#else
#include <curses.h>
#endif

void desc(const char *s)
{
        attrset(0);
        bkgdset(0);
        addstr("INFO: ");
        addstr(s);
        addch('\n');
}

int main(void)
{
        initscr();
        cbreak();
        noecho();
        start_color();
        use_default_colors();
        init_pair(1, COLOR_RED, COLOR_YELLOW);
#ifdef USE_SLANG
        SLtt_set_color(2, NULL, "green", "default");
#else
        init_pair(2, COLOR_GREEN, -1);
#endif

        char *s = getenv("TERM");
        addstr("$TERM environment variable: ");
        addstr(s ? s : "unset");
        addch('\n');
        
        addstr("terminal library: ");
#ifdef NCURSES_VERSION
        addstr("ncurses");
#elif SLANG_VERSION
        addstr("slcurses");
#else
        addstr("unknown");
#endif
        addch('\n');

        int bce = tigetflag("bce");
        addstr("terminal has bce capability: ");
        addstr(bce > 0 ? "yes" : "no");
        addch('\n');

        s = getenv("COLORFGBG");
        addstr("$COLORFG environment variable: ");
        addstr(s ? s : "unset");
        addch('\n');

        desc("non-default background w/ bkgdset()");
        attrset(COLOR_PAIR(1));
        addstr("1 The quick brown fox jumps over the lazy dog.");
        bkgdset(COLOR_PAIR(1));
        addch('\n');

        desc("non-default background w/o bkgdset()");
        attrset(COLOR_PAIR(1));
        addstr("2 The quick brown fox jumps over the lazy dog.");
        bkgdset(0);
        addch('\n');

        desc("non-default background w/ attrset(0)");
        attrset(COLOR_PAIR(1));
        addstr("3 The quick brown fox jumps over the lazy dog.");
        attrset(0);
        bkgdset(0);
        addch('\n');

        desc("default background w/ bkgdset()");
        attrset(COLOR_PAIR(2));
        addstr("4 The quick brown fox jumps over the lazy dog.");
        bkgdset(COLOR_PAIR(2));
        addch('\n');

        desc("default background w/o bkgdset()");
        attrset(COLOR_PAIR(2));
        addstr("5 The quick brown fox jumps over the lazy dog.");
        bkgdset(0);
        addch('\n');

        desc("default background w/ attrset(0)");
        attrset(COLOR_PAIR(2));
        addstr("6 The quick brown fox jumps over the lazy dog.");
        attrset(0);
        bkgdset(0);
        addch('\n');

        getch();
        endwin();
        return 0;
}

Attachment: pgpsas2Aa8gJq.pgp
Description: PGP signature