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 E0D331384DF for ; Wed, 16 Jan 2013 12:56:48 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0F57021C046; Wed, 16 Jan 2013 12:56:48 +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 3FE5321C046 for ; Wed, 16 Jan 2013 12:56:47 +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 213BF33DAAB for ; Wed, 16 Jan 2013 12:56:46 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id B1048E4086 for ; Wed, 16 Jan 2013 12:56:44 +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: <1358323549.dc50feb37e84cf3dec29eac69143d7e625734cf3.yamakuzure@gentoo> Subject: [gentoo-commits] proj/ufed:master commit in: / X-VCS-Repository: proj/ufed X-VCS-Files: ufed-curses-checklist.c ufed-curses.c ufed-curses.h X-VCS-Directories: / X-VCS-Committer: yamakuzure X-VCS-Committer-Name: Sven Eden X-VCS-Revision: dc50feb37e84cf3dec29eac69143d7e625734cf3 X-VCS-Branch: master Date: Wed, 16 Jan 2013 12:56:44 +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: 1107781c-236f-4ef5-8198-a675b9b146bc X-Archives-Hash: acc26d47f4b397284ab30977acaed4ac commit: dc50feb37e84cf3dec29eac69143d7e625734cf3 Author: Sven Eden gmx de> AuthorDate: Wed Jan 16 08:05:49 2013 +0000 Commit: Sven Eden gmx de> CommitDate: Wed Jan 16 08:05:49 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/ufed.git;a=commit;h=dc50feb3 Added filtering of now transported masked flags. These are not shown, yet, because of the filter being turned off by default. A key to toggle the filtering of masked flags is not implemented, yet. With this commit ufed should not do anything different than in the past. --- ufed-curses-checklist.c | 69 +++++++++++++++++++++++++++++--------------- ufed-curses.c | 73 +++++++++++++++++++++++++++++++++------------- ufed-curses.h | 5 +++ 3 files changed, 103 insertions(+), 44 deletions(-) diff --git a/ufed-curses-checklist.c b/ufed-curses-checklist.c index 50dc1b4..b43ecac 100644 --- a/ufed-curses-checklist.c +++ b/ufed-curses-checklist.c @@ -11,6 +11,41 @@ #include "ufed-curses-help.h" +/* internal types */ +struct flag { + struct item item; + char *name; + char on; + char *state; + char *descr[FLEXIBLE_ARRAY_MEMBER]; +}; + + +/* internal members */ +static struct flag *flags; +static int descriptionleft; +static char *fayt; +static struct item **faytsave; + +#define mkKey(x) x, sizeof(x)-1 +static const struct key keys[] = { + { '?', mkKey("Help (?)") }, + { '\n', mkKey("Save (Return/Enter)") }, + { '\033', mkKey("Cancel (Esc)") }, + { '\0', mkKey("") } +}; +#undef mkKey + + +/* internal prototypes */ +static void free_flags(void); + + +/* external members */ +enum mask showMasked = show_unmasked; //!< Set whether to show masked, unmasked or both flags + + +/* static functions */ static char *getline(FILE *fp) { size_t size; char *result; @@ -45,22 +80,14 @@ static char *getline(FILE *fp) { } size += size/2; } + return NULL; // never reached. } -static struct flag { - struct item item; - char *name; - char on; - char *state; - char *descr[FLEXIBLE_ARRAY_MEMBER]; -} *flags; -static int descriptionleft; - -static void free_flags(void); static void read_flags(void) { FILE *input = fdopen(3, "r"); char *line; int y=0; + if(input==NULL) exit(-1); atexit(&free_flags); @@ -89,23 +116,29 @@ static void read_flags(void) { minwidth = name.end-name.start+11; flag->name = &line[name.start]; + /* check and save current flag setting from configuration */ line[on.end] = '\0'; + flag->item.isMasked = false; if(!strcmp(&line[on.start], "on")) flag->on = '+'; else if(!strcmp(&line[on.start], "off")) flag->on = '-'; else if(!strcmp(&line[on.start], "def")) flag->on = ' '; - else if(!strcmp(&line[on.start], "msk")) + else if(!strcmp(&line[on.start], "msk")) { flag->on = 'm'; + flag->item.isMasked = true; + } else exit(-1); + /* check and set flag state */ line[state.end] = '\0'; if(state.end-state.start != 4) exit(-1); flag->state = &line[state.start]; + /* check and set flag item height */ flag->item.height = ndescr; { int i; for(i=0; idescr[i] = getline(input); @@ -113,6 +146,7 @@ static void read_flags(void) { y += ndescr; + /* Save flag in our linked list */ if(flags==NULL) { flag->item.prev = (struct item *) flag; flag->item.next = (struct item *) flag; @@ -147,14 +181,6 @@ static void free_flags(void) { } } -static const struct key keys[] = { -#define key(x) x, sizeof(x)-1 - { '?', key("Help (?)") }, - { '\n', key("Save (Return/Enter)") }, - { '\033', key("Cancel (Esc)") }, - { '\0', key("") } -#undef key -}; static void drawflag(struct item *item, bool highlight) { struct flag *flag = (struct flag *) item; @@ -182,7 +208,7 @@ static void drawflag(struct item *item, bool highlight) { ? flag->state[1] : ' ' : flag->on, flag->on == ' ' ? ')' : ']', - /* distance and name being masked or not */ + /* distance and name */ minwidth-11, flag->name, /* current selection state */ flag->state); @@ -214,9 +240,6 @@ static void drawflag(struct item *item, bool highlight) { wnoutrefresh(win(List)); } -static char *fayt; -static struct item **faytsave; - static int callback(struct item **currentitem, int key) { if(*fayt!='\0' && key!=KEY_BACKSPACE && (key==' ' || key!=(unsigned char) key || !isprint(key))) { *fayt = '\0'; diff --git a/ufed-curses.c b/ufed-curses.c index 14b41e3..65c4ba8 100644 --- a/ufed-curses.c +++ b/ufed-curses.c @@ -6,6 +6,7 @@ #include #include +/* internal types */ struct window window[wCount] = { { NULL, 0, 0, 5, 0 }, /* Top */ { NULL, 5, 0, -8, 3 }, /* Left */ @@ -16,15 +17,22 @@ struct window window[wCount] = { { NULL, -3, 0, 3, 0 }, /* Bottom */ }; -static const char *subtitle; +/* internal members */ +static const char *subtitle; static const struct key *keys; - static struct item *items, *currentitem; + + +/* external members */ int topy, minwidth; +extern enum mask showMasked; +/* internal prototypes */ static void checktermsize(void); + +/* internal functions */ void initcurses(void) { setlocale(LC_CTYPE, ""); initscr(); @@ -71,19 +79,35 @@ static void checktermsize(void) { static void (*drawitem)(struct item *, bool); void drawitems(void) { - struct item *item; - int y; + struct item *item = currentitem; + int y = item->top - topy; - item = currentitem; - while((y=item->top-topy) > 0) + /* move to the top of the displayed list */ + for ( ; (y > 0) && item; y = item->top - topy) item = item->prev; + /* advance in the list if the top item would be a masked + * flag that is to be filtered out. + * This is needed in two situations. First at the very start + * of the program and second whenever the filtering is + * toggled. The latter resets the list position to guarantee + * a valid display. + */ + if ((show_unmasked == showMasked) && item->isMasked) { + while (item && item->isMasked) { + if (currentitem == item) + currentitem = item->next; + topy += item->height; + item = item->next; + } + } + for(;;) { if(item!=currentitem) (*drawitem)(item, FALSE); y += item->height; item = item->next; - if(y>=wHeight(List)) + if(y >= wHeight(List)) break; if(item==items) { char buf[wWidth(List)]; @@ -221,9 +245,9 @@ static void draw(void) { void scrollcurrent(void) { if(currentitem->top < topy) - topy = max(currentitem->top, currentitem->top+currentitem->height-wHeight(List)); - else if(currentitem->top+currentitem->height > topy+wHeight(List)) - topy = min(currentitem->top+currentitem->height-wHeight(List), currentitem->top); + topy = max(currentitem->top, currentitem->top + currentitem->height - wHeight(List)); + else if( (currentitem->top + currentitem->height) > (topy + wHeight(List))) + topy = min(currentitem->top + currentitem->height - wHeight(List), currentitem->top); else return; drawitems(); @@ -267,6 +291,7 @@ bool yesno(const char *prompt) { break; #endif } + return FALSE; } int maineventloop( @@ -313,7 +338,8 @@ int maineventloop( if(c==KEY_MOUSE) { MEVENT event; if(getmouse(&event)==OK) { - if(mousekey != ERR && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED | BUTTON1_RELEASED)) { + if( (mousekey != ERR) + && (event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED | BUTTON1_RELEASED)) ) { cbreak(); mousekey = ERR; if(!(event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))) @@ -344,8 +370,8 @@ int maineventloop( (*drawitem)(currentitem, TRUE); } } else if(wmouse_trafo(win(Scrollbar), &event.y, &event.x, FALSE)) { - if(event.bstate & (BUTTON1_PRESSED | BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED) - && event.y < wHeight(Scrollbar)-1) { + if( (event.bstate & (BUTTON1_PRESSED | BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED)) + && (event.y < wHeight(Scrollbar)-1) ) { halfdelay(1); #define SIM(key) \ @@ -371,8 +397,6 @@ int maineventloop( for(;;) { c = getch(); switch(c) { - default: - goto check_key; case ERR: continue; case KEY_MOUSE: @@ -393,14 +417,17 @@ int maineventloop( wrefresh(win(List)); } } + break; + default: + goto check_key; } break; } } } } else if(wmouse_trafo(win(Bottom), &event.y, &event.x, FALSE)) { - if(event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED) - && event.y == 1) { + if( (event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED)) + && (event.y == 1) ) { const struct key *key; int x = event.x; if(x < 2) @@ -437,11 +464,13 @@ int maineventloop( switch(c) { case KEY_UP: - if(currentitem->toptop < topy ) { (*drawitem)(currentitem, FALSE); topy--; (*drawitem)(currentitem, TRUE); - } else if(currentitem!=items || topy>currentitem->top) { + } else if( (currentitem!=items || topy>currentitem->top) + && ( !currentitem->prev->isMasked + || (show_unmasked != showMasked)) ) { (*drawitem)(currentitem, FALSE); currentitem = currentitem->prev; scrollcurrent(); @@ -450,11 +479,13 @@ int maineventloop( break; case KEY_DOWN: - if(currentitem->top+currentitem->height>topy+wHeight(List)) { + if( (currentitem->top + currentitem->height) > (topy + wHeight(List)) ) { (*drawitem)(currentitem, FALSE); topy++; (*drawitem)(currentitem, TRUE); - } else if(currentitem->next!=items) { + } else if( (currentitem->next != items) + && ( currentitem->next->isMasked + || (show_masked != showMasked)) ){ (*drawitem)(currentitem, FALSE); currentitem = currentitem->next; scrollcurrent(); diff --git a/ufed-curses.h b/ufed-curses.h index 8730d36..7a97c3e 100644 --- a/ufed-curses.h +++ b/ufed-curses.h @@ -5,14 +5,19 @@ #include enum win { Top, Left, List, Input, Scrollbar, Right, Bottom, wCount }; +enum mask { show_unmasked, show_both, show_masked }; + struct window { WINDOW *win; const int top, left, height, width; }; + struct item { struct item *prev, *next; int top, height; + bool isMasked; }; + struct key { char key; const char *descr;