[Aptitude-svn-commit] r3367 - in branches/aptitude-0.3/aptitude: . src
Daniel Burrows
dburrows@costa.debian.org
Tue, 07 Jun 2005 17:03:12 +0000
Author: dburrows
Date: Tue Jun 7 17:03:09 2005
New Revision: 3367
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/load_config.cc
Log:
Update the configuration parsing code to load styles from the configuration file.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Tue Jun 7 17:03:09 2005
@@ -1,5 +1,9 @@
2005-06-07 Daniel Burrows <dburrows@debian.org>
+ * src/load_config.cc:
+
+ Change load_colors to load_styles.
+
* src/edit_pkg_hier.cc, src/edit_pkg_hier.h:
Update for the new display protocols; add missing copyright
Modified: branches/aptitude-0.3/aptitude/src/load_config.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/load_config.cc (original)
+++ branches/aptitude-0.3/aptitude/src/load_config.cc Tue Jun 7 17:03:09 2005
@@ -4,7 +4,7 @@
#include "aptitude.h"
-#include "vscreen/config/colors.h"
+#include "vscreen/config/style.h"
#include "vscreen/config/keybindings.h"
#include <apt-pkg/configuration.h>
@@ -17,7 +17,83 @@
using namespace std;
-void load_colors(std::string group, bool use_theme)
+static int parse_color(const string &s)
+{
+ const char * const cs=s.c_str();
+
+ if(!strcasecmp(cs, "black"))
+ return COLOR_BLACK;
+ else if(!strcasecmp(cs, "red"))
+ return COLOR_RED;
+ else if(!strcasecmp(cs, "green"))
+ return COLOR_GREEN;
+ else if(!strcasecmp(cs, "yellow"))
+ return COLOR_YELLOW;
+ else if(!strcasecmp(cs, "blue"))
+ return COLOR_BLUE;
+ else if(!strcasecmp(cs, "magenta"))
+ return COLOR_MAGENTA;
+ else if(!strcasecmp(cs, "cyan"))
+ return COLOR_CYAN;
+ else if(!strcasecmp(cs, "white"))
+ return COLOR_WHITE;
+ else
+ {
+ _error->Error(_("Unrecognized color name \"%s\""), cs);
+ return -1;
+ }
+}
+
+static attr_t parse_attr(const char *s, size_t len)
+{
+ if(!strncasecmp(s, "standout", len))
+ return A_STANDOUT;
+ else if(!strncasecmp(s, "underline", len))
+ return A_UNDERLINE;
+ else if(!strncasecmp(s, "reverse", len))
+ return A_REVERSE;
+ else if(!strncasecmp(s, "blink", len))
+ return A_BLINK;
+ else if(!strncasecmp(s, "dim", len))
+ return A_DIM;
+ else if(!strncasecmp(s, "bold", len))
+ return A_BOLD;
+ else if(!strncasecmp(s, "protect", len))
+ return A_PROTECT;
+ else if(!strncasecmp(s, "invisible", len))
+ return A_INVIS;
+ else if(!strncasecmp(s, "altcharset", len))
+ return A_ALTCHARSET;
+ else
+ {
+ _error->Error(_("Unrecognized attribute name \"%s\""), s);
+ return 0;
+ }
+}
+
+static attr_t parse_attrs(const string &s)
+{
+ attr_t rval=0;
+
+ const char * const cs=s.c_str();
+
+ string::size_type start=0;
+ while(start<s.size())
+ {
+ while(start < s.size() && s[start] == ',')
+ ++start;
+
+ string::size_type len=0;
+ while(start+len < s.size() && s[start+len] != ',')
+ ++len;
+
+ rval|=parse_attr(cs+start, len);
+ }
+
+ return rval;
+}
+
+void load_styles(std::string group, bool use_theme)
{
Configuration::Item const *cfg_grp=aptcfg->get_cfg(use_theme)->Tree(group.c_str());
@@ -27,33 +103,38 @@
for(Configuration::Item const *i=cfg_grp->Child; i; i=i->Next)
{
if(!i->Value.empty())
- _error->Error(_("Invalid entry in color definition group: \"%s\""), i->Tag.c_str());
+ _error->Error(_("Invalid entry in style definition group: \"%s\""), i->Tag.c_str());
else if(i->Tag.empty())
- _error->Error(_("Invalid tagless entry in color definition group: \"%s\""), i->Value.c_str());
- else if(!i->Child || !i->Child->Next || i->Child->Next->Next)
- _error->Error(_("Need exactly two colors in color definition \"%s\""), i->Tag.c_str());
+ _error->Error(_("Invalid tagless entry in style definition group: \"%s\""), i->Value.c_str());
else
{
- short fg, bg;
- int attr=0;
- string fgstr=i->Child->Value;
-
- // Support bold attribute on the foreground color.
- if(tolower(fgstr[0])=='b' && tolower(fgstr[1])=='o' &&
- tolower(fgstr[2])=='l' && tolower(fgstr[3])=='d')
+ style curr;
+
+ for(Configuration::Item const *j=i->Child; j; j=j->Next)
{
- attr|=A_BOLD;
- fgstr=string(fgstr,4);
+ if(!strcasecmp(j->Tag.c_str(), "fg"))
+ curr.set_fg(parse_color(j->Tag));
+ else if(!strcasecmp(j->Tag.c_str(), "bg"))
+ curr.set_bg(parse_color(j->Tag));
+ else
+ {
+ void (style::*f)(attr_t)=NULL;
+ if(!strcasecmp(j->Tag.c_str(), "set"))
+ f=&style::attrs_on;
+ else if(!strcasecmp(j->Tag.c_str(), "clear"))
+ f=&style::attrs_off;
+ else if(!strcasecmp(j->Tag.c_str(), "flip"))
+ f=&style::attrs_flip;
+
+ if(!f)
+ _error->Error(_("Unknown style attribute %s"),
+ j->Tag.c_str());
+ else
+ (curr.*f)(parse_attrs(j->Value));
+ }
}
- if(!parse_color(fgstr, fg))
- _error->Error(_("Can't parse foreground \"%s\"of color \"%s\""),
- fgstr.c_str(), i->Tag.c_str());
- else if(!parse_color(i->Child->Next->Value, bg))
- _error->Error(_("Can't parse background \"%s\" of color \"%s\""),
- i->Child->Next->Value.c_str(), i->Tag.c_str());
- else
- set_color(i->Tag, fg, bg, attr);
+ set_style(i->Tag, curr);
}
}
}