Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libcurses Set the curses default colours to white on bla...



details:   https://anonhg.NetBSD.org/src/rev/8a3ccdb1e189
branches:  trunk
changeset: 534853:8a3ccdb1e189
user:      jdc <jdc%NetBSD.org@localhost>
date:      Sun Aug 04 16:43:04 2002 +0000

description:
Set the curses default colours to white on black when using colour.
See the Single UNIX Specification, Version 2 :

  http://www.opengroup.org/onlinepubs/007908799/xcurses/can_change_color.html

Also, add the functions :

        use_default_colors();
        assume_default_colors(fore, back);

(from ncurses) that allow the terminal default colours or user-specified
default colours to be used.

diffstat:

 lib/libcurses/PSD.doc/fns.doc  |   18 +++
 lib/libcurses/background.c     |   41 ++++++-
 lib/libcurses/color.c          |  217 +++++++++++++++++++++++++++++++++++-----
 lib/libcurses/curses.3         |    4 +-
 lib/libcurses/curses.c         |    6 +-
 lib/libcurses/curses.h         |    4 +-
 lib/libcurses/curses_private.h |    9 +-
 lib/libcurses/refresh.c        |   58 +++-------
 lib/libcurses/screen.c         |    5 +-
 lib/libcurses/shlib_version    |    4 +-
 10 files changed, 272 insertions(+), 94 deletions(-)

diffs (truncated from 723 to 300 lines):

diff -r 50cfe9a7940b -r 8a3ccdb1e189 lib/libcurses/PSD.doc/fns.doc
--- a/lib/libcurses/PSD.doc/fns.doc     Sun Aug 04 14:57:34 2002 +0000
+++ b/lib/libcurses/PSD.doc/fns.doc     Sun Aug 04 16:43:04 2002 +0000
@@ -74,6 +74,13 @@
 \*(Es
 In this case, it will put on as much as it can.
 .Ds
+.Fn assume_default_colors "short fore" "short back"
+.De
+Set the curses default foreground and background colors to
+.Vn fore
+and
+.Vn back .
+.Ds
 .Fn attroff "int attribute" \(dg
 .De
 Remove character attributes set by
@@ -1239,6 +1246,12 @@
 .De
 Initialize the color routines. 
 This must be called before any of the color routines are used.
+The terminal is setup to use the curses default colors of white foreground
+on black background, unless
+.Fn assume_default_colors
+or
+.Fn use_default_colors
+are called.
 .Ds
 .Ft "WINDOW *"
 .Fn subwin "WINDOW *win" "int lines" "int cols" "int begin_y" "int begin_x"
@@ -1381,6 +1394,11 @@
 .De
 Make the window appear to have not been updated even if it has been.
 .Ds
+.Fn use_default_colors ""
+.De
+Use the terminal foreground and background colors as the curses default
+foreground and background colors.
+.Ds
 .Fn vline "chtype ch" "int count"
 .De
 Draws a vertical line of character
diff -r 50cfe9a7940b -r 8a3ccdb1e189 lib/libcurses/background.c
--- a/lib/libcurses/background.c        Sun Aug 04 14:57:34 2002 +0000
+++ b/lib/libcurses/background.c        Sun Aug 04 16:43:04 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: background.c,v 1.6 2000/04/24 14:09:42 blymn Exp $     */
+/*     $NetBSD: background.c,v 1.7 2002/08/04 16:43:05 jdc Exp $       */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: background.c,v 1.6 2000/04/24 14:09:42 blymn Exp $");
+__RCSID("$NetBSD: background.c,v 1.7 2002/08/04 16:43:05 jdc Exp $");
 #endif                         /* not lint */
 
 #include "curses.h"
@@ -71,13 +71,19 @@
 void
 wbkgdset(WINDOW *win, chtype ch)
 {
+#ifdef DEBUG
+       __CTRACE("wbkgdset: (%0.2o), '%s', %08x\n",
+           win, unctrl(ch & +__CHARTEXT), ch & __ATTRIBUTES);
+#endif
+
+       /* Background character. */
        if (ch & __CHARTEXT)
                win->bch = (wchar_t) ch & __CHARTEXT;
+
+       /* Background attributes (check colour). */
+       if (__using_color && !(ch & __COLOR))
+               ch |= __default_color;
        win->battr = (attr_t) ch & __ATTRIBUTES;
-#ifdef DEBUG
-       __CTRACE("wbkgdset: (%0.2o), '%s', %08x\n",
-           win, unctrl(win->bch), win->battr);
-#endif
 }
 
 /*
@@ -89,12 +95,23 @@
 {
        int     y, x;
 
+#ifdef DEBUG
+       __CTRACE("wbkgd: (%0.2o), '%s', %08x\n",
+           win, unctrl(ch & +__CHARTEXT), ch & __ATTRIBUTES);
+#endif
+
+       /* Background attributes (check colour). */
+       if (__using_color && !(ch & __COLOR))
+               ch |= __default_color;
+
+       win->battr = (attr_t) ch & __ATTRIBUTES;
        wbkgdset(win, ch);
        for (y = 0; y < win->maxy; y++)
                for (x = 0; x < win->maxx; x++) {
                        if (ch & A_CHARTEXT)
                                win->lines[y]->line[x].bch = ch & __CHARTEXT;
-                       win->lines[y]->line[x].battr = ch & __ATTRIBUTES;
+                       win->lines[y]->line[x].battr =
+                           (attr_t) ch & __ATTRIBUTES;
                }
        __touchwin(win);
        return(OK);
@@ -107,6 +124,12 @@
 chtype
 getbkgd(WINDOW *win)
 {
-       return ((chtype) ((win->bch & A_CHARTEXT) |
-           (win->battr & A_ATTRIBUTES)));
+       attr_t  battr;
+
+       /* Background attributes (check colour). */
+       battr = win->battr & A_ATTRIBUTES;
+       if (__using_color && ((battr & __COLOR) == __default_color))
+               battr &= ~__default_color;
+
+       return ((chtype) ((win->bch & A_CHARTEXT) | battr));
 }
diff -r 50cfe9a7940b -r 8a3ccdb1e189 lib/libcurses/color.c
--- a/lib/libcurses/color.c     Sun Aug 04 14:57:34 2002 +0000
+++ b/lib/libcurses/color.c     Sun Aug 04 16:43:04 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: color.c,v 1.18 2002/06/26 18:13:59 christos Exp $      */
+/*     $NetBSD: color.c,v 1.19 2002/08/04 16:43:07 jdc Exp $   */
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -38,12 +38,22 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: color.c,v 1.18 2002/06/26 18:13:59 christos Exp $");
+__RCSID("$NetBSD: color.c,v 1.19 2002/08/04 16:43:07 jdc Exp $");
 #endif                         /* not lint */
 
 #include "curses.h"
 #include "curses_private.h"
 
+/* Have we initialised colours? */
+int    __using_color = 0;
+
+/* Default colour number */
+attr_t __default_color = 0;
+
+/* Default colour pair values - white on black. */
+struct __pair  __default_pair = {COLOR_WHITE, COLOR_BLACK, 0};
+
+/* Default colour values */
 /* Flags for colours and pairs */
 #define        __USED          0x01
 
@@ -51,7 +61,8 @@
 attr_t __nca;
 
 static void
-__change_pair __P((short));
+__change_pair(short);
+
 /*
  * has_colors --
  *     Check if terminal has colours.
@@ -87,8 +98,11 @@
 int
 start_color(void)
 {
-       int     i;
-       attr_t  temp_nc;
+       int                      i;
+       attr_t                   temp_nc;
+       struct __winlist        *wlp;
+       WINDOW                  *win;
+       int                      y, x;
 
        if (has_colors() == FALSE)
                return(ERR);
@@ -102,7 +116,10 @@
                        COLOR_PAIRS = 0;
                        COLORS = 0;
                } else {
-                       COLOR_PAIRS = __tc_pa > MAX_PAIRS ? MAX_PAIRS : __tc_pa;
+                       COLOR_PAIRS = (__tc_pa > MAX_PAIRS ?
+                           MAX_PAIRS : __tc_pa) - 1;
+                        /* Use the last colour pair for curses default. */
+                       __default_color = COLOR_PAIR(COLOR_PAIRS);
                }
        }
        if (!COLORS)
@@ -206,13 +223,51 @@
                _cursesi_screen->colours[i].flags = 0;
        }
 
-       /* Initialise colour pairs to default (white on black) */
-       for (i = 0; i < COLOR_PAIRS; i++) {
+       /* Initialise pair 0 to default colours. */
+       _cursesi_screen->colour_pairs[0].fore = -1;
+       _cursesi_screen->colour_pairs[0].back = -1;
+       _cursesi_screen->colour_pairs[0].flags = 0;
+
+       /* Initialise user colour pairs to default (white on black) */
+       for (i = 1; i < COLOR_PAIRS; i++) {
                _cursesi_screen->colour_pairs[i].fore = COLOR_WHITE;
                _cursesi_screen->colour_pairs[i].back = COLOR_BLACK;
                _cursesi_screen->colour_pairs[i].flags = 0;
        }
 
+       /* Initialise default colour pair. */
+       _cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].fore =
+           __default_pair.fore;
+       _cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].back =
+           __default_pair.back;
+       _cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].flags =
+           __default_pair.flags;
+
+       __using_color = 1;
+
+       /* Set all positions on all windows to curses default colours. */
+       for (wlp = __winlistp; wlp != NULL; wlp = wlp->nextp) {
+               win = wlp->winp;
+               if (wlp->winp == curscr) {
+                       /* Reset colour attribute on curscr */
+                       for (y = 0; y < curscr->maxy; y++)
+                               for (x = 0; x < curscr->maxx; x++) {
+                                       if ((curscr->lines[y]->line[x].battr & __COLOR) == __default_color)
+                                               curscr->lines[y]->line[x].battr &= ~__COLOR;
+                               }
+               } else if (wlp->winp != __virtscr) {
+                       /* Set background attribute on other windows */
+                       if (!(win->battr & __COLOR))
+                               win->battr |= __default_color;
+                       for (y = 0; y < win->maxy; y++) {
+                               for (x = 0; x < win->maxx; x++)
+                                       if (!(win->lines[y]->line[x].battr & __COLOR))
+                                               win->lines[y]->line[x].battr |= __default_color;
+                       }
+                       __touchwin(win);
+               }
+       }
+
        return(OK);
 }
 
@@ -229,11 +284,11 @@
        __CTRACE("init_pair: %d, %d, %d\n", pair, fore, back);
 #endif
 
-       if (pair < 0 || pair >= COLOR_PAIRS)
+       if (pair < 0 || pair > COLOR_PAIRS)
                return (ERR);
-       if (fore < 0 || fore >= COLORS)
+       if (fore < -1 || fore >= COLORS)
                return (ERR);
-       if (back < 0 || back >= COLORS)
+       if (back < -1 || back >= COLORS)
                return (ERR);
 
        if ((_cursesi_screen->colour_pairs[pair].flags & __USED) &&
@@ -261,7 +316,7 @@
 int
 pair_content(short pair, short *forep, short *backp)
 {
-       if (pair < 0 || pair >= _cursesi_screen->COLOR_PAIRS)
+       if (pair < 0 || pair > _cursesi_screen->COLOR_PAIRS)
                return(ERR);
 
        *forep = _cursesi_screen->colour_pairs[pair].fore;
@@ -279,7 +334,7 @@
 #ifdef DEBUG
        __CTRACE("init_color: %d, %d, %d, %d\n", color, red, green, blue);
 #endif
-       if (color < 0 || color >= _cursesi_screen->COLOR_PAIRS)
+       if (color < 0 || color >= _cursesi_screen->COLORS)
                return(ERR);
 
        _cursesi_screen->colours[color].red = red;
@@ -307,14 +362,62 @@
 }
 
 /*
+ * use_default_colors --
+ *     Use terminal default colours instead of curses default colour.
+  */
+int
+use_default_colors()
+{
+#ifdef DEBUG
+       __CTRACE("use_default_colors\n");
+#endif
+       
+       return(assume_default_colors(-1, -1));
+}
+
+/*
+ * assume_default_colors --
+ *     Set the default foreground and background colours.



Home | Main Index | Thread Index | Old Index