diff --git a/src/Makefile.am b/src/Makefile.am index dfcb0b09c41d4ec3871fcda3720cad19fce8c07c..1bf484e3cde1e5e36c5e668f198ca9a1a12317a0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ bin_PROGRAMS = ncdu -ncdu_SOURCES = browser.c calc.c exclude.c main.c util.c +ncdu_SOURCES = browser.c calc.c exclude.c help.c main.c util.c -noinst_HEADERS = browser.h calc.h exclude.h util.h ncdu.h +noinst_HEADERS = browser.h calc.h exclude.h help.h ncdu.h util.h diff --git a/src/browser.c b/src/browser.c index b74d590722e07c0b041d0b83daf480db81b17c70..3c7a86b68f45a6a41bf7bf61dc1ae0af498d2f68 100644 --- a/src/browser.c +++ b/src/browser.c @@ -27,6 +27,7 @@ #include "browser.h" #include "util.h" #include "calc.h" +#include "help.h" #include <string.h> #include <stdlib.h> @@ -434,11 +435,11 @@ int browse_key(int ch) { case 'i': toggle(flags, BF_INFO); break; - /* case '?': - showHelp(); + help_init(); nonfo++; break; + /* case 'd': drawBrowser(0); n = selected(); diff --git a/src/help.c b/src/help.c index 67eafa50d2ba713f6193bd5643163f9e8fad220e..0d5c34c6d6d3f7894366ed7c7d79089cb6b30426 100644 --- a/src/help.c +++ b/src/help.c @@ -24,9 +24,18 @@ */ #include "ncdu.h" +#include "help.h" +#include "browser.h" +#include "util.h" + +#include <ncurses.h> +#include <string.h> + + +int page, start; -#define KEYS 14 +#define KEYS 14 char *keys[KEYS*2] = { /*|----key----| |----------------description----------------|*/ "up/down", "Cycle through the items", @@ -46,10 +55,11 @@ char *keys[KEYS*2] = { }; - -void drawHelp(int page, int start) { +int help_draw() { int i, line; + browse_draw(); + nccreate(15, 60, "ncdu help"); ncaddstr(13, 38, "Press q to continue"); @@ -145,54 +155,50 @@ void drawHelp(int page, int start) { ncaddstr(10, 16, "http://dev.yorhel.nl/ncdu/"); break; } - refresh(); + return 0; } -void showHelp(void) { - int p = 1, st = 0, ch; - - drawHelp(p, st); - while((ch = getch())) { - switch(ch) { - case ERR: - break; - case '1': - case '2': - case '3': - p = ch-'0'; - st = 0; - break; - case KEY_RIGHT: - case KEY_NPAGE: - if(++p > 3) - p = 3; - st = 0; - break; - case KEY_LEFT: - case KEY_PPAGE: - if(--p < 1) - p = 1; - st = 0; - break; - case KEY_DOWN: - case ' ': - if(st < KEYS-10) - st++; - break; - case KEY_UP: - if(st > 0) - st--; - break; - case KEY_RESIZE: - ncresize(); - drawBrowser(0); - break; - default: - return; - } - drawHelp(p, st); +int help_key(int ch) { + switch(ch) { + case '1': + case '2': + case '3': + page = ch-'0'; + start = 0; + break; + case KEY_RIGHT: + case KEY_NPAGE: + if(++page > 3) + page = 3; + start = 0; + break; + case KEY_LEFT: + case KEY_PPAGE: + if(--page < 1) + page = 1; + start = 0; + break; + case KEY_DOWN: + case ' ': + if(start < KEYS-10) + start++; + break; + case KEY_UP: + if(start > 0) + start--; + break; + default: + pstate = ST_BROWSE; } + return 0; +} + + +void help_init() { + page = 1; + start = 0; + pstate = ST_HELP; } diff --git a/src/help.h b/src/help.h new file mode 100644 index 0000000000000000000000000000000000000000..6d21042dd858bc9514dbfa8fd98fd31187d6d0a8 --- /dev/null +++ b/src/help.h @@ -0,0 +1,37 @@ +/* ncdu - NCurses Disk Usage + + Copyright (c) 2007-2009 Yoran Heling + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +#ifndef _help_h +#define _help_h + +#include "ncdu.h" + +int help_key(int); +int help_draw(void); +void help_init(); + + +#endif + diff --git a/src/main.c b/src/main.c index b9bc901e68b8484803c9c4d333a07560a7f14f31..888aaade35a568c8470653623b280b43437b6c73 100644 --- a/src/main.c +++ b/src/main.c @@ -45,6 +45,7 @@ void screen_draw() { switch(pstate) { case ST_CALC: n = calc_draw(); break; case ST_BROWSE: n = browse_draw(); break; + case ST_HELP: n = help_draw(); break; } if(!n) refresh(); @@ -66,6 +67,7 @@ int input_handle(int wait) { switch(pstate) { case ST_CALC: return calc_key(ch); case ST_BROWSE: return browse_key(ch); + case ST_HELP: return help_key(ch); } screen_draw(); } @@ -153,7 +155,7 @@ int main(int argc, char **argv) { if(pstate == ST_CALC) calc_process(); else if(input_handle(0)) - break; + break; } erase();