Przeglądaj źródła

dselect: Use a new attribute array instead of separate attribute variables

Guillem Jover 14 lat temu
rodzic
commit
c49aec380a
6 zmienionych plików z 62 dodań i 76 usunięć
  1. 4 4
      dselect/basecmds.cc
  2. 22 33
      dselect/baselist.cc
  3. 19 22
      dselect/dselect.h
  4. 5 5
      dselect/methlist.cc
  5. 2 2
      dselect/pkginfo.cc
  6. 10 10
      dselect/pkgtop.cc

+ 4 - 4
dselect/basecmds.cc

@@ -162,7 +162,7 @@ void baselist::displayhelp(const struct helpmenuentry *helpmenu, int key) {
   int maxx, maxy, i, nextkey;
 
   getmaxyx(stdscr,maxy,maxx);
-  wbkgdset(stdscr, ' ' | helpscreen_attr);
+  wbkgdset(stdscr, ' ' | part_attr[helpscreen]);
   clearok(stdscr,TRUE);
   for (;;) {
     werase(stdscr);
@@ -172,14 +172,14 @@ void baselist::displayhelp(const struct helpmenuentry *helpmenu, int key) {
     if (hme->key) {
       int x, y DPKG_ATTR_UNUSED;
 
-      attrset(helpscreen_attr);
+      attrset(part_attr[helpscreen]);
       mvaddstr(1,0, gettext(hme->msg->text));
-      attrset(title_attr);
+      attrset(part_attr[title]);
       mvaddstr(0,0, _("Help: "));
       addstr(gettext(hme->msg->title));
       getyx(stdscr,y,x);
       while (++x<maxx) addch(' ');
-      attrset(thisstate_attr);
+      attrset(part_attr[thisstate]);
       mvaddstr(maxy-1,0,
 _("Press ? for help menu, . for next topic, <space> to exit help."));
       getyx(stdscr,y,x);

+ 22 - 33
dselect/baselist.cc

@@ -124,34 +124,22 @@ void baselist::startdisplay() {
     for (i = 1; i < numscreenparts; i++) {
        if (init_pair(i, color[i].fore, color[i].back) != OK)
          ohshite(_("failed to allocate colour pair"));
+       part_attr[i] = COLOR_PAIR(i) | color[i].attr;
     }
-    /* TODO: should use an array of attr's, indexed by attr name. Oh well. */
-    list_attr=		COLOR_PAIR(list)	| color[list].attr;
-    listsel_attr= 	COLOR_PAIR(listsel)	| color[listsel].attr;
-    title_attr=		COLOR_PAIR(title)	| color[title].attr;
-    thisstate_attr=	COLOR_PAIR(thisstate)	| color[thisstate].attr;
-    selstate_attr=	COLOR_PAIR(selstate)	| color[selstate].attr;
-    selstatesel_attr= 	COLOR_PAIR(selstatesel)	| color[selstatesel].attr;
-    colheads_attr=	COLOR_PAIR(colheads)	| color[colheads].attr;
-    query_attr=		COLOR_PAIR(query)	| color[query].attr;
-    info_attr=		COLOR_PAIR(info)	| color[info].attr;
-    info_headattr=	COLOR_PAIR(info_head)	| color[info_head].attr;
-    whatinfo_attr=	COLOR_PAIR(whatinfo)	| color[whatinfo].attr;
-    helpscreen_attr=	COLOR_PAIR(helpscreen)	| color[helpscreen].attr;
   } else {
     /* User defined attributes for B&W mode are not currently supported. */
-    title_attr= A_REVERSE;
-    thisstate_attr= A_STANDOUT;
-    list_attr= 0;
-    listsel_attr= A_STANDOUT;
-    selstate_attr= A_BOLD;
-    selstatesel_attr= A_STANDOUT;
-    colheads_attr= A_BOLD;
-    query_attr= title_attr;
-    info_attr= list_attr;
-    info_headattr= A_BOLD;
-    whatinfo_attr= thisstate_attr;
-    helpscreen_attr= A_NORMAL;
+    part_attr[title] = A_REVERSE;
+    part_attr[thisstate] = A_STANDOUT;
+    part_attr[list] = 0;
+    part_attr[listsel] = A_STANDOUT;
+    part_attr[selstate] = A_BOLD;
+    part_attr[selstatesel] = A_STANDOUT;
+    part_attr[colheads]= A_BOLD;
+    part_attr[query] = part_attr[title];
+    part_attr[info] = part_attr[list];
+    part_attr[info_head] = A_BOLD;
+    part_attr[whatinfo] = part_attr[thisstate];
+    part_attr[helpscreen] = A_NORMAL;
   }
 
   // set up windows and pads, based on screen size
@@ -165,31 +153,31 @@ void baselist::startdisplay() {
 
   titlewin= newwin(1,xmax, 0,0);
   if (!titlewin) ohshite(_("failed to create title window"));
-  wattrset(titlewin,title_attr);
+  wattrset(titlewin, part_attr[title]);
 
   whatinfowin= newwin(1,xmax, whatinfo_row,0);
   if (!whatinfowin) ohshite(_("failed to create whatinfo window"));
-  wattrset(whatinfowin,whatinfo_attr);
+  wattrset(whatinfowin, part_attr[whatinfo]);
 
   listpad = newpad(ymax, total_width);
   if (!listpad) ohshite(_("failed to create baselist pad"));
 
   colheadspad= newpad(1, total_width);
   if (!colheadspad) ohshite(_("failed to create heading pad"));
-  wattrset(colheadspad,colheads_attr);
+  wattrset(colheadspad, part_attr[colheads]);
 
   thisstatepad= newpad(1, total_width);
   if (!thisstatepad) ohshite(_("failed to create thisstate pad"));
-  wattrset(thisstatepad,thisstate_attr);
+  wattrset(thisstatepad, part_attr[thisstate]);
 
   infopad= newpad(MAX_DISPLAY_INFO, total_width);
   if (!infopad) ohshite(_("failed to create info pad"));
-  wattrset(infopad,info_attr);
-  wbkgdset(infopad, ' ' | info_attr);
+  wattrset(infopad, part_attr[info]);
+  wbkgdset(infopad, ' ' | part_attr[info]);
 
   querywin= newwin(1,xmax,ymax-1,0);
   if (!querywin) ohshite(_("failed to create query window"));
-  wbkgdset(querywin, ' ' | query_attr);
+  wbkgdset(querywin, ' ' | part_attr[query]);
 
   if (cursorline >= topofscreen + list_height) topofscreen= cursorline;
   if (topofscreen > nitems - list_height) topofscreen= nitems - list_height;
@@ -225,7 +213,8 @@ void baselist::enddisplay() {
 void baselist::redrawall() {
   redrawtitle();
   redrawcolheads();
-  wattrset(listpad,list_attr); mywerase(listpad);
+  wattrset(listpad, part_attr[list]);
+  mywerase(listpad);
   ldrawnstart= ldrawnend= -1; // start is first drawn; end is first undrawn; -1=none
   refreshlist();
   redrawthisstate();

+ 19 - 22
dselect/dselect.h

@@ -45,6 +45,23 @@ struct helpmenuentry {
 
 struct keybindings;
 
+enum screenparts {
+	background,
+	list,
+	listsel,
+	title,
+	thisstate,
+	selstate,
+	selstatesel,
+	colheads,
+	query,
+	info,
+	info_head,
+	whatinfo,
+	helpscreen,
+	numscreenparts,
+};
+
 class baselist {
 protected:
   // Screen dimensions &c.
@@ -52,11 +69,8 @@ protected:
   int title_height, colheads_height, list_height;
   int thisstate_height, info_height, whatinfo_height;
   int colheads_row, thisstate_row, info_row, whatinfo_row, list_row;
-  int list_attr, listsel_attr, title_attr, colheads_attr, info_attr;
-  int info_headattr, whatinfo_attr;
-  int thisstate_attr, query_attr;
-  int selstate_attr, selstatesel_attr;
-  int helpscreen_attr;
+
+  int part_attr[numscreenparts];
 
   int gap_width;
   int total_width;
@@ -151,23 +165,6 @@ void cursesoff();
 
 extern int expertmode;
 
-enum screenparts {
-       background,
-       list,
-       listsel,
-       title,
-       thisstate,
-       selstate,
-       selstatesel,
-       colheads,
-       query,
-       info,
-       info_head,
-       whatinfo,
-       helpscreen,
-       numscreenparts,
-};
-
 struct colordata {
        int fore;
        int back;

+ 5 - 5
dselect/methlist.cc

@@ -88,10 +88,10 @@ void methodlist::redraw1itemsel(int index, int selected) {
   int i;
   const char *p;
 
-  wattrset(listpad, selected ? listsel_attr : list_attr);
+  wattrset(listpad, part_attr[selected ? listsel : list]);
   mvwaddch(listpad,index,0,
            table[index] == coption ? '*' : ' ');
-  wattrset(listpad, selected ? listsel_attr : list_attr);
+  wattrset(listpad, part_attr[selected ? listsel : list]);
   mvwprintw(listpad,index,name_column-1, " %-*.*s ",
             name_width, name_width, table[index]->name);
 
@@ -109,7 +109,7 @@ void methodlist::redraw1itemsel(int index, int selected) {
 
 void methodlist::redrawcolheads() {
   if (colheads_height) {
-    wattrset(colheadspad,colheads_attr);
+    wattrset(colheadspad, part_attr[colheads]);
     mywerase(colheadspad);
     mvwaddstr(colheadspad,0,0, "  ");
     mvwaddnstr(colheadspad,0,name_column, _("Abbrev."), name_width);
@@ -182,11 +182,11 @@ quitaction methodlist::display() {
 void methodlist::itd_description() {
   whatinfovb(_("Explanation"));
 
-  wattrset(infopad,info_headattr);
+  wattrset(infopad, part_attr[info_head]);
   waddstr(infopad, table[cursorline]->name);
   waddstr(infopad," - ");
   waddstr(infopad, table[cursorline]->summary);
-  wattrset(infopad,info_attr);
+  wattrset(infopad, part_attr[info]);
 
   const char *m= table[cursorline]->description;
   if (!m || !*m) m= _("No explanation available.");

+ 2 - 2
dselect/pkginfo.cc

@@ -112,11 +112,11 @@ void packagelist::itd_description() {
       m = _("No description available.");
     const char *p= strchr(m,'\n');
     int l= p ? (int)(p-m) : strlen(m);
-    wattrset(infopad,info_headattr);
+    wattrset(infopad, part_attr[info_head]);
     waddstr(infopad, table[cursorline]->pkg->set->name);
     waddstr(infopad," - ");
     waddnstr(infopad,m,l);
-    wattrset(infopad,info_attr);
+    wattrset(infopad, part_attr[info]);
     if (p) {
       waddstr(infopad,"\n\n");
       wordwrapinfo(1,++p);

+ 10 - 10
dselect/pkgtop.cc

@@ -142,7 +142,7 @@ void packagelist::redraw1itemsel(int index, int selected) {
   const struct pkgbin *info = &pkg->available;
   int screenline = index - topofscreen;
 
-  wattrset(listpad, selected ? listsel_attr : list_attr);
+  wattrset(listpad, part_attr[selected ? listsel : list]);
 
   if (pkg->set->name) {
     if (verbose) {
@@ -157,11 +157,11 @@ void packagelist::redraw1itemsel(int index, int selected) {
               /* FIXME: keep this? */
               /*table[index]->original == table[index]->selected ? "(same)"
               : */gettext(wantstrings[table[index]->original]));
-      wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
+      wattrset(listpad, part_attr[selected ? selstatesel : selstate]);
       wprintw(listpad, "%-*.*s",
               status_want_width, status_want_width,
               gettext(wantstrings[table[index]->selected]));
-      wattrset(listpad, selected ? listsel_attr : list_attr);
+      wattrset(listpad, part_attr[selected ? listsel : list]);
       waddch(listpad, ' ');
 
       mvwprintw(listpad, screenline, priority_column - 1, " %-*.*s",
@@ -176,9 +176,9 @@ void packagelist::redraw1itemsel(int index, int selected) {
              /*table[index]->original == table[index]->selected ? ' '
              : */wantchars[table[index]->original]);
 
-      wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
+      wattrset(listpad, part_attr[selected ? selstatesel : selstate]);
       waddch(listpad, wantchars[table[index]->selected]);
-      wattrset(listpad, selected ? listsel_attr : list_attr);
+      wattrset(listpad, part_attr[selected ? listsel : list]);
 
       wmove(listpad, screenline, priority_column - 1);
       waddch(listpad, ' ');
@@ -208,11 +208,11 @@ void packagelist::redraw1itemsel(int index, int selected) {
     if (versionavailable_width) {
       if (informativeversion(&pkg->available.version) &&
           versioncompare(&pkg->available.version,&pkg->installed.version) > 0)
-        wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
+        wattrset(listpad, part_attr[selected ? selstatesel : selstate]);
       mvwprintw(listpad, screenline, versionavailable_column, "%-*.*s",
                 versionavailable_width, versionavailable_width,
                 versiondescribe(&pkg->available.version, vdew_nonambig));
-      wattrset(listpad, selected ? listsel_attr : list_attr);
+      wattrset(listpad, part_attr[selected ? listsel : list]);
       waddch(listpad,' ');
     }
 
@@ -236,10 +236,10 @@ void packagelist::redraw1itemsel(int index, int selected) {
     while (j-- >0) { waddch(listpad,ACS_HLINE); i--; }
     waddch(listpad,' ');
 
-    wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
+    wattrset(listpad, part_attr[selected ? selstatesel : selstate]);
     p= buf;
     while (i>0 && *p) { waddnstr(listpad, p,1); p++; i--; }
-    wattrset(listpad, selected ? listsel_attr : list_attr);
+    wattrset(listpad, part_attr[selected ? listsel : list]);
 
     waddch(listpad,' ');
     j= (indent<<1) + 1;
@@ -253,7 +253,7 @@ void packagelist::redraw1itemsel(int index, int selected) {
 
 void packagelist::redrawcolheads() {
   if (colheads_height) {
-    wattrset(colheadspad,colheads_attr);
+    wattrset(colheadspad, part_attr[colheads]);
     mywerase(colheadspad);
     if (verbose) {
       wmove(colheadspad,0,0);