Ncurses and color - Unix

This is a discussion on Ncurses and color - Unix ; Hi all, I'm looking to write a program using Ncurses and I have a question about colours (or colors if you are in the US). On my machine (latest Ubuntu) I have libncurses version 5.6 and I am running my ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: Ncurses and color

  1. Ncurses and color

    Hi all,

    I'm looking to write a program using Ncurses and I have a question
    about colours (or colors if you are in the US).

    On my machine (latest Ubuntu) I have libncurses version 5.6 and I
    am running my test program inside an xterm (version 229). With this
    setup, the ncurses function can_change_color returns false, and the
    default colours are somewhat boring.

    However I know I can get all sorts of interesting colors in programs
    like Vim and GNU Screen. I've had a preliminary look at the sources
    to these programs, but its not immediately obvious how they achieve
    them.

    Anyone have any clues to impart?

    Thz,
    Andrew J. Hunter

  2. Re: Ncurses and color

    On Jan 6, 9:51 pm, Andrew.J.Hunte...@gmail.com wrote:
    > Hi all,
    >
    > I'm looking to write a program using Ncurses and I have a question
    > about colours (or colors if you are in the US).
    >
    > On my machine (latest Ubuntu) I have libncurses version 5.6 and I
    > am running my test program inside an xterm (version 229). With this
    > setup, the ncurses function can_change_color returns false, and the
    > default colours are somewhat boring.


    Have you tried the program on a terminal other then xterm?

    > However I know I can get all sorts of interesting colors in programs
    > like Vim and GNU Screen. I've had a preliminary look at the sources
    > to these programs, but its not immediately obvious how they achieve
    > them.
    >


    Vim isn't written using ncurses, so that won't help.


    > Anyone have any clues to impart?


    Have a look at this:

    http://invisible-island.net/ncurses/...no_xterm_color

    >
    > Thz,
    > Andrew J. Hunter


  3. Re: Ncurses and color

    Jim Kukunas wrote:

    > Have you tried the program on a terminal other then xterm?


    Yes, rxvt, gnome-terminal and Eterm. Same behavior on all of them.

    Any idea which terminal type is available on Linux and might be able
    to provide access to more colours?

    > Vim isn't written using ncurses, so that won't help.


    Any ideas what it is written with?

    > Have a look at this:
    >
    > http://invisible-island.net/ncurses/...no_xterm_color


    My xterm does do color, and runs this program:

    http://www.frexx.de/xterm-256-notes/data/256colors2.pl

    quite happily, displaying an absolute rainbow of colors.

    However, using ncurses, I only seem to be able to access the small,
    rather poor subset labeled "System colors".

    AJH

  4. Re: Ncurses and color

    Andrew.J.Hunter74@gmail.com wrote:
    >> Have you tried the program on a terminal other then xterm?


    > Yes, rxvt, gnome-terminal and Eterm. Same behavior on all of them.


    I don't see any comment that he's setting $TERM to use a different
    terminal description.

    > Any idea which terminal type is available on Linux and might be able
    > to provide access to more colours?


    >> Vim isn't written using ncurses, so that won't help.


    > Any ideas what it is written with?


    It uses the terminal database provided by ncurses, as well as some
    builtin-generic terminal descriptions (redundant where ncurses is
    available). For instance, ncurses provides (from xterm...) a
    "xterm-256color" terminal description.

    --
    Thomas E. Dickey
    http://invisible-island.net
    ftp://invisible-island.net

  5. Re: Ncurses and color

    On Jan 11, 11:52 pm, Thomas Dickey wrote:
    > I don't see any comment that he's setting $TERM to use a different
    > terminal description.


    Yep, just using whatever TERM variable is set up automatically when I
    invoke the terminal.

    > It uses the terminal database provided by ncurses, as well as some
    > builtin-generic terminal descriptions (redundant where ncurses is
    > available). For instance, ncurses provides (from xterm...) a
    > "xterm-256color" terminal description.


    Oh wow! I am now enlightened. Thanks Thomas.

    If I run my test program with the standard TERM environment variable I
    get :

    ajh@home : ./curses_test
    has_colors : true
    start_color : true
    can_change_color : false
    use_default_colors : true
    color_pairs : 64

    but if I run it as:

    ajh@home : TERM=xterm-256color ./curses_test
    has_colors : true
    start_color : true
    can_change_color : true
    use_default_colors : true
    color_pairs : 32767

    Which is what I want.

    I now have some new questions following on from the above:

    - Who is responsible for setting TERM?
    - Should the ncurses database be aware of my xterm being able to do
    more than 64 colors?
    - Is there a way to detect that the xterm is really an
    xterm-256color so that the TERM variable can be overridden?

    --
    AJH

  6. Re: Ncurses and color

    Andrew.J.Hunter74@gmail.com wrote:
    > On Jan 11, 11:52 pm, Thomas Dickey wrote:
    >> I don't see any comment that he's setting $TERM to use a different
    >> terminal description.


    > Yep, just using whatever TERM variable is set up automatically when I
    > invoke the terminal.


    >> It uses the terminal database provided by ncurses, as well as some
    >> builtin-generic terminal descriptions (redundant where ncurses is
    >> available). For instance, ncurses provides (from xterm...) a
    >> "xterm-256color" terminal description.


    > Oh wow! I am now enlightened. Thanks Thomas.


    > If I run my test program with the standard TERM environment variable I
    > get :


    > ajh@home : ./curses_test
    > has_colors : true
    > start_color : true
    > can_change_color : false
    > use_default_colors : true
    > color_pairs : 64


    > but if I run it as:


    > ajh@home : TERM=xterm-256color ./curses_test
    > has_colors : true
    > start_color : true
    > can_change_color : true
    > use_default_colors : true
    > color_pairs : 32767


    > Which is what I want.


    If xterm weren't compiled to support 256 colors, it would look not as nice...

    > I now have some new questions following on from the above:


    > - Who is responsible for setting TERM?


    "you" - the person who sets up the configuration.

    > - Should the ncurses database be aware of my xterm being able to do
    > more than 64 colors?


    In general it cannot know what the terminal can do.
    Some terminals implement queries that can tell a smart application
    what features the terminal has, but most do not.

    Taking xterm as a special case, it implements many of the DEC VT220,
    VT320, etc., queries. It also implements some extra ones - though
    one that can tell how many colors it supports has been a non-default
    configuration option (used by vim). From ctlseqs.txt:

    DCS + q Pt ST
    Request Termcap/Terminfo String (xterm, experimental). The
    string following the "q" is a list of names encoded in hex-
    adecimal (2 digits per character) separated by ; which corre-
    spond to termcap or terminfo key names.
    xterm responds with DCS 1 + r Pt ST for valid requests, adding
    to Pt an = , and the value of the corresponding string that
    xterm would send, or DCS 0 + r Pt ST for invalid requests.
    The strings are encoded in hexadecimal (2 digits per charac-
    ter).

    (a rather terse description of the escape sequence). There's a demo
    script in xterm's vttests subdirectory named "tcapquery.pl".

    I made it a default in the most recent patches 230/231, since it was
    part of the code needed to support this feature:

    --disable-tcap-fkeys disable termcap function-keys

    Compile-in code to support feature which allows xterm to use the
    function-key definitions from the termcap/terminfo entry which it used
    to set the $TERM variable on startup.

    Generally packagers add features, and don't suppress features.
    So technically there is a way to ask xterm. But not in general.

    > - Is there a way to detect that the xterm is really an
    > xterm-256color so that the TERM variable can be overridden?


    That escape sequence can be used (provided that xterm is compiled with
    the tcap-query feature).

    --
    Thomas E. Dickey
    http://invisible-island.net
    ftp://invisible-island.net

  7. Re: Ncurses and color

    Thomas Dickey wrote:
    > Compile-in code to support feature which allows xterm to use the
    > function-key definitions from the termcap/terminfo entry which it used
    > to set the $TERM variable on startup.


    As an afterthought: on startup xterm tries to use the $TERM it's told to,
    e.g.,

    -tn name
    This option specifies the name of the terminal type
    to be set in the TERM environment variable. It
    corresponds to the termName resource. This terminal
    type must exist in the terminal database (termcap or
    terminfo, depending on how xterm is built) and
    should have li# and co# entries. If the terminal
    type is not found, xterm uses the built-in list
    ``xterm'', ``vt102'', etc.

    and it's relatively easy to set the function-keys to match. But if
    it's compiled for 88-colors, setting $TERM to xterm-256color won't
    make it do 256 (the bits are organized differently). A 256-color
    xterm can be setup to look just like the 88-color xterm though.

    --
    Thomas E. Dickey
    http://invisible-island.net
    ftp://invisible-island.net

+ Reply to Thread