mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
Converted help.c to the new framework and re-added help window
This commit is contained in:
parent
76a2530579
commit
6568a962bc
5 changed files with 98 additions and 52 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
100
src/help.c
100
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
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
37
src/help.h
Normal file
37
src/help.h
Normal file
|
|
@ -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
|
||||
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue