mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
Rewrote util.h to the new style
This commit is contained in:
parent
b10a0f536f
commit
fa90c77c96
6 changed files with 145 additions and 81 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
bin_PROGRAMS = ncdu
|
bin_PROGRAMS = ncdu
|
||||||
|
|
||||||
ncdu_SOURCES = browser.c calc.c main.c util.c exclude.c help.c delete.c
|
ncdu_SOURCES = calc.c exclude.c main.c util.c
|
||||||
|
|
||||||
noinst_HEADERS = calc.h exclude.h ncdu.h
|
noinst_HEADERS = calc.h exclude.h util.h ncdu.h
|
||||||
|
|
|
||||||
11
src/calc.c
11
src/calc.c
|
|
@ -26,6 +26,7 @@
|
||||||
#include "ncdu.h"
|
#include "ncdu.h"
|
||||||
#include "calc.h"
|
#include "calc.h"
|
||||||
#include "exclude.h"
|
#include "exclude.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct state_calc stcalc;
|
struct state_calc stcalc;
|
||||||
|
|
||||||
|
|
@ -278,8 +279,8 @@ void calc_draw_progress() {
|
||||||
nccreate(10, 60, dat == NULL ? "Calculating..." : "Recalculating...");
|
nccreate(10, 60, dat == NULL ? "Calculating..." : "Recalculating...");
|
||||||
|
|
||||||
ncprint(2, 2, "Total items: %-8d size: %s",
|
ncprint(2, 2, "Total items: %-8d size: %s",
|
||||||
stcalc.parent->items, cropsize(stcalc.parent->size));
|
stcalc.parent->items, formatsize(stcalc.parent->size, sflags & SF_SI));
|
||||||
ncprint(3, 2, "Current dir: %s", cropdir(stcalc.cur, 43));
|
ncprint(3, 2, "Current dir: %s", cropstr(stcalc.cur, 43));
|
||||||
ncaddstr(8, 43, "Press q to quit");
|
ncaddstr(8, 43, "Press q to quit");
|
||||||
|
|
||||||
/* show warning if we couldn't open a dir */
|
/* show warning if we couldn't open a dir */
|
||||||
|
|
@ -287,7 +288,7 @@ void calc_draw_progress() {
|
||||||
attron(A_BOLD);
|
attron(A_BOLD);
|
||||||
ncaddstr(5, 2, "Warning:");
|
ncaddstr(5, 2, "Warning:");
|
||||||
attroff(A_BOLD);
|
attroff(A_BOLD);
|
||||||
ncprint(5, 11, "could not open %-32s", cropdir(stcalc.lasterr, 32));
|
ncprint(5, 11, "could not open %-32s", cropstr(stcalc.lasterr, 32));
|
||||||
ncaddstr(6, 3, "some directory sizes may not be correct");
|
ncaddstr(6, 3, "some directory sizes may not be correct");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -315,8 +316,8 @@ void calc_draw_error(char *cur, char *msg) {
|
||||||
ncaddstr(2, 2, "Error:");
|
ncaddstr(2, 2, "Error:");
|
||||||
attroff(A_BOLD);
|
attroff(A_BOLD);
|
||||||
|
|
||||||
ncprint(2, 9, "could not open %s", cropdir(cur, 34));
|
ncprint(2, 9, "could not open %s", cropstr(cur, 34));
|
||||||
ncprint(3, 4, "%s", cropdir(msg, 52));
|
ncprint(3, 4, "%s", cropstr(msg, 52));
|
||||||
ncaddstr(5, 30, "press any key to continue...");
|
ncaddstr(5, 30, "press any key to continue...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
10
src/main.c
10
src/main.c
|
|
@ -25,13 +25,11 @@
|
||||||
|
|
||||||
#include "ncdu.h"
|
#include "ncdu.h"
|
||||||
#include "exclude.h"
|
#include "exclude.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
/* check ncdu.h what these are for */
|
/* check ncdu.h what these are for */
|
||||||
struct dir *dat;
|
struct dir *dat;
|
||||||
int winrows, wincols;
|
|
||||||
char sdir[PATH_MAX];
|
|
||||||
int sflags, bflags, sdelay, bgraph;
|
int sflags, bflags, sdelay, bgraph;
|
||||||
int subwinc, subwinr;
|
|
||||||
int pstate;
|
int pstate;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -52,7 +50,8 @@ int input_handle(int wait) {
|
||||||
screen_draw();
|
screen_draw();
|
||||||
while((ch = getch()) != ERR) {
|
while((ch = getch()) != ERR) {
|
||||||
if(ch == KEY_RESIZE) {
|
if(ch == KEY_RESIZE) {
|
||||||
ncresize();
|
if(ncresize((sflags & SF_IGNS ? 0 : 17), (sflags * SF_IGNS ? 0 : 60)))
|
||||||
|
sflags |= SF_IGNS;
|
||||||
screen_draw();
|
screen_draw();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -141,7 +140,8 @@ int main(int argc, char **argv) {
|
||||||
noecho();
|
noecho();
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
ncresize();
|
if(ncresize((sflags & SF_IGNS ? 0 : 17), (sflags * SF_IGNS ? 0 : 60)))
|
||||||
|
sflags |= SF_IGNS;
|
||||||
|
|
||||||
while(pstate != ST_QUIT) {
|
while(pstate != ST_QUIT) {
|
||||||
if(pstate == ST_CALC)
|
if(pstate == ST_CALC)
|
||||||
|
|
|
||||||
23
src/ncdu.h
23
src/ncdu.h
|
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _ncdu_h
|
||||||
|
#define _ncdu_h
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
|
@ -82,10 +84,6 @@
|
||||||
# define S_ISLNK(x) (x & S_IFLNK)
|
# define S_ISLNK(x) (x & S_IFLNK)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* check nccreate in util.c for more info on these defines */
|
|
||||||
#define ncaddstr(r, c, s) mvaddstr(subwinr+(r), subwinc+(c), s)
|
|
||||||
#define ncaddch(r, c, s) mvaddch(subwinr+(r), subwinc+(c), s)
|
|
||||||
#define ncmove(r, c) move(subwinr+(r), subwinc+(c))
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -146,13 +144,8 @@ struct dir {
|
||||||
*/
|
*/
|
||||||
/* main directory data */
|
/* main directory data */
|
||||||
extern struct dir *dat;
|
extern struct dir *dat;
|
||||||
/* updated when window is resized */
|
|
||||||
extern int winrows, wincols;
|
|
||||||
/* global settings */
|
/* global settings */
|
||||||
extern char sdir[PATH_MAX];
|
|
||||||
extern int sflags, bflags, sdelay, bgraph;
|
extern int sflags, bflags, sdelay, bgraph;
|
||||||
/* used for creating windows */
|
|
||||||
extern int subwinr, subwinc;
|
|
||||||
/* program state */
|
/* program state */
|
||||||
extern int pstate;
|
extern int pstate;
|
||||||
|
|
||||||
|
|
@ -162,15 +155,6 @@ extern int pstate;
|
||||||
*/
|
*/
|
||||||
/* main.c */
|
/* main.c */
|
||||||
int input_handle(int);
|
int input_handle(int);
|
||||||
/* util.c */
|
|
||||||
char *cropdir(const char *, int);
|
|
||||||
char *cropsize(const off_t);
|
|
||||||
char *fullsize(const off_t);
|
|
||||||
void ncresize(void);
|
|
||||||
void nccreate(int, int, char *);
|
|
||||||
void ncprint(int, int, char *, ...);
|
|
||||||
struct dir *freedir(struct dir *);
|
|
||||||
char *getpath(struct dir *, char *);
|
|
||||||
/* browser.c */
|
/* browser.c */
|
||||||
void drawBrowser(int);
|
void drawBrowser(int);
|
||||||
void showBrowser(void);
|
void showBrowser(void);
|
||||||
|
|
@ -178,3 +162,6 @@ void showBrowser(void);
|
||||||
void showHelp(void);
|
void showHelp(void);
|
||||||
/* delete.c */
|
/* delete.c */
|
||||||
struct dir *showDelete(struct dir *);
|
struct dir *showDelete(struct dir *);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
||||||
98
src/util.c
98
src/util.c
|
|
@ -23,36 +23,44 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ncdu.h"
|
#include "util.h"
|
||||||
|
|
||||||
char cropsizedat[8];
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ncurses.h>
|
||||||
|
|
||||||
|
int winrows, wincols;
|
||||||
|
int subwinr, subwinc;
|
||||||
|
|
||||||
|
char cropstrdat[4096];
|
||||||
|
char formatsizedat[8];
|
||||||
char fullsizedat[20]; /* max: 999.999.999.999.999 */
|
char fullsizedat[20]; /* max: 999.999.999.999.999 */
|
||||||
char cropdirdat[4096];
|
|
||||||
|
|
||||||
char *cropdir(const char *from, int s) {
|
|
||||||
|
char *cropstr(const char *from, int s) {
|
||||||
int i, j, o = strlen(from);
|
int i, j, o = strlen(from);
|
||||||
if(o < s) {
|
if(o < s) {
|
||||||
strcpy(cropdirdat, from);
|
strcpy(cropstrdat, from);
|
||||||
return(cropdirdat);
|
return cropstrdat;
|
||||||
}
|
}
|
||||||
j=s/2-3;
|
j=s/2-3;
|
||||||
for(i=0; i<j; i++)
|
for(i=0; i<j; i++)
|
||||||
cropdirdat[i] = from[i];
|
cropstrdat[i] = from[i];
|
||||||
cropdirdat[i] = '.';
|
cropstrdat[i] = '.';
|
||||||
cropdirdat[++i] = '.';
|
cropstrdat[++i] = '.';
|
||||||
cropdirdat[++i] = '.';
|
cropstrdat[++i] = '.';
|
||||||
j=o-s;
|
j=o-s;
|
||||||
while(++i<s)
|
while(++i<s)
|
||||||
cropdirdat[i] = from[j+i];
|
cropstrdat[i] = from[j+i];
|
||||||
cropdirdat[s] = '\0';
|
cropstrdat[s] = '\0';
|
||||||
return(cropdirdat);
|
return cropstrdat;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return value is always xxx.xXB = 8 bytes (including \0) */
|
|
||||||
char *cropsize(const off_t from) {
|
char *formatsize(const off_t from, int si) {
|
||||||
float r = from;
|
float r = from;
|
||||||
char c = ' ';
|
char c = ' ';
|
||||||
if(sflags & SF_SI) {
|
if(si) {
|
||||||
if(r < 1000.0f) { }
|
if(r < 1000.0f) { }
|
||||||
else if(r < 1000e3f) { c = 'k'; r/=1000.0f; }
|
else if(r < 1000e3f) { c = 'k'; r/=1000.0f; }
|
||||||
else if(r < 1000e6f) { c = 'M'; r/=1000e3f; }
|
else if(r < 1000e6f) { c = 'M'; r/=1000e3f; }
|
||||||
|
|
@ -65,25 +73,24 @@ char *cropsize(const off_t from) {
|
||||||
else if(r < 1023e9f) { c = 'G'; r/=1073741824.0f; }
|
else if(r < 1023e9f) { c = 'G'; r/=1073741824.0f; }
|
||||||
else { c = 'T'; r/=1099511627776.0f; }
|
else { c = 'T'; r/=1099511627776.0f; }
|
||||||
}
|
}
|
||||||
sprintf(cropsizedat, "%5.1f%cB", r, c);
|
sprintf(formatsizedat, "%5.1f%cB", r, c);
|
||||||
return(cropsizedat);
|
return formatsizedat;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns integer as a string with thousand seperators
|
|
||||||
BUG: Uses a dot as seperator, ignores current locale */
|
|
||||||
char *fullsize(const off_t from) {
|
char *fullsize(const off_t from) {
|
||||||
char tmp[20];
|
char tmp[20];
|
||||||
off_t n = from;
|
off_t n = from;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
/* the K&R method - more portable than sprintf with %lld */
|
/* the K&R method - more portable than sprintf with %lld */
|
||||||
i = 0;
|
i = 0;
|
||||||
do {
|
do {
|
||||||
tmp[i++] = n % 10 + '0';
|
tmp[i++] = n % 10 + '0';
|
||||||
} while((n /= 10) > 0);
|
} while((n /= 10) > 0);
|
||||||
tmp[i] = '\0';
|
tmp[i] = '\0';
|
||||||
|
|
||||||
/* reverse and add thousand seperators */
|
/* reverse and add thousand seperators */
|
||||||
j = 0;
|
j = 0;
|
||||||
while(i--) {
|
while(i--) {
|
||||||
fullsizedat[j++] = tmp[i];
|
fullsizedat[j++] = tmp[i];
|
||||||
|
|
@ -92,19 +99,19 @@ char *fullsize(const off_t from) {
|
||||||
}
|
}
|
||||||
fullsizedat[j] = '\0';
|
fullsizedat[j] = '\0';
|
||||||
|
|
||||||
return(fullsizedat);
|
return fullsizedat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ncresize(void) {
|
int ncresize(int minrows, int mincols) {
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
getmaxyx(stdscr, winrows, wincols);
|
getmaxyx(stdscr, winrows, wincols);
|
||||||
while(!(sflags & SF_IGNS) && (winrows < 17 || wincols < 60)) {
|
while((minrows && winrows < minrows) || (mincols && wincols < mincols)) {
|
||||||
erase();
|
erase();
|
||||||
mvaddstr(0, 0, "Warning: terminal too small,");
|
mvaddstr(0, 0, "Warning: terminal too small,");
|
||||||
mvaddstr(1, 1, "please either resize your terminal,");
|
mvaddstr(1, 1, "please either resize your terminal,");
|
||||||
mvaddstr(2, 1, "press i to ignore, or press q to quit.");
|
mvaddstr(2, 1, "press i to ignore, or press q to quit.");
|
||||||
touchwin(stdscr);
|
|
||||||
refresh();
|
refresh();
|
||||||
nodelay(stdscr, 0);
|
nodelay(stdscr, 0);
|
||||||
ch = getch();
|
ch = getch();
|
||||||
|
|
@ -116,36 +123,24 @@ void ncresize(void) {
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
if(ch == 'i')
|
if(ch == 'i')
|
||||||
sflags |= SF_IGNS;
|
return 1;
|
||||||
}
|
}
|
||||||
erase();
|
erase();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Instead of using several ncurses windows, we only draw to stdscr.
|
|
||||||
* the functions nccreate, ncprint and the macros ncaddstr and ncaddch
|
|
||||||
* mimic the behaviour of ncurses windows.
|
|
||||||
* This works better than using ncurses windows when all windows are
|
|
||||||
* created in the correct order: it paints directly on stdscr, so
|
|
||||||
* wrefresh, wnoutrefresh and other window-specific functions are not
|
|
||||||
* necessary.
|
|
||||||
* Also, this method doesn't require any window objects, as you can
|
|
||||||
* only create one window at a time.
|
|
||||||
*
|
|
||||||
* This function creates a new window in the center of the screen
|
|
||||||
* with a border and a title.
|
|
||||||
*/
|
|
||||||
void nccreate(int height, int width, char *title) {
|
void nccreate(int height, int width, char *title) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
subwinr = winrows/2-height/2;
|
subwinr = winrows/2-height/2;
|
||||||
subwinc = wincols/2-width/2;
|
subwinc = wincols/2-width/2;
|
||||||
|
|
||||||
/* clear window */
|
/* clear window */
|
||||||
for(i=0; i<height; i++)
|
for(i=0; i<height; i++)
|
||||||
mvhline(subwinr+i, subwinc, ' ', width);
|
mvhline(subwinr+i, subwinc, ' ', width);
|
||||||
|
|
||||||
/* box() only works around curses windows, so create our own */
|
/* box() only works around curses windows, so create our own */
|
||||||
move(subwinr, subwinc);
|
move(subwinr, subwinc);
|
||||||
addch(ACS_ULCORNER);
|
addch(ACS_ULCORNER);
|
||||||
for(i=0; i<width-2; i++)
|
for(i=0; i<width-2; i++)
|
||||||
|
|
@ -161,7 +156,7 @@ void nccreate(int height, int width, char *title) {
|
||||||
mvvline(subwinr+1, subwinc, ACS_VLINE, height-2);
|
mvvline(subwinr+1, subwinc, ACS_VLINE, height-2);
|
||||||
mvvline(subwinr+1, subwinc+width-1, ACS_VLINE, height-2);
|
mvvline(subwinr+1, subwinc+width-1, ACS_VLINE, height-2);
|
||||||
|
|
||||||
/* title */
|
/* title */
|
||||||
attron(A_BOLD);
|
attron(A_BOLD);
|
||||||
mvaddstr(subwinr, subwinc+4, title);
|
mvaddstr(subwinr, subwinc+4, title);
|
||||||
attroff(A_BOLD);
|
attroff(A_BOLD);
|
||||||
|
|
@ -177,7 +172,6 @@ void ncprint(int r, int c, char *fmt, ...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void freedir_rec(struct dir *dr) {
|
void freedir_rec(struct dir *dr) {
|
||||||
struct dir *tmp, *tmp2;
|
struct dir *tmp, *tmp2;
|
||||||
tmp2 = dr;
|
tmp2 = dr;
|
||||||
|
|
@ -189,11 +183,11 @@ void freedir_rec(struct dir *dr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* remove a file/directory from the in-memory map */
|
|
||||||
struct dir *freedir(struct dir *dr) {
|
struct dir *freedir(struct dir *dr) {
|
||||||
struct dir *tmp, *cur;
|
struct dir *tmp, *cur;
|
||||||
|
|
||||||
/* update sizes of parent directories */
|
/* update sizes of parent directories */
|
||||||
tmp = dr;
|
tmp = dr;
|
||||||
while((tmp = tmp->parent) != NULL) {
|
while((tmp = tmp->parent) != NULL) {
|
||||||
tmp->size -= dr->size;
|
tmp->size -= dr->size;
|
||||||
|
|
@ -201,25 +195,25 @@ struct dir *freedir(struct dir *dr) {
|
||||||
tmp->items -= dr->items+1;
|
tmp->items -= dr->items+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free dr->sub recursive */
|
/* free dr->sub recursive */
|
||||||
if(dr->sub) freedir_rec(dr->sub);
|
if(dr->sub) freedir_rec(dr->sub);
|
||||||
|
|
||||||
/* update references */
|
/* update references */
|
||||||
cur = NULL;
|
cur = NULL;
|
||||||
if(dr->parent) {
|
if(dr->parent) {
|
||||||
/* item is at the top of the dir, refer to next item */
|
/* item is at the top of the dir, refer to next item */
|
||||||
if(dr->parent->sub == dr) {
|
if(dr->parent->sub == dr) {
|
||||||
dr->parent->sub = dr->next;
|
dr->parent->sub = dr->next;
|
||||||
cur = dr->next;
|
cur = dr->next;
|
||||||
}
|
}
|
||||||
/* else, get the previous item and update it's "next"-reference */
|
/* else, get the previous item and update it's "next"-reference */
|
||||||
else
|
else
|
||||||
for(tmp = dr->parent->sub; tmp != NULL; tmp = tmp->next)
|
for(tmp = dr->parent->sub; tmp != NULL; tmp = tmp->next)
|
||||||
if(tmp->next == dr) {
|
if(tmp->next == dr) {
|
||||||
tmp->next = dr->next;
|
tmp->next = dr->next;
|
||||||
cur = tmp;
|
cur = tmp;
|
||||||
}
|
}
|
||||||
/* no previous item, refer to parent dir */
|
/* no previous item, refer to parent dir */
|
||||||
if(cur == NULL && dr->parent->parent)
|
if(cur == NULL && dr->parent->parent)
|
||||||
cur = dr->parent;
|
cur = dr->parent;
|
||||||
}
|
}
|
||||||
|
|
@ -232,6 +226,7 @@ struct dir *freedir(struct dir *dr) {
|
||||||
return(cur);
|
return(cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *getpath(struct dir *cur, char *to) {
|
char *getpath(struct dir *cur, char *to) {
|
||||||
struct dir *d, *list[100];
|
struct dir *d, *list[100];
|
||||||
int c = 0;
|
int c = 0;
|
||||||
|
|
@ -248,3 +243,4 @@ char *getpath(struct dir *cur, char *to) {
|
||||||
|
|
||||||
return to;
|
return to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
80
src/util.h
Normal file
80
src/util.h
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
/* 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 _util_h
|
||||||
|
#define _util_h
|
||||||
|
|
||||||
|
#include "ncdu.h"
|
||||||
|
|
||||||
|
/* updated when window is resized */
|
||||||
|
extern int winrows, wincols;
|
||||||
|
|
||||||
|
/* used by the nc* functions and macros */
|
||||||
|
extern int subwinr, subwinc;
|
||||||
|
|
||||||
|
|
||||||
|
/* Instead of using several ncurses windows, we only draw to stdscr.
|
||||||
|
* the functions nccreate, ncprint and the macros ncaddstr and ncaddch
|
||||||
|
* mimic the behaviour of ncurses windows.
|
||||||
|
* This works better than using ncurses windows when all windows are
|
||||||
|
* created in the correct order: it paints directly on stdscr, so
|
||||||
|
* wrefresh, wnoutrefresh and other window-specific functions are not
|
||||||
|
* necessary.
|
||||||
|
* Also, this method doesn't require any window objects, as you can
|
||||||
|
* only create one window at a time.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* updates winrows, wincols, and displays a warning when the terminal
|
||||||
|
* is smaller than the specified minimum size. */
|
||||||
|
int ncresize(int, int);
|
||||||
|
|
||||||
|
/* creates a new centered window with border */
|
||||||
|
void nccreate(int, int, char *);
|
||||||
|
|
||||||
|
/* printf something somewhere in the last created window */
|
||||||
|
void ncprint(int, int, char *, ...);
|
||||||
|
|
||||||
|
/* same as the w* functions of ncurses */
|
||||||
|
#define ncaddstr(r, c, s) mvaddstr(subwinr+(r), subwinc+(c), s)
|
||||||
|
#define ncaddch(r, c, s) mvaddch(subwinr+(r), subwinc+(c), s)
|
||||||
|
#define ncmove(r, c) move(subwinr+(r), subwinc+(c))
|
||||||
|
|
||||||
|
/* crops a string into the specified length */
|
||||||
|
char *cropstr(const char *, int);
|
||||||
|
|
||||||
|
/* formats size in the form of xxx.xXB */
|
||||||
|
char *formatsize(const off_t, int);
|
||||||
|
|
||||||
|
/* int2string with thousand separators */
|
||||||
|
char *fullsize(const off_t);
|
||||||
|
|
||||||
|
/* recursively free()s a directory tree */
|
||||||
|
struct dir *freedir(struct dir *);
|
||||||
|
|
||||||
|
/* generates full path from a dir item */
|
||||||
|
char *getpath(struct dir *, char *);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
Loading…
Reference in a new issue