diff --git a/Makefile.am b/Makefile.am index 41cd6ecf5a02a198ab8e060dc740ba0545ed9019..28e19e76cf262934b03715fbf0fe7260d14e51dd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,6 +13,7 @@ ncdu_SOURCES=\ src/exclude.c\ src/help.c\ src/shell.c\ + src/quit.c\ src/main.c\ src/path.c\ src/util.c @@ -28,6 +29,7 @@ noinst_HEADERS=\ src/global.h\ src/help.h\ src/shell.h\ + src/quit.h\ src/path.h\ src/util.h diff --git a/src/browser.c b/src/browser.c index c49720eb1accc4ff517560ed5a4eede8dfa863f8..d1adb4bcd17eedbbd7643016f688ad4ee2163d10 100644 --- a/src/browser.c +++ b/src/browser.c @@ -397,7 +397,7 @@ int browse_key(int ch) { if(info_show) info_show = 0; else - return 1; + quit_init(); break; case 'g': if(++graph > 3) diff --git a/src/global.h b/src/global.h index 9ba22bae9c965e24b5bbce4436162b09f91e1768..17f192dcff315f61983a9f62661989d2d9d50272 100644 --- a/src/global.h +++ b/src/global.h @@ -56,6 +56,7 @@ #define ST_DEL 2 #define ST_HELP 3 #define ST_SHELL 4 +#define ST_QUIT 5 /* structure representing a file or directory */ @@ -104,5 +105,6 @@ int input_handle(int); #include "path.h" #include "util.h" #include "shell.h" +#include "quit.h" #endif diff --git a/src/main.c b/src/main.c index 206c3b7da9b19f9cb8bcdbe56463fe8baef533dc..6eeca0cb2c7e5c0780a001e2830078a7ae9e1bcc 100644 --- a/src/main.c +++ b/src/main.c @@ -54,6 +54,7 @@ static void screen_draw() { case ST_HELP: help_draw(); break; case ST_SHELL: shell_draw(); break; case ST_DEL: delete_draw(); break; + case ST_QUIT: quit_draw(); break; } } @@ -97,6 +98,7 @@ int input_handle(int wait) { case ST_BROWSE: return browse_key(ch); case ST_HELP: return help_key(ch); case ST_DEL: return delete_key(ch); + case ST_QUIT: return quit_key(ch); } screen_draw(); } diff --git a/src/quit.c b/src/quit.c new file mode 100644 index 0000000000000000000000000000000000000000..6594ded5adc02b68737f01d66dae1ead2bb5ff9b --- /dev/null +++ b/src/quit.c @@ -0,0 +1,55 @@ +/* ncdu - NCurses Disk Usage + + Copyright (c) 2015 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. + +*/ + +#include "global.h" + +#include <ncurses.h> + +/* extern? */ int page, start; + +int quit_key(int ch) { + switch(ch) { + case 'y': + case 'Y': + return 1; + break; + default: + pstate = ST_BROWSE; + } + return 0; +} + +void quit_draw() { + browse_draw(); + + nccreate(4,30, "ncdu confirm quit"); + ncaddstr(2,2, "Really quit? (y/N)"); +} + +void quit_init() { + page = 1; + start = 0; + pstate = ST_QUIT; +} diff --git a/src/quit.h b/src/quit.h new file mode 100644 index 0000000000000000000000000000000000000000..54b03d8afc4cd2533b3f8332a418785701d0f70a --- /dev/null +++ b/src/quit.h @@ -0,0 +1,37 @@ +/* ncdu - NCurses Disk Usage + + Copyright (c) 2015 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 _quit_h +#define _quit_h + +#include "global.h" + +int quit_key(int); +void quit_draw(void); +void quit_init(void); + + +#endif +