mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
Support exporting to stdout while still allowing -u 2 to work
This commit is contained in:
parent
9d341950ff
commit
7ccb98006a
2 changed files with 33 additions and 6 deletions
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
static FILE *stream;
|
static FILE *stream;
|
||||||
|
|
@ -131,8 +132,9 @@ static int final(int fail) {
|
||||||
|
|
||||||
|
|
||||||
int dir_export_init(const char *fn) {
|
int dir_export_init(const char *fn) {
|
||||||
/* TODO: stdout support */
|
if(strcmp(fn, "-") == 0)
|
||||||
if((stream = fopen(fn, "w")) == NULL)
|
stream = stdout;
|
||||||
|
else if((stream = fopen(fn, "w")) == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
level = 0;
|
level = 0;
|
||||||
|
|
|
||||||
33
src/main.c
33
src/main.c
|
|
@ -41,6 +41,7 @@ long update_delay = 100;
|
||||||
|
|
||||||
static int min_rows = 17, min_cols = 60;
|
static int min_rows = 17, min_cols = 60;
|
||||||
static int ncurses_init = 0;
|
static int ncurses_init = 0;
|
||||||
|
static int ncurses_tty = 0; /* Explicitely open /dev/tty instead of using stdio */
|
||||||
static long lastupdate = 999;
|
static long lastupdate = 999;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -165,17 +166,19 @@ static char *argv_parse(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(export) {
|
if(export) {
|
||||||
/* TODO: Support exporting to stdout */
|
|
||||||
if(dir_export_init(export)) {
|
if(dir_export_init(export)) {
|
||||||
printf("Can't open %s: %s\n", export, strerror(errno));
|
printf("Can't open %s: %s\n", export, strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
if(strcmp(export, "-") == 0)
|
||||||
|
ncurses_tty = 1;
|
||||||
} else
|
} else
|
||||||
dir_mem_init(NULL);
|
dir_mem_init(NULL);
|
||||||
|
|
||||||
/* Use the single-line scan feedback by default when exporting. */
|
/* Use the single-line scan feedback by default when exporting to file, no
|
||||||
|
* feedback when exporting to stdout. */
|
||||||
if(dir_ui == -1)
|
if(dir_ui == -1)
|
||||||
dir_ui = export ? 1 : 2;
|
dir_ui = export && strcmp(export, "-") == 0 ? 0 : export ? 1 : 2;
|
||||||
|
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
@ -183,10 +186,32 @@ static char *argv_parse(int argc, char **argv) {
|
||||||
|
|
||||||
/* Initializes ncurses only when not done yet. */
|
/* Initializes ncurses only when not done yet. */
|
||||||
static void init_nc() {
|
static void init_nc() {
|
||||||
|
int ok = 0;
|
||||||
|
FILE *tty;
|
||||||
|
SCREEN *term;
|
||||||
|
|
||||||
if(ncurses_init)
|
if(ncurses_init)
|
||||||
return;
|
return;
|
||||||
ncurses_init = 1;
|
ncurses_init = 1;
|
||||||
initscr();
|
|
||||||
|
if(ncurses_tty) {
|
||||||
|
tty = fopen("/dev/tty", "r+");
|
||||||
|
if(!tty) {
|
||||||
|
fprintf(stderr, "Error opening /dev/tty: %s\n", strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
term = newterm(NULL, tty, tty);
|
||||||
|
if(term)
|
||||||
|
set_term(term);
|
||||||
|
ok = !!term;
|
||||||
|
} else
|
||||||
|
ok = !!initscr();
|
||||||
|
|
||||||
|
if(!ok) {
|
||||||
|
fprintf(stderr, "Error while initializing ncurses.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
cbreak();
|
cbreak();
|
||||||
noecho();
|
noecho();
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue