From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 816DF138620 for ; Wed, 23 Jan 2013 12:05:32 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 45F77E064A; Wed, 23 Jan 2013 12:05:31 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 4970CE0639 for ; Wed, 23 Jan 2013 12:05:30 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 243EA33DB44 for ; Wed, 23 Jan 2013 12:05:29 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id DFAF4E4079 for ; Wed, 23 Jan 2013 12:05:26 +0000 (UTC) From: "Sven Eden" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sven Eden" Message-ID: <1358755403.876dd7edca1a28acceb95046ce466db0690f60e9.yamakuzure@gentoo> Subject: [gentoo-commits] proj/ufed:master commit in: / X-VCS-Repository: proj/ufed X-VCS-Files: ufed-curses-checklist.c ufed-curses-help.c ufed-curses.c ufed-curses.h X-VCS-Directories: / X-VCS-Committer: yamakuzure X-VCS-Committer-Name: Sven Eden X-VCS-Revision: 876dd7edca1a28acceb95046ce466db0690f60e9 X-VCS-Branch: master Date: Wed, 23 Jan 2013 12:05:26 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 89cc4aad-579a-488f-8374-0b4300d772ab X-Archives-Hash: fcb46c944441d4882fb32f708bab0970 commit: 876dd7edca1a28acceb95046ce466db0690f60e9 Author: Sven Eden gmx de> AuthorDate: Mon Jan 21 08:03:23 2013 +0000 Commit: Sven Eden gmx de> CommitDate: Mon Jan 21 08:03:23 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/ufed.git;a=commit;h=876dd7ed Changed keys display to be more easier to handle. Added convenience methods to set prev/next items to display. Added a method to apply filters. Added a method to reset the display. Optimized filter handling. Prepared the upcoming rewrite of the core display design. (It is not fit to handle filters or wrapped lines.) --- ufed-curses-checklist.c | 40 +++++++--- ufed-curses-help.c | 3 +- ufed-curses.c | 196 +++++++++++++++++++++++++++++----------------- ufed-curses.h | 6 +- 4 files changed, 159 insertions(+), 86 deletions(-) diff --git a/ufed-curses-checklist.c b/ufed-curses-checklist.c index b0b8ff1..a4f65b8 100644 --- a/ufed-curses-checklist.c +++ b/ufed-curses-checklist.c @@ -36,10 +36,12 @@ static const struct key keys[] = { { '?', mkKey("Help (?)") }, { '\n', mkKey("Save (Return/Enter)") }, { '\033', mkKey("Cancel (Esc)") }, - { KEY_F(5), mkKey("Toggle (F5: Mask") }, - { KEY_F(6), mkKey("F6: Pkg") }, -// { KEY_F(7), mkKey("F7: Local") }, -// { KEY_F(8), mkKey("F8: Installed)") }, + { -1, mkKey("Display (") }, + { KEY_F(5), mkKey("Mask (F5)") }, + { KEY_F(6), mkKey("Order (F6)") }, +// { KEY_F(7), mkKey("Local/Global (F7)") }, +// { KEY_F(8), mkKey("Installed (F8)") }, + { -1, mkKey(")") }, { '\0', mkKey("") } }; #undef mkKey @@ -52,6 +54,7 @@ static void free_flags(void); /* external members */ enum mask showMasked = show_unmasked; //!< Set whether to show masked, unmasked or both flags enum order pkgOrder = pkgs_left; //!< Set whether to display package lists left or right of the description +enum scope showScope = show_all; //!< Set whether global, local or all flags are shown int firstNormalY = -1; //!< y of first not masked flag @@ -283,12 +286,17 @@ static void free_flags(void) { } -static void drawflag(struct item *item, bool highlight) { +static int drawflag(struct item *item, bool highlight) { struct flag *flag = (struct flag *) item; char buf[wWidth(List)+1]; char desc[maxDescWidth]; int y = flag->item.top - topy; int idx = 0; + int usedY = 0; + + // Return early if there is nothing to display: + if (!isLegalItem(item)) + return 0; /* Determine with which description to start. * Overly long description lists might not fit on one screen, @@ -318,10 +326,20 @@ static void drawflag(struct item *item, bool highlight) { flag->state); /* print descriptions according to filters - * TODO: Implement local/global and installed/all filters + * TODO: Implement installed/all filters */ if(idx < flag->item.height) { for(;;) { + // Filter global description if it is not wanted: + if (!idx && (show_local == showScope) && flag->item.isGlobal) { + ++idx; + continue; + } + + // Break on local descriptions if they are not wanted: + if (idx && (show_global == showScope)) + break; + // Display flag state sprintf(buf + minwidth, "[%c] ", flag->item.isMasked ? flag->isInstalled[idx] ? 'M' : 'm' @@ -358,6 +376,7 @@ static void drawflag(struct item *item, bool highlight) { waddstr(win(List), buf); y++; idx++; + usedY++; if((idx < flag->item.height) && (y < wHeight(List)) ) { char *p; for(p = buf; p != buf + minwidth; p++) @@ -374,6 +393,7 @@ static void drawflag(struct item *item, bool highlight) { if(highlight) wmove(win(List), max(flag->item.top - topy, 0), 2); wnoutrefresh(win(List)); + return usedY; } static int callback(struct item **currentitem, int key) { @@ -410,14 +430,14 @@ static int callback(struct item **currentitem, int key) { /* if the current flag does not match, search one that does. */ else { do item = item->next; - while(item!=*currentitem && strncasecmp(((struct flag *) item)->name, fayt, n)!=0); + while( (item != *currentitem) + && ( ( strncasecmp(((struct flag *) item)->name, fayt, n) + || !isLegalItem(item)) ) ); /* if there was no match (or the match is filtered), * update the input area to show that there is no match */ - if ( (item == *currentitem) - || ( item->isMasked && (show_unmasked == showMasked)) - || (!item->isMasked && (show_masked == showMasked)) ) { + if (item == *currentitem) { if (item != *currentitem) item = *currentitem; wattrset(win(Input), COLOR_PAIR(4) | A_BOLD | A_REVERSE); diff --git a/ufed-curses-help.c b/ufed-curses-help.c index 79bd35e..c967ff6 100644 --- a/ufed-curses-help.c +++ b/ufed-curses-help.c @@ -170,7 +170,7 @@ static const struct key keys[] = { #undef key }; -static void drawline(struct item *item, bool highlight) { +static int drawline(struct item *item, bool highlight) { struct line *line = (struct line *) item; char buf[wWidth(List)+1]; sprintf(buf, "%-*.*s", wWidth(List), wWidth(List), line->text); @@ -182,6 +182,7 @@ static void drawline(struct item *item, bool highlight) { if(highlight) wmove(win(List), line->item.top-topy, 0); wnoutrefresh(win(List)); + return 1; } static int callback(struct item **currentitem, int key) { diff --git a/ufed-curses.c b/ufed-curses.c index 63797e9..1e9b232 100644 --- a/ufed-curses.c +++ b/ufed-curses.c @@ -28,10 +28,15 @@ static struct item *items, *currentitem; int topy, minwidth; extern enum mask showMasked; extern enum order pkgOrder; +extern enum scope showScope; extern int firstNormalY; + /* internal prototypes */ static void checktermsize(void); +void resetDisplay(); +void setNextItem(int count, bool strict); +void setPrevItem(int count, bool strict); /* internal functions */ @@ -79,7 +84,7 @@ static void checktermsize(void) { } } -static void (*drawitem)(struct item *, bool); +static int (*drawitem)(struct item *, bool); void drawitems(void) { struct item *item = currentitem; @@ -107,8 +112,9 @@ void drawitems(void) { for(;;) { if(item!=currentitem) - (*drawitem)(item, FALSE); - y += item->height; + y += (*drawitem)(item, FALSE); + else + y += item->height; item = item->next; if(y >= wHeight(List)) break; @@ -338,7 +344,7 @@ bool yesno(const char *prompt) { int maineventloop( const char *_subtitle, int(*_callback)(struct item **, int), - void(*_drawitem)(struct item *, bool), + int(*_drawitem)(struct item *, bool), struct item *_items, const struct key *_keys) { int result; @@ -346,7 +352,7 @@ int maineventloop( { const char *temp = subtitle; subtitle=_subtitle; _subtitle=temp; } - { void(*temp)(struct item *, bool) = drawitem; + { int(*temp)(struct item *, bool) = drawitem; drawitem=_drawitem; _drawitem=temp; } { struct item *temp=items; @@ -475,7 +481,7 @@ int maineventloop( continue; x -= 2; for(key = keys; key->key!='\0'; key++) { - if((size_t)x < key->length) { + if( (key->key > 0) && ((size_t)x < key->length)) { event.x -= x; wattrset(win(Bottom), COLOR_PAIR(3) | A_BOLD | A_REVERSE); mvwaddstr(win(Bottom), event.y, event.x, key->descr); @@ -509,83 +515,41 @@ int maineventloop( (*drawitem)(currentitem, FALSE); topy--; (*drawitem)(currentitem, TRUE); - } else if( (currentitem!=items || topy>currentitem->top) - && ( !currentitem->prev->isMasked - || (show_unmasked != showMasked)) ) { - (*drawitem)(currentitem, FALSE); - currentitem = currentitem->prev; - scrollcurrent(); - (*drawitem)(currentitem, TRUE); - } + } else + setPrevItem(1, true); break; case KEY_DOWN: if( (currentitem->top + currentitem->height) > (topy + wHeight(List)) ) { + // Scroll through descriptions if their list is longer than the window (*drawitem)(currentitem, FALSE); topy++; (*drawitem)(currentitem, TRUE); - } else if( (currentitem->next != items) - && ( currentitem->next->isMasked - || (show_masked != showMasked)) ){ - (*drawitem)(currentitem, FALSE); - currentitem = currentitem->next; - scrollcurrent(); - (*drawitem)(currentitem, TRUE); - } + } else + setNextItem(1, true); break; case KEY_PPAGE: - if(currentitem!=items) { - struct item *olditem = currentitem; - (*drawitem)(currentitem, FALSE); - while( (currentitem != items) - && ( (olditem->top - currentitem->prev->top) <= wHeight(List)) - && ( ( !currentitem->prev->isMasked - || (show_unmasked != showMasked)) ) ) { - currentitem = currentitem->prev; - } - scrollcurrent(); - (*drawitem)(currentitem, TRUE); - } + if(currentitem!=items) + setPrevItem(wHeight(List), false); break; case KEY_NPAGE: - if(currentitem->next!=items) { - struct item *olditem = currentitem; - (*drawitem)(currentitem, FALSE); - while( (currentitem->next != items) - && (((currentitem->next->top + currentitem->next->height) - -(olditem->top + olditem->height) ) <= wHeight(List)) - && ( ( currentitem->next->isMasked - || (show_masked != showMasked)) ) ) { - currentitem = currentitem->next; - } - scrollcurrent(); - (*drawitem)(currentitem, TRUE); - } + if(currentitem->next!=items) + setNextItem(wHeight(List), false); break; case KEY_HOME: - if(currentitem!=items) { - (*drawitem)(currentitem, FALSE); - currentitem = items; - if (show_unmasked == showMasked) { - while (currentitem->isMasked) - currentitem = currentitem->next; - } - scrollcurrent(); - (*drawitem)(currentitem, TRUE); - } + if(currentitem!=items) + resetDisplay(); break; case KEY_END: if(currentitem->next!=items) { (*drawitem)(currentitem, FALSE); currentitem = items->prev; - if (show_masked == showMasked) { - while (!currentitem->isMasked) - currentitem = currentitem->prev; - } + while (!isLegalItem(currentitem)) + currentitem = currentitem->prev; scrollcurrent(); (*drawitem)(currentitem, TRUE); } @@ -595,25 +559,21 @@ int maineventloop( if (show_masked == showMasked) showMasked = show_unmasked; else if (show_both == showMasked) showMasked = show_masked; else if (show_unmasked == showMasked) showMasked = show_both; - currentitem = items; - topy = 0; - draw(); + resetDisplay(); break; case KEY_F(6): if (pkgs_left == pkgOrder) pkgOrder = pkgs_right; else pkgOrder = pkgs_left; - draw(); + drawitems(); break; - case KEY_BTAB: - if (show_masked == showMasked) showMasked = show_both; - else if (show_both == showMasked) showMasked = show_unmasked; - else if (show_unmasked == showMasked) showMasked = show_masked; - currentitem = items; - topy = 0; - draw(); - break; +// case KEY_F(7): +// if (show_local == showScope) showScope = show_all; +// else if (show_global == showScope) showScope = show_local; +// else if (show_all == showScope) showScope = show_global; +// resetDisplay(); +// break; #ifdef KEY_RESIZE case KEY_RESIZE: @@ -649,3 +609,93 @@ exit: return result; } + + +/* @brief Set display to first legal item and redraw + */ +void resetDisplay() +{ + (*drawitem)(currentitem, FALSE); + currentitem = items; + while (!isLegalItem(currentitem)) + currentitem = currentitem->next; + topy = currentitem->top; + draw(); +} + + +/* @brief set currentitem to the next item @a count lines away + * @param count set how many lines should be skipped + * @param strict if set to false, at least one item has to be skipped. + */ +void setNextItem(int count, bool strict) +{ + bool result = true; + struct item *curr = currentitem; + int skipped = 0; + + while (result && (skipped < count)) { + if (curr->next == items) + result = false; // The list is finished, no next item to display + else + curr = curr->next; + + // curr is only counted if it is not filtered out: + if (isLegalItem(curr)) + ++skipped; + } // End of trying to find a next item + + if ( (result && strict) || (!strict && skipped) ) { + (*drawitem)(currentitem, FALSE); + currentitem = curr; + scrollcurrent(); + (*drawitem)(currentitem, TRUE); + } +} + + +/* @brief set currentitem to the previous item @a count lines away + * @param count set how many lines should be skipped + * @param strict if set to false, at least one item has to be skipped. + */ +void setPrevItem(int count, bool strict) +{ + bool result = true; + struct item *curr = currentitem; + int skipped = 0; + + while (result && (skipped < count)) { + if (curr == items) + result = false; // The list is finished, no previous item to display + else + curr = curr->prev; + + // curr is only counted if it is not filtered out: + if (isLegalItem(curr)) + ++skipped; + } // End of trying to find next item + + if ( (result && strict) || (!strict && skipped) ) { + (*drawitem)(currentitem, FALSE); + currentitem = curr; + scrollcurrent(); + (*drawitem)(currentitem, TRUE); + } +} + + +/* @brief return true if the given @a item is not filtered out + */ +bool isLegalItem(struct item *item) +{ + if ( // 1: Mask filter + ( ( item->isMasked && (show_unmasked != showMasked)) + || (!item->isMasked && (show_masked != showMasked)) ) + // 2: Global / Local filter + && ( ( item->isGlobal && ( (show_local != showScope) || (item->height > 1) ) ) + || (!item->isGlobal && ( show_global != showScope)) ) ) + return true; + return false; +} + + diff --git a/ufed-curses.h b/ufed-curses.h index a608f33..7a1ca4d 100644 --- a/ufed-curses.h +++ b/ufed-curses.h @@ -6,7 +6,7 @@ #define DEBUG_EXIT 1 -#define DEBUG_TRACE 1 +#undef DEBUG_TRACE #if defined(DEBUG_EXIT) # define ERROR_EXIT(code, fmt, ...) { \ @@ -30,6 +30,7 @@ enum win { Top, Left, List, Input, Scrollbar, Right, Bottom, wCount }; enum mask { show_unmasked, show_both, show_masked }; enum order { pkgs_left, pkgs_right }; +enum scope { show_all, show_global, show_local }; struct window { WINDOW *win; @@ -57,12 +58,13 @@ extern void cursesdone(void); extern int maineventloop( const char *subtitle, int (*callback)(struct item **currentitem, int key), - void(*drawitem)(struct item *item, bool highlight), + int (*drawitem)(struct item *item, bool highlight), struct item *items, const struct key *keys); extern void drawitems(void); extern void scrollcurrent(void); extern bool yesno(const char *); +bool isLegalItem(struct item *item); static inline WINDOW *win(enum win w) { return window[w].win; } static inline int wTop (enum win w) { return (window[w].top >= 0 ? 0 : LINES) + window[w].top ; }