diff options
author | Sven Eden <yamakuzure@gmx.net> | 2013-09-12 08:43:08 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2013-09-12 08:43:08 +0200 |
commit | f7c1e82d76ebdada260d8cfcad3e61e845ebd75a (patch) | |
tree | 416d6ea311d3cb78771d68b7e34199cbd870e96a | |
parent | types: New function setKeyDispLen() calculates the display length of buttons ... (diff) | |
download | ufed-f7c1e82d76ebdada260d8cfcad3e61e845ebd75a.tar.gz ufed-f7c1e82d76ebdada260d8cfcad3e61e845ebd75a.tar.bz2 ufed-f7c1e82d76ebdada260d8cfcad3e61e845ebd75a.zip |
Key descriptions (buttons) are now recalculated to only use as much space as they actually can have.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | ufed-curses-checklist.c | 45 | ||||
-rw-r--r-- | ufed-curses.c | 75 | ||||
-rw-r--r-- | ufed-curses.h | 2 |
4 files changed, 75 insertions, 48 deletions
@@ -18,3 +18,4 @@ ufed ufed-curses testflags.txt ufed.8 +0.90_get_portdir_from_portageq.patch.gz diff --git a/ufed-curses-checklist.c b/ufed-curses-checklist.c index a512869..29c9a0e 100644 --- a/ufed-curses-checklist.c +++ b/ufed-curses-checklist.c @@ -642,20 +642,47 @@ int main(void) initcurses(); - /* The keys to use differ whether ro_mode is true or false */ + /* Some notes on the keys: + * - The key '\0' (or simply 0) stops the processing of the + * array. This means, templates or future keys can be added + * beforehand behind a key=0 line - they will never be + * displayed. + * - key < 0 will show the key name only. This is useful for + * adding spaces or titles. + * - The texts are dynamic. As a smaller display shows only + * a limited amount of characters, texts should be crafted to + * start with their core information. + * Bad : "Show only global" => "Show only g" => "Show o" + * Good: "Global flags" => "Global flag" => "Global" + */ sKey keys[] = { - /* Row 0 - General keys */ + /* Row 0 left - General keys */ MAKE_KEY('?', "?:", "Help", "", "", NULL, 0), MAKE_KEY('\n', "Enter:", "Save", "Exit", "", (int*)&ro_mode, 0), MAKE_KEY('\033', "Esc:", "Cancel", "Exit", "", (int*)&ro_mode, 0), - /* Row 1 - F-KEy toggles */ - MAKE_KEY(KEY_F( 5), "F5:", "global", "local", "all", (int*)&e_scope, 1), - MAKE_KEY(KEY_F( 6), "F6:", "installed", "not installed", "all", (int*)&e_state, 1), - MAKE_KEY(KEY_F( 7), "F7:", "masked", "all", "unmasked", (int*)&e_mask, 1), - MAKE_KEY(KEY_F( 9), "F9:", "desc left", "desc right", "", (int*)&e_order, 1), - MAKE_KEY(KEY_F(10), "F10:", "stripped", "full", "", (int*)&e_desc, 1), - MAKE_KEY('\0', "", "", "", "", NULL, 0) + /* Row 0 right - Display style (description) */ + MAKE_KEY(-1, " ", "", "", "", NULL, 0), + MAKE_KEY(-1, "Display: ", "", "", "", NULL, 0), + MAKE_KEY(KEY_F( 9), "F9:", "Pkg right", "Pkg left", "", (int*)&e_order, 0), + MAKE_KEY(KEY_F(10), "F10:", "Stripped description", "Normal description", "", (int*)&e_desc, 0), + + /* Row 1 - Filter settings */ + MAKE_KEY(-1, "Filter: ", "", "", "", NULL, 1), + MAKE_KEY(KEY_F( 5), "F5:", + "Global flags", "Local flags", "All (Global and Local)", + (int*)&e_scope, 1), + MAKE_KEY(KEY_F( 6), "F6:", + "Installed packages", "Not installed packages", "All", + (int*)&e_state, 1), + MAKE_KEY(KEY_F( 7), "F7:", + "Masked/Forced flags", "All (Masked and Normal)", "Unmasked flags", + (int*)&e_mask, 1), + MAKE_KEY(0, "", "", "", "", NULL, 0), /* processing stops here (row _MUST_ be 0 here!) */ + + /* future keys, that are planned */ + MAKE_KEY(KEY_F( 8), "F8:", "Unknown flags", "Known flags", "all", NULL, 1), + MAKE_KEY(KEY_F(11), "F11:", "Wrap descriptions", "One-line-descriptions", "", NULL, 0) }; result = maineventloop(ro_mode ? subtitle_ro : subtitle_rw, diff --git a/ufed-curses.c b/ufed-curses.c index 2428cfd..70a0ac7 100644 --- a/ufed-curses.c +++ b/ufed-curses.c @@ -8,7 +8,7 @@ /* internal members */ static const char* subtitle = NULL; -static const sKey* keys = NULL; +static sKey* keys = NULL; static sFlag* currentflag = NULL; static sFlag* flags = NULL; static bool withSep = false; @@ -141,27 +141,21 @@ void drawBottom(bool withSep) mvwaddch(w, 3, bWidth - 1, ACS_LRCORNER); // lower right corner on line 3 if (keys) { - const sKey* key = keys; - char buf[COLS + 1]; - int pos = 2; - int row = 0; - int len_full = 0; - int len_name = 0; - int len_desc = 0; - - while (key->key != '\0') { - if (row != key->row) { - row = key->row; - pos = 2; - } + setKeyDispLen(keys, bWidth - 1); - len_name = key->name_len; - len_desc = key->desc_len; - len_full = len_name + len_desc; + sKey* key = keys; + char buf[COLS + 1]; + int row = 0; + int pos = 2; - if (pos < (bWidth - 2)) { - if (len_full > (bWidth - 2 - pos)) - len_full = bWidth - 2 - pos; + while (key->key) { + int len_name = key->name_len; + int len_desc = key->disp_len; + int len_full = len_name + len_desc; + + if (pos < (bWidth - 1)) { + if (len_full > (bWidth - 1 - pos)) + len_full = bWidth - 1 - pos; /* Write name of the key */ if (len_name > len_full) @@ -185,8 +179,12 @@ void drawBottom(bool withSep) } } ++key; - } - } + if (row != key->row) { + row = key->row; + pos = 2; + } + } // End of key display loop + } // End of having keys wnoutrefresh(w); @@ -377,9 +375,6 @@ void drawTop(bool withSep) } mvwaddstr(w, 0, 0, buf); - /// REMOVEME: Stop wasting space - //whline(w, ACS_HLINE, wWidth(Top)); - wattrset(w, COLOR_PAIR(2) | A_BOLD); mvwaddch(w, 1, 0, ACS_ULCORNER); whline(w, ACS_HLINE, wWidth(Top)-2); @@ -524,7 +519,7 @@ int maineventloop( int(*_callback)(sFlag**, int), int(*_drawflag)(sFlag*, bool), sFlag* _flags, - const sKey *_keys, + sKey *_keys, bool _withSep) { int result; @@ -540,7 +535,7 @@ int maineventloop( { sFlag* temp = flags; flags = _flags; _flags = temp; } - { const sKey *temp = keys; + { sKey *temp = keys; keys = _keys; _keys = temp; } @@ -670,14 +665,14 @@ int maineventloop( } // End of alternate scrollbar event } // End of having a scrollbar } else if(wmouse_trafo(win(Bottom), &event.y, &event.x, FALSE)) { + WINDOW* w = win(Bottom); + int bWidth = wWidth(Bottom); if( (event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED)) && (event.y >= 1) && (event.y <= 2)) { const sKey* key = keys; char buf[COLS + 1]; int x = event.x; int y = event.y; - int len_name = 0; - int len_desc = 0; if((x < 2) || (y < 1) || (y > 2)) continue; x -= 2; @@ -688,25 +683,29 @@ int maineventloop( // Check key for ( ; (key->row == y) && (x >= 0) && (key->key != '\0'); key++) { - len_name = key->name_len; - len_desc = key->desc_len; + int len_name = key->name_len; + int len_desc = key->disp_len; if ( (key->key > 0) && (x > len_name) && (x < (len_name + len_desc) ) ) { event.x -= x - len_name; + if (len_desc > (bWidth - 1 - event.x)) + len_desc = bWidth - 1 - event.x; + sprintf(buf, "%-*.*s", len_desc - 1, len_desc - 1, key->desc[*key->idx]); - wattrset(win(Bottom), COLOR_PAIR(7) | A_BOLD); - mvwaddstr(win(Bottom), event.y, event.x, buf); - wmove(win(Bottom), event.y, event.x); - wrefresh(win(Bottom)); + wattrset(w, COLOR_PAIR(7) | A_BOLD); + mvwaddstr(w, event.y, event.x, buf); + + wmove(w, event.y, event.x); + wrefresh(w); usleep(100000); - wattrset(win(Bottom), COLOR_PAIR(6)); - waddstr(win(Bottom), buf); + wattrset(w, COLOR_PAIR(6)); + waddstr(w, buf); - wnoutrefresh(win(Bottom)); + wnoutrefresh(w); c = key->key; goto check_key; } diff --git a/ufed-curses.h b/ufed-curses.h index 117500f..bff758d 100644 --- a/ufed-curses.h +++ b/ufed-curses.h @@ -14,7 +14,7 @@ int maineventloop( int (*callback)(sFlag** curr, int key), int (*drawflag)(sFlag* flag, bool highlight), sFlag* flags, - const sKey* keys, + sKey* keys, bool withSep); void resetDisplay(bool withSep); bool scrollcurrent(void); |