mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-12 17:08:39 -09:00
Confirm quit action with a cancellable dialog.
This commit is contained in:
parent
682add5eae
commit
e96cc36d56
6 changed files with 99 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
55
src/quit.c
Normal file
55
src/quit.c
Normal file
|
|
@ -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;
|
||||
}
|
||||
37
src/quit.h
Normal file
37
src/quit.h
Normal file
|
|
@ -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
|
||||
|
||||
Loading…
Reference in a new issue