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
|
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 "browser.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "calc.h"
|
#include "calc.h"
|
||||||
|
#include "help.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -434,11 +435,11 @@ int browse_key(int ch) {
|
||||||
case 'i':
|
case 'i':
|
||||||
toggle(flags, BF_INFO);
|
toggle(flags, BF_INFO);
|
||||||
break;
|
break;
|
||||||
/*
|
|
||||||
case '?':
|
case '?':
|
||||||
showHelp();
|
help_init();
|
||||||
nonfo++;
|
nonfo++;
|
||||||
break;
|
break;
|
||||||
|
/*
|
||||||
case 'd':
|
case 'd':
|
||||||
drawBrowser(0);
|
drawBrowser(0);
|
||||||
n = selected();
|
n = selected();
|
||||||
|
|
|
||||||
100
src/help.c
100
src/help.c
|
|
@ -24,9 +24,18 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ncdu.h"
|
#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] = {
|
char *keys[KEYS*2] = {
|
||||||
/*|----key----| |----------------description----------------|*/
|
/*|----key----| |----------------description----------------|*/
|
||||||
"up/down", "Cycle through the items",
|
"up/down", "Cycle through the items",
|
||||||
|
|
@ -46,10 +55,11 @@ char *keys[KEYS*2] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int help_draw() {
|
||||||
void drawHelp(int page, int start) {
|
|
||||||
int i, line;
|
int i, line;
|
||||||
|
|
||||||
|
browse_draw();
|
||||||
|
|
||||||
nccreate(15, 60, "ncdu help");
|
nccreate(15, 60, "ncdu help");
|
||||||
ncaddstr(13, 38, "Press q to continue");
|
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/");
|
ncaddstr(10, 16, "http://dev.yorhel.nl/ncdu/");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
refresh();
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void showHelp(void) {
|
int help_key(int ch) {
|
||||||
int p = 1, st = 0, ch;
|
switch(ch) {
|
||||||
|
case '1':
|
||||||
drawHelp(p, st);
|
case '2':
|
||||||
while((ch = getch())) {
|
case '3':
|
||||||
switch(ch) {
|
page = ch-'0';
|
||||||
case ERR:
|
start = 0;
|
||||||
break;
|
break;
|
||||||
case '1':
|
case KEY_RIGHT:
|
||||||
case '2':
|
case KEY_NPAGE:
|
||||||
case '3':
|
if(++page > 3)
|
||||||
p = ch-'0';
|
page = 3;
|
||||||
st = 0;
|
start = 0;
|
||||||
break;
|
break;
|
||||||
case KEY_RIGHT:
|
case KEY_LEFT:
|
||||||
case KEY_NPAGE:
|
case KEY_PPAGE:
|
||||||
if(++p > 3)
|
if(--page < 1)
|
||||||
p = 3;
|
page = 1;
|
||||||
st = 0;
|
start = 0;
|
||||||
break;
|
break;
|
||||||
case KEY_LEFT:
|
case KEY_DOWN:
|
||||||
case KEY_PPAGE:
|
case ' ':
|
||||||
if(--p < 1)
|
if(start < KEYS-10)
|
||||||
p = 1;
|
start++;
|
||||||
st = 0;
|
break;
|
||||||
break;
|
case KEY_UP:
|
||||||
case KEY_DOWN:
|
if(start > 0)
|
||||||
case ' ':
|
start--;
|
||||||
if(st < KEYS-10)
|
break;
|
||||||
st++;
|
default:
|
||||||
break;
|
pstate = ST_BROWSE;
|
||||||
case KEY_UP:
|
|
||||||
if(st > 0)
|
|
||||||
st--;
|
|
||||||
break;
|
|
||||||
case KEY_RESIZE:
|
|
||||||
ncresize();
|
|
||||||
drawBrowser(0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
drawHelp(p, st);
|
|
||||||
}
|
}
|
||||||
|
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) {
|
switch(pstate) {
|
||||||
case ST_CALC: n = calc_draw(); break;
|
case ST_CALC: n = calc_draw(); break;
|
||||||
case ST_BROWSE: n = browse_draw(); break;
|
case ST_BROWSE: n = browse_draw(); break;
|
||||||
|
case ST_HELP: n = help_draw(); break;
|
||||||
}
|
}
|
||||||
if(!n)
|
if(!n)
|
||||||
refresh();
|
refresh();
|
||||||
|
|
@ -66,6 +67,7 @@ int input_handle(int wait) {
|
||||||
switch(pstate) {
|
switch(pstate) {
|
||||||
case ST_CALC: return calc_key(ch);
|
case ST_CALC: return calc_key(ch);
|
||||||
case ST_BROWSE: return browse_key(ch);
|
case ST_BROWSE: return browse_key(ch);
|
||||||
|
case ST_HELP: return help_key(ch);
|
||||||
}
|
}
|
||||||
screen_draw();
|
screen_draw();
|
||||||
}
|
}
|
||||||
|
|
@ -153,7 +155,7 @@ int main(int argc, char **argv) {
|
||||||
if(pstate == ST_CALC)
|
if(pstate == ST_CALC)
|
||||||
calc_process();
|
calc_process();
|
||||||
else if(input_handle(0))
|
else if(input_handle(0))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
erase();
|
erase();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue