[Aptitude-svn-commit] r3268 - in branches/aptitude-0.3/aptitude: . src/vscreen/config
Daniel Burrows
dburrows@costa.debian.org
Sat, 07 May 2005 21:05:10 +0000
Author: dburrows
Date: Sat May 7 21:05:07 2005
New Revision: 3268
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/vscreen/config/colors.cc
branches/aptitude-0.3/aptitude/src/vscreen/config/colors.h
Log:
Register colors by content, not name.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Sat May 7 21:05:07 2005
@@ -1,5 +1,10 @@
2005-05-07 Daniel Burrows <dburrows@debian.org>
+ * src/vscreen/config/colors.cc, src/vscreen/config/colors.h:
+
+ Change the color database to allow orthogonal selection of fg/bg
+ colors. Now nothing compiles. Whee!
+
* src/vscreen/config/Makefile.am, src/vscreen/config/styles.cc, src/vscreen/config/styles.h:
Add basic support for styles that allow you to override the
Modified: branches/aptitude-0.3/aptitude/src/vscreen/config/colors.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/config/colors.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/config/colors.cc Sat May 7 21:05:07 2005
@@ -1,6 +1,6 @@
// colors.cc -*-c++-*-
//
-// Copyright 1999 Daniel Burrows
+// Copyright 1999-2001, 2003-2005 Daniel Burrows
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -19,109 +19,38 @@
#include "colors.h"
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef HAVE_HASH_MAP
-#include <hash_map>
-#else
-#ifdef HAVE_EXT_HASH_MAP
-#include <ext/hash_map>
-#else
-// Fallback to the non-hashing map class
-#include <map>
-#define hash_map map
-#endif
-#endif
-
#include "../curses++.h"
-#include "../vscreen.h"
-#include "../../generic/strhash.h"
-
-using namespace std;
-using namespace __gnu_cxx;
-
-int npairs=1;
-// FIXME: is this right? I --assume-- that it is; the curses documentation
-// appears to say that any color but 0 can be changed. But...
-bool color_names_initialized=false;
+static bool colors_initted=false;
+static bool colors_avail=false;
-// Stores a color pair and some extra attributes
-typedef pair<short, int> colorinfo;
+// Simplistic allocation scheme for colors: (fg,bg) => fg*COLORS+bg
-hash_map<string, colorinfo> colormap;
-hash_map<string, short> color_names;
-
-void init_color_names()
+static void init_colors()
{
- color_names["black"]=0;
- color_names["red"]=1;
- color_names["green"]=2;
- color_names["yellow"]=3;
- color_names["blue"]=4;
- color_names["magenta"]=5;
- color_names["cyan"]=6;
- color_names["white"]=7;
-}
+ colors_initted=true;
-int get_color(const string name)
-{
- hash_map<string, colorinfo>::iterator found;
- found=colormap.find(name);
+ if(COLOR_PAIRS<COLORS*COLORS || use_default_colors() == ERR)
+ return;
- if(found==colormap.end())
- return COLOR_PAIR(0);
- else
- return COLOR_PAIR(found->second.first)|found->second.second;
-}
+ colors_avail=true;
-void set_color(const string name, short fg, short bg, int attr)
-{
- hash_map<string, colorinfo>::iterator found=colormap.find(name);
- if(found==colormap.end())
- {
- int newnum=npairs++;
-
- init_pair(newnum, fg, bg);
- colormap[name]=colorinfo(newnum, attr);
- }
- else
- {
- init_pair(found->second.first, fg, bg);
- found->second.second=attr;
-
- // The following is necessary because ncurses is broken.
- // You see, the documentation for init_pair *claims* that the terminal
- // will be cleared and redrawn from scratch if an existing pair is
- // redefined. The more fool you if you believe it! No, you have to
- // do this yourself..sigh..
- vscreen_redraw();
- }
+ for(short fg=0; fg<COLORS; ++fg)
+ for(short bg=0; bg<COLORS; ++bg)
+ {
+ if(fg==0 && bg==0)
+ assume_default_colors(0, 0);
+ else
+ init_pair(fg*COLORS+bg, fg, bg);
+ }
}
-bool parse_color(string s, short &c)
+int get_color_pair(short fg, short bg)
{
- char *endptr;
+ init_colors();
- int rval=strtol(s.c_str(), &endptr, 0);
- if(*endptr)
- {
- if(!color_names_initialized)
- init_color_names();
- hash_map<string, short>::iterator found=color_names.find(s);
- if(found==color_names.end())
- return false;
- else
- {
- c=found->second;
- return true;
- }
- }
+ if(!colors_avail)
+ return false;
else
- {
- c=rval;
- return true;
- }
+ return fg*COLORS+bg;
}
Modified: branches/aptitude-0.3/aptitude/src/vscreen/config/colors.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/config/colors.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/config/colors.h Sat May 7 21:05:07 2005
@@ -1,6 +1,6 @@
// colors.h -*-c++-*-
//
-// Copyright 1999 Daniel Burrows
+// Copyright 1999-2001, 2004-2005 Daniel Burrows
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -17,20 +17,17 @@
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
//
-// Acts as a repository for colors.
+// Manages color allocation so as to allow any combination of
+// foreground/background colors to be used. If there aren't enough
+// color pairs available to handle all color combinations, this will
+// act as though no colors are available. It might be possible to
+// use colors more effectively; for instance, by ignoring attempts
+// to define colors whose foreground and background are the same.
#ifndef COLORS_H
#define COLORS_H
-#include <string>
-
-// Returns the named color or the default color if no such color exists.
-int get_color(const std::string name);
-
-// Sets the named color to have the given foreground, background, and
-// attributes.
-void set_color(const std::string name, short fg, short bg, int attr);
-
-bool parse_color(std::string s, short &c);
+/** \return a color pair for the given foreground and background. */
+int get_color_pair(short fg, short bg);
#endif