2009-04-13 19:25:46 +04:00
|
|
|
/* ncdu - NCurses Disk Usage
|
|
|
|
|
2016-08-24 21:49:20 +03:00
|
|
|
Copyright (c) 2007-2016 Yoran Heling
|
2007-07-20 15:15:46 +04:00
|
|
|
|
|
|
|
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:
|
2009-04-13 19:25:46 +04:00
|
|
|
|
2007-07-20 15:15:46 +04:00
|
|
|
The above copyright notice and this permission notice shall be included
|
|
|
|
in all copies or substantial portions of the Software.
|
2009-04-13 19:25:46 +04:00
|
|
|
|
2007-07-20 15:15:46 +04:00
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2009-04-26 13:08:40 +04:00
|
|
|
#include "global.h"
|
2007-07-20 15:15:46 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ncurses.h>
|
2007-07-20 15:15:46 +04:00
|
|
|
|
|
|
|
|
2013-01-13 15:53:24 +04:00
|
|
|
static int graph = 1, show_as = 0, info_show = 0, info_page = 0, info_start = 0, show_items = 0;
|
2012-09-06 15:16:11 +04:00
|
|
|
static char *message = NULL;
|
2009-04-13 19:25:46 +04:00
|
|
|
|
2007-07-20 15:15:46 +04:00
|
|
|
|
|
|
|
|
2011-10-31 18:09:12 +04:00
|
|
|
static void browse_draw_info(struct dir *dr) {
|
2010-02-27 17:15:25 +03:00
|
|
|
struct dir *t;
|
2010-02-28 12:13:12 +03:00
|
|
|
int i;
|
2010-02-27 17:15:25 +03:00
|
|
|
|
2009-04-18 18:02:46 +04:00
|
|
|
nccreate(11, 60, "Item info");
|
|
|
|
|
2010-02-27 17:15:25 +03:00
|
|
|
if(dr->hlnk) {
|
2017-07-08 17:29:31 +03:00
|
|
|
nctab(41, info_page == 0, 1, "Info");
|
|
|
|
nctab(50, info_page == 1, 2, "Links");
|
2010-02-27 17:15:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(info_page) {
|
|
|
|
case 0:
|
|
|
|
attron(A_BOLD);
|
|
|
|
ncaddstr(2, 3, "Name:");
|
|
|
|
ncaddstr(3, 3, "Path:");
|
|
|
|
ncaddstr(4, 3, "Type:");
|
|
|
|
ncaddstr(6, 3, " Disk usage:");
|
|
|
|
ncaddstr(7, 3, "Apparent size:");
|
|
|
|
attroff(A_BOLD);
|
|
|
|
|
|
|
|
ncaddstr(2, 9, cropstr(dr->name, 49));
|
|
|
|
ncaddstr(3, 9, cropstr(getpath(dr->parent), 49));
|
|
|
|
ncaddstr(4, 9, dr->flags & FF_DIR ? "Directory"
|
|
|
|
: dr->flags & FF_FILE ? "File" : "Other (link, device, socket, ..)");
|
2017-07-08 17:29:31 +03:00
|
|
|
|
|
|
|
ncmove(6, 18);
|
|
|
|
printsize(UIC_DEFAULT, dr->size);
|
|
|
|
addstrc(UIC_DEFAULT, " (");
|
2018-01-21 17:38:36 +03:00
|
|
|
addstrc(UIC_NUM, fullsize(dr->size));
|
2017-07-08 17:29:31 +03:00
|
|
|
addstrc(UIC_DEFAULT, " B)");
|
|
|
|
|
|
|
|
ncmove(7, 18);
|
|
|
|
printsize(UIC_DEFAULT, dr->asize);
|
|
|
|
addstrc(UIC_DEFAULT, " (");
|
2018-01-21 17:38:36 +03:00
|
|
|
addstrc(UIC_NUM, fullsize(dr->asize));
|
2017-07-08 17:29:31 +03:00
|
|
|
addstrc(UIC_DEFAULT, " B)");
|
2010-02-27 17:15:25 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
for(i=0,t=dr->hlnk; t!=dr; t=t->hlnk,i++) {
|
|
|
|
if(info_start > i)
|
|
|
|
continue;
|
|
|
|
if(i-info_start > 5)
|
|
|
|
break;
|
|
|
|
ncaddstr(2+i-info_start, 3, cropstr(getpath(t), 54));
|
|
|
|
}
|
|
|
|
if(t!=dr)
|
|
|
|
ncaddstr(8, 25, "-- more --");
|
|
|
|
break;
|
|
|
|
}
|
2009-04-18 18:02:46 +04:00
|
|
|
|
2017-07-08 17:29:31 +03:00
|
|
|
ncaddstr(9, 31, "Press ");
|
2018-01-21 17:38:36 +03:00
|
|
|
addchc(UIC_KEY, 'i');
|
2017-07-08 17:29:31 +03:00
|
|
|
addstrc(UIC_DEFAULT, " to hide this window");
|
2009-04-18 18:02:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-08 17:29:31 +03:00
|
|
|
static void browse_draw_flag(struct dir *n, int *x) {
|
|
|
|
addchc(n->flags & FF_BSEL ? UIC_FLAG_SEL : UIC_FLAG,
|
|
|
|
n == dirlist_parent ? ' ' :
|
|
|
|
n->flags & FF_EXL ? '<' :
|
2009-04-13 19:25:46 +04:00
|
|
|
n->flags & FF_ERR ? '!' :
|
|
|
|
n->flags & FF_SERR ? '.' :
|
|
|
|
n->flags & FF_OTHFS ? '>' :
|
2010-02-27 13:29:36 +03:00
|
|
|
n->flags & FF_HLNKC ? 'H' :
|
2009-04-13 19:25:46 +04:00
|
|
|
!(n->flags & FF_FILE
|
|
|
|
|| n->flags & FF_DIR) ? '@' :
|
|
|
|
n->flags & FF_DIR
|
|
|
|
&& n->sub == NULL ? 'e' :
|
2017-07-08 17:29:31 +03:00
|
|
|
' ');
|
|
|
|
*x += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void browse_draw_graph(struct dir *n, int *x) {
|
|
|
|
float pc = 0.0f;
|
|
|
|
int o, i;
|
|
|
|
enum ui_coltype c = n->flags & FF_BSEL ? UIC_SEL : UIC_DEFAULT;
|
|
|
|
|
|
|
|
if(!graph)
|
|
|
|
return;
|
|
|
|
|
|
|
|
*x += graph == 1 ? 13 : graph == 2 ? 9 : 20;
|
|
|
|
if(n == dirlist_parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
addchc(c, '[');
|
|
|
|
|
|
|
|
/* percentage (6 columns) */
|
|
|
|
if(graph == 2 || graph == 3) {
|
|
|
|
pc = (float)(show_as ? n->parent->asize : n->parent->size);
|
|
|
|
if(pc < 1)
|
2010-03-07 13:10:00 +03:00
|
|
|
pc = 1.0f;
|
2018-01-21 17:38:36 +03:00
|
|
|
uic_set(c == UIC_SEL ? UIC_NUM_SEL : UIC_NUM);
|
2017-07-08 17:29:31 +03:00
|
|
|
printw("%5.1f", ((float)(show_as ? n->asize : n->size) / pc) * 100.0f);
|
|
|
|
addchc(c, '%');
|
2009-04-13 19:25:46 +04:00
|
|
|
}
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2017-07-08 17:29:31 +03:00
|
|
|
if(graph == 3)
|
|
|
|
addch(' ');
|
2013-01-13 15:53:24 +04:00
|
|
|
|
2017-07-08 17:29:31 +03:00
|
|
|
/* graph (10 columns) */
|
|
|
|
if(graph == 1 || graph == 3) {
|
|
|
|
uic_set(c == UIC_SEL ? UIC_GRAPH_SEL : UIC_GRAPH);
|
|
|
|
o = (int)(10.0f*(float)(show_as ? n->asize : n->size) / (float)(show_as ? dirlist_maxa : dirlist_maxs));
|
|
|
|
for(i=0; i<10; i++)
|
|
|
|
addch(i < o ? '#' : ' ');
|
2013-01-13 15:53:24 +04:00
|
|
|
}
|
|
|
|
|
2017-07-08 17:29:31 +03:00
|
|
|
addchc(c, ']');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void browse_draw_items(struct dir *n, int *x) {
|
|
|
|
enum ui_coltype c = n->flags & FF_BSEL ? UIC_SEL : UIC_DEFAULT;
|
|
|
|
|
|
|
|
if(!show_items)
|
|
|
|
return;
|
|
|
|
*x += 7;
|
|
|
|
|
|
|
|
if(n->items > 99999) {
|
|
|
|
addstrc(c, "> ");
|
2018-01-21 17:38:36 +03:00
|
|
|
addstrc(c == UIC_SEL ? UIC_NUM_SEL : UIC_NUM, "100");
|
2017-07-08 17:29:31 +03:00
|
|
|
addchc(c, 'k');
|
|
|
|
} else if(n->items) {
|
2018-01-21 17:38:36 +03:00
|
|
|
uic_set(c == UIC_SEL ? UIC_NUM_SEL : UIC_NUM);
|
2017-07-08 17:29:31 +03:00
|
|
|
printw("%6s", fullsize(n->items));
|
2009-04-13 19:25:46 +04:00
|
|
|
}
|
2017-07-08 17:29:31 +03:00
|
|
|
}
|
2009-04-13 19:25:46 +04:00
|
|
|
|
2017-07-08 17:29:31 +03:00
|
|
|
|
|
|
|
static void browse_draw_item(struct dir *n, int row) {
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
enum ui_coltype c = n->flags & FF_BSEL ? UIC_SEL : UIC_DEFAULT;
|
|
|
|
uic_set(c);
|
|
|
|
mvhline(row, 0, ' ', wincols);
|
|
|
|
move(row, 0);
|
|
|
|
|
|
|
|
browse_draw_flag(n, &x);
|
|
|
|
move(row, x);
|
|
|
|
|
|
|
|
if(n != dirlist_parent)
|
|
|
|
printsize(c, show_as ? n->asize : n->size);
|
|
|
|
x += 10;
|
|
|
|
move(row, x);
|
|
|
|
|
|
|
|
browse_draw_graph(n, &x);
|
|
|
|
move(row, x);
|
|
|
|
|
|
|
|
browse_draw_items(n, &x);
|
|
|
|
move(row, x);
|
|
|
|
|
2018-01-21 17:38:36 +03:00
|
|
|
if(n->flags & FF_DIR)
|
|
|
|
c = c == UIC_SEL ? UIC_DIR_SEL : UIC_DIR;
|
|
|
|
addchc(c, n->flags & FF_DIR ? '/' : ' ');
|
2017-07-08 17:29:31 +03:00
|
|
|
addstrc(c, cropstr(n->name, wincols-x-1));
|
2009-04-13 19:25:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-26 11:49:51 +04:00
|
|
|
void browse_draw() {
|
2010-03-07 13:10:00 +03:00
|
|
|
struct dir *t;
|
2017-07-08 17:29:31 +03:00
|
|
|
char *tmp;
|
2012-08-26 20:08:56 +04:00
|
|
|
int selected = 0, i;
|
2007-07-20 15:15:46 +04:00
|
|
|
|
2007-07-24 11:58:22 +04:00
|
|
|
erase();
|
2010-03-07 13:10:00 +03:00
|
|
|
t = dirlist_get(0);
|
2007-07-20 15:15:46 +04:00
|
|
|
|
2010-03-07 13:10:00 +03:00
|
|
|
/* top line - basic info */
|
2017-07-08 17:29:31 +03:00
|
|
|
uic_set(UIC_HD);
|
2007-07-24 11:58:22 +04:00
|
|
|
mvhline(0, 0, ' ', wincols);
|
2017-07-08 17:29:31 +03:00
|
|
|
mvprintw(0,0,"%s %s ~ Use the arrow keys to navigate, press ", PACKAGE_NAME, PACKAGE_VERSION);
|
2018-01-21 17:38:36 +03:00
|
|
|
addchc(UIC_KEY_HD, '?');
|
2017-07-08 17:29:31 +03:00
|
|
|
addstrc(UIC_HD, " for help");
|
2012-09-06 14:32:41 +04:00
|
|
|
if(dir_import_active)
|
|
|
|
mvaddstr(0, wincols-10, "[imported]");
|
|
|
|
else if(read_only)
|
2011-10-31 16:10:36 +04:00
|
|
|
mvaddstr(0, wincols-11, "[read-only]");
|
2009-04-13 19:25:46 +04:00
|
|
|
|
2010-03-07 13:10:00 +03:00
|
|
|
/* second line - the path */
|
2017-07-08 17:29:31 +03:00
|
|
|
mvhlinec(UIC_DEFAULT, 1, 0, '-', wincols);
|
2014-01-22 16:30:51 +04:00
|
|
|
if(dirlist_par) {
|
2017-07-08 17:29:31 +03:00
|
|
|
mvaddchc(UIC_DEFAULT, 1, 3, ' ');
|
2014-01-22 16:30:51 +04:00
|
|
|
tmp = getpath(dirlist_par);
|
2017-07-08 17:29:31 +03:00
|
|
|
mvaddstrc(UIC_DIR, 1, 4, cropstr(tmp, wincols-8));
|
|
|
|
mvaddchc(UIC_DEFAULT, 1, 4+((int)strlen(tmp) > wincols-8 ? wincols-8 : (int)strlen(tmp)), ' ');
|
2009-04-18 17:34:47 +04:00
|
|
|
}
|
|
|
|
|
2010-03-07 13:10:00 +03:00
|
|
|
/* bottom line - stats */
|
2017-07-08 17:29:31 +03:00
|
|
|
uic_set(UIC_HD);
|
|
|
|
mvhline(winrows-1, 0, ' ', wincols);
|
2010-03-07 13:10:00 +03:00
|
|
|
if(t) {
|
2017-07-08 17:29:31 +03:00
|
|
|
mvaddstr(winrows-1, 0, " Total disk usage: ");
|
|
|
|
printsize(UIC_HD, t->parent->size);
|
|
|
|
addstrc(UIC_HD, " Apparent size: ");
|
2018-01-21 17:38:36 +03:00
|
|
|
uic_set(UIC_NUM_HD);
|
2017-07-08 17:29:31 +03:00
|
|
|
printsize(UIC_HD, t->parent->asize);
|
|
|
|
addstrc(UIC_HD, " Items: ");
|
2018-01-21 17:38:36 +03:00
|
|
|
uic_set(UIC_NUM_HD);
|
2017-07-08 17:29:31 +03:00
|
|
|
printw("%d", t->parent->items);
|
2010-03-07 13:10:00 +03:00
|
|
|
} else
|
|
|
|
mvaddstr(winrows-1, 0, " No items to display.");
|
2017-07-08 17:29:31 +03:00
|
|
|
uic_set(UIC_DEFAULT);
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2010-03-07 13:10:00 +03:00
|
|
|
/* nothing to display? stop here. */
|
|
|
|
if(!t)
|
|
|
|
return;
|
2007-08-12 13:52:24 +04:00
|
|
|
|
2010-03-07 13:10:00 +03:00
|
|
|
/* get start position */
|
2010-04-28 15:32:30 +04:00
|
|
|
t = dirlist_top(0);
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
/* print the list to the screen */
|
2010-04-28 15:32:30 +04:00
|
|
|
for(i=0; t && i<winrows-3; t=dirlist_next(t),i++) {
|
2010-07-18 20:58:22 +04:00
|
|
|
browse_draw_item(t, 2+i);
|
2010-03-07 13:10:00 +03:00
|
|
|
/* save the selected row number for later */
|
|
|
|
if(t->flags & FF_BSEL)
|
|
|
|
selected = i;
|
2007-07-20 15:15:46 +04:00
|
|
|
}
|
2007-08-12 13:52:24 +04:00
|
|
|
|
2012-09-06 15:16:11 +04:00
|
|
|
/* draw message window */
|
|
|
|
if(message) {
|
|
|
|
nccreate(6, 60, "Message");
|
|
|
|
ncaddstr(2, 2, message);
|
|
|
|
ncaddstr(4, 34, "Press any key to continue");
|
|
|
|
}
|
|
|
|
|
2009-04-18 18:02:46 +04:00
|
|
|
/* draw information window */
|
2010-03-07 13:10:00 +03:00
|
|
|
t = dirlist_get(0);
|
2012-09-06 15:16:11 +04:00
|
|
|
if(!message && info_show && t != dirlist_parent)
|
2010-03-07 13:10:00 +03:00
|
|
|
browse_draw_info(t);
|
2009-04-18 18:02:46 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
/* move cursor to selected row for accessibility */
|
2008-08-02 17:31:21 +04:00
|
|
|
move(selected+2, 0);
|
2009-04-13 19:25:46 +04:00
|
|
|
}
|
|
|
|
|
2008-08-02 17:31:21 +04:00
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
int browse_key(int ch) {
|
2010-03-07 13:10:00 +03:00
|
|
|
struct dir *t, *sel;
|
|
|
|
int i, catch = 0;
|
2010-02-27 17:15:25 +03:00
|
|
|
|
2012-09-06 15:16:11 +04:00
|
|
|
/* message window overwrites all keys */
|
|
|
|
if(message) {
|
|
|
|
message = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-07 13:10:00 +03:00
|
|
|
sel = dirlist_get(0);
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2010-02-27 17:15:25 +03:00
|
|
|
/* info window overwrites a few keys */
|
2010-03-07 13:10:00 +03:00
|
|
|
if(info_show && sel)
|
2010-02-27 17:15:25 +03:00
|
|
|
switch(ch) {
|
|
|
|
case '1':
|
|
|
|
info_page = 0;
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
if(sel->hlnk)
|
|
|
|
info_page = 1;
|
|
|
|
break;
|
|
|
|
case KEY_RIGHT:
|
|
|
|
case 'l':
|
|
|
|
if(sel->hlnk) {
|
|
|
|
info_page = 1;
|
|
|
|
catch++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KEY_LEFT:
|
|
|
|
case 'h':
|
|
|
|
if(sel->hlnk) {
|
|
|
|
info_page = 0;
|
|
|
|
catch++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KEY_UP:
|
|
|
|
case 'k':
|
|
|
|
if(sel->hlnk && info_page == 1) {
|
|
|
|
if(info_start > 0)
|
|
|
|
info_start--;
|
|
|
|
catch++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KEY_DOWN:
|
|
|
|
case 'j':
|
|
|
|
case ' ':
|
|
|
|
if(sel->hlnk && info_page == 1) {
|
2010-03-07 13:10:00 +03:00
|
|
|
for(i=0,t=sel->hlnk; t!=sel; t=t->hlnk)
|
2010-02-27 17:15:25 +03:00
|
|
|
i++;
|
|
|
|
if(i > info_start+6)
|
|
|
|
info_start++;
|
|
|
|
catch++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!catch)
|
|
|
|
switch(ch) {
|
2009-04-13 19:25:46 +04:00
|
|
|
/* selecting items */
|
|
|
|
case KEY_UP:
|
2009-10-18 14:52:00 +04:00
|
|
|
case 'k':
|
2010-03-07 13:10:00 +03:00
|
|
|
dirlist_select(dirlist_get(-1));
|
2010-04-28 15:32:30 +04:00
|
|
|
dirlist_top(-1);
|
2010-02-27 17:15:25 +03:00
|
|
|
info_start = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
|
|
|
case KEY_DOWN:
|
2009-10-18 14:52:00 +04:00
|
|
|
case 'j':
|
2010-03-07 13:10:00 +03:00
|
|
|
dirlist_select(dirlist_get(1));
|
2010-04-28 15:32:30 +04:00
|
|
|
dirlist_top(1);
|
2010-02-27 17:15:25 +03:00
|
|
|
info_start = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
|
|
|
case KEY_HOME:
|
2010-03-07 13:10:00 +03:00
|
|
|
dirlist_select(dirlist_next(NULL));
|
2010-04-28 15:32:30 +04:00
|
|
|
dirlist_top(2);
|
2010-02-27 17:15:25 +03:00
|
|
|
info_start = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
|
|
|
case KEY_LL:
|
|
|
|
case KEY_END:
|
2010-03-07 13:10:00 +03:00
|
|
|
dirlist_select(dirlist_get(1<<30));
|
2010-04-28 15:32:30 +04:00
|
|
|
dirlist_top(1);
|
2010-02-27 17:15:25 +03:00
|
|
|
info_start = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
|
|
|
case KEY_PPAGE:
|
2010-03-07 13:10:00 +03:00
|
|
|
dirlist_select(dirlist_get(-1*(winrows-3)));
|
2010-04-28 15:32:30 +04:00
|
|
|
dirlist_top(-1);
|
2010-02-27 17:15:25 +03:00
|
|
|
info_start = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
|
|
|
case KEY_NPAGE:
|
2010-03-07 13:10:00 +03:00
|
|
|
dirlist_select(dirlist_get(winrows-3));
|
2010-04-28 15:32:30 +04:00
|
|
|
dirlist_top(1);
|
2010-02-27 17:15:25 +03:00
|
|
|
info_start = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2009-04-26 11:55:23 +04:00
|
|
|
/* sorting items */
|
2009-04-13 19:25:46 +04:00
|
|
|
case 'n':
|
2010-04-28 17:39:45 +04:00
|
|
|
dirlist_set_sort(DL_COL_NAME, dirlist_sort_col == DL_COL_NAME ? !dirlist_sort_desc : 0, DL_NOCHANGE);
|
2010-03-07 13:10:00 +03:00
|
|
|
info_show = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
|
|
|
case 's':
|
2010-03-07 13:10:00 +03:00
|
|
|
i = show_as ? DL_COL_ASIZE : DL_COL_SIZE;
|
2010-04-28 17:39:45 +04:00
|
|
|
dirlist_set_sort(i, dirlist_sort_col == i ? !dirlist_sort_desc : 1, DL_NOCHANGE);
|
2010-03-07 13:10:00 +03:00
|
|
|
info_show = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
2013-01-13 16:13:31 +04:00
|
|
|
case 'C':
|
|
|
|
dirlist_set_sort(DL_COL_ITEMS, dirlist_sort_col == DL_COL_ITEMS ? !dirlist_sort_desc : 1, DL_NOCHANGE);
|
|
|
|
info_show = 0;
|
|
|
|
break;
|
2009-10-18 14:52:00 +04:00
|
|
|
case 'e':
|
2010-03-07 13:10:00 +03:00
|
|
|
dirlist_set_hidden(!dirlist_hidden);
|
|
|
|
info_show = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
|
|
|
case 't':
|
2013-06-05 18:52:53 +04:00
|
|
|
dirlist_set_sort(DL_NOCHANGE, DL_NOCHANGE, !dirlist_sort_df);
|
2010-03-07 13:10:00 +03:00
|
|
|
info_show = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
|
|
|
case 'a':
|
2010-03-07 13:10:00 +03:00
|
|
|
show_as = !show_as;
|
|
|
|
if(dirlist_sort_col == DL_COL_ASIZE || dirlist_sort_col == DL_COL_SIZE)
|
|
|
|
dirlist_set_sort(show_as ? DL_COL_ASIZE : DL_COL_SIZE, DL_NOCHANGE, DL_NOCHANGE);
|
|
|
|
info_show = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
|
|
|
|
2009-04-26 11:55:23 +04:00
|
|
|
/* browsing */
|
2009-04-13 19:25:46 +04:00
|
|
|
case 10:
|
|
|
|
case KEY_RIGHT:
|
2009-10-18 14:52:00 +04:00
|
|
|
case 'l':
|
2014-01-22 16:30:51 +04:00
|
|
|
if(sel != NULL && sel->flags & FF_DIR) {
|
|
|
|
dirlist_open(sel == dirlist_parent ? dirlist_par->parent : sel);
|
2010-04-28 15:32:30 +04:00
|
|
|
dirlist_top(-3);
|
|
|
|
}
|
2010-03-07 13:10:00 +03:00
|
|
|
info_show = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
|
|
|
case KEY_LEFT:
|
2015-08-02 23:59:32 +03:00
|
|
|
case KEY_BACKSPACE:
|
2009-10-18 14:52:00 +04:00
|
|
|
case 'h':
|
|
|
|
case '<':
|
2014-01-22 16:30:51 +04:00
|
|
|
if(dirlist_par && dirlist_par->parent != NULL) {
|
|
|
|
dirlist_open(dirlist_par->parent);
|
2010-04-28 15:32:30 +04:00
|
|
|
dirlist_top(-3);
|
|
|
|
}
|
2010-03-07 13:10:00 +03:00
|
|
|
info_show = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
|
|
|
|
2009-04-26 13:08:40 +04:00
|
|
|
/* and other stuff */
|
2009-04-13 19:25:46 +04:00
|
|
|
case 'r':
|
2012-09-06 15:16:11 +04:00
|
|
|
if(dir_import_active) {
|
|
|
|
message = "Directory imported from file, won't refresh.";
|
|
|
|
break;
|
|
|
|
}
|
2014-01-22 16:30:51 +04:00
|
|
|
if(dirlist_par) {
|
2012-08-27 16:17:40 +04:00
|
|
|
dir_ui = 2;
|
2014-01-22 16:30:51 +04:00
|
|
|
dir_mem_init(dirlist_par);
|
|
|
|
dir_scan_init(getpath(dirlist_par));
|
2012-08-26 16:41:25 +04:00
|
|
|
}
|
2010-03-07 13:10:00 +03:00
|
|
|
info_show = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
|
|
|
case 'q':
|
2010-03-07 13:10:00 +03:00
|
|
|
if(info_show)
|
|
|
|
info_show = 0;
|
2009-04-19 12:06:33 +04:00
|
|
|
else
|
2015-09-20 02:11:12 +03:00
|
|
|
if (confirm_quit)
|
|
|
|
quit_init();
|
|
|
|
else return 1;
|
2009-04-19 12:06:33 +04:00
|
|
|
break;
|
2009-04-13 19:25:46 +04:00
|
|
|
case 'g':
|
2009-04-18 18:02:46 +04:00
|
|
|
if(++graph > 3)
|
|
|
|
graph = 0;
|
2010-03-07 13:10:00 +03:00
|
|
|
info_show = 0;
|
2009-04-18 18:02:46 +04:00
|
|
|
break;
|
2013-01-13 15:53:24 +04:00
|
|
|
case 'c':
|
|
|
|
show_items = !show_items;
|
|
|
|
break;
|
2009-04-18 18:02:46 +04:00
|
|
|
case 'i':
|
2010-03-07 13:10:00 +03:00
|
|
|
info_show = !info_show;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
|
|
|
case '?':
|
2009-04-19 12:03:42 +04:00
|
|
|
help_init();
|
2010-03-07 13:10:00 +03:00
|
|
|
info_show = 0;
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
|
|
|
case 'd':
|
2017-01-06 20:35:30 +03:00
|
|
|
if(read_only >= 1 || dir_import_active) {
|
|
|
|
message = read_only >= 1
|
2012-09-06 15:16:11 +04:00
|
|
|
? "File deletion disabled in read-only mode."
|
|
|
|
: "File deletion not available for imported directories.";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(sel == NULL || sel == dirlist_parent)
|
2009-04-19 13:35:24 +04:00
|
|
|
break;
|
2010-03-07 13:10:00 +03:00
|
|
|
info_show = 0;
|
|
|
|
if((t = dirlist_get(1)) == sel)
|
2010-04-27 19:58:17 +04:00
|
|
|
if((t = dirlist_get(-1)) == sel || t == dirlist_parent)
|
2014-01-22 16:30:51 +04:00
|
|
|
t = NULL;
|
2010-03-07 13:10:00 +03:00
|
|
|
delete_init(sel, t);
|
2009-04-13 19:25:46 +04:00
|
|
|
break;
|
2014-12-14 02:24:35 +03:00
|
|
|
case 'b':
|
2017-01-06 20:35:30 +03:00
|
|
|
if(read_only >= 2 || dir_import_active) {
|
|
|
|
message = read_only >= 2
|
|
|
|
? "Shell feature disabled in read-only mode."
|
|
|
|
: "Shell feature not available for imported directories.";
|
2015-04-05 11:03:32 +03:00
|
|
|
break;
|
|
|
|
}
|
2014-12-14 02:24:35 +03:00
|
|
|
shell_init();
|
|
|
|
break;
|
2010-02-27 17:15:25 +03:00
|
|
|
}
|
2009-04-18 17:45:26 +04:00
|
|
|
|
2010-03-07 13:10:00 +03:00
|
|
|
/* make sure the info_* options are correct */
|
|
|
|
sel = dirlist_get(0);
|
|
|
|
if(!info_show || sel == dirlist_parent)
|
|
|
|
info_show = info_page = info_start = 0;
|
|
|
|
else if(sel && !sel->hlnk)
|
|
|
|
info_page = info_start = 0;
|
|
|
|
|
2009-04-13 19:25:46 +04:00
|
|
|
return 0;
|
2007-07-20 15:15:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-22 16:30:51 +04:00
|
|
|
void browse_init(struct dir *par) {
|
2009-04-18 17:23:33 +04:00
|
|
|
pstate = ST_BROWSE;
|
2012-09-06 15:16:11 +04:00
|
|
|
message = NULL;
|
2014-01-22 16:30:51 +04:00
|
|
|
dirlist_open(par);
|
2009-04-18 17:23:33 +04:00
|
|
|
}
|
|
|
|
|