aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2023-04-17 22:04:03 -0400
committerShav Kinderlehrer <[email protected]>2023-04-17 22:04:03 -0400
commitb60ecd747be86ae034538b64968c089a3149a4e5 (patch)
tree8f589e2decd68fb54bed6e1712474f0145037fd5
parentf8bdf764b2a532e878f47010428aee534793dd5f (diff)
downloadlat-0.9.0.tar.gz
lat-0.9.0.zip
Add argsv0.9.0
- --headers
-rw-r--r--include/arg.h1
-rw-r--r--src/lib/arg.c9
-rw-r--r--src/main.c9
3 files changed, 16 insertions, 3 deletions
diff --git a/include/arg.h b/include/arg.h
index 5c45800..e37a950 100644
--- a/include/arg.h
+++ b/include/arg.h
@@ -9,6 +9,7 @@ struct config {
bool process;
bool color;
bool lines;
+ bool headers;
bool force_binary;
bool has_read_stdin;
};
diff --git a/src/lib/arg.c b/src/lib/arg.c
index 39bc816..3db3e8f 100644
--- a/src/lib/arg.c
+++ b/src/lib/arg.c
@@ -11,6 +11,7 @@ void help(void) {
printf("options:\n"
"\t-c, --color\t toggle whether to print color or not\n"
"\t-n, --lines\t toggle whether to print line numbers or not\n"
+ "\t-t, --headers\t toggle whether to print file headers or not\n"
"\t-b, --binary\t toggle whether to force the data to be treated as "
"binary or not\n"
"\t-V, --version\t show program version\n"
@@ -40,6 +41,11 @@ void parselongarg(char *arg) {
return;
}
+ if (strcmp(arg, "--headers")) {
+ conf.headers = !conf.headers;
+ return;
+ }
+
if (strcmp(arg, "--binary") == 0) {
conf.force_binary = !conf.force_binary;
return;
@@ -71,6 +77,9 @@ void parseshortarg(char *arg) {
case 'n':
conf.lines = !conf.lines;
break;
+ case 't':
+ conf.headers = !conf.headers;
+ break;
case 'b':
conf.force_binary = !conf.force_binary;
break;
diff --git a/src/main.c b/src/main.c
index 13d0bf8..72b4e9d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -27,7 +27,9 @@ void run(FILE *fp, char *filename, bool tty) {
f.binary = !f.binary;
}
- if (tty) {
+ conf.headers = conf.headers && tty; // tty still overrides user
+
+ if (conf.headers) {
char *addon = f.binary ? "<binary>" : "";
fprintf(stderr, "\r\x1b[2K%s%s%s%s\r\n", invert_t, basename(filename),
addon, reset);
@@ -60,7 +62,7 @@ void run(FILE *fp, char *filename, bool tty) {
fflush(stdout); // prevent timing inconsistencies between stdout and stderr
- if (tty) {
+ if (conf.headers) {
float rounded;
char *format = formatbytes(f.buflen, &rounded);
@@ -71,10 +73,11 @@ void run(FILE *fp, char *filename, bool tty) {
void initconf(void) {
conf.stdin = false;
conf.force_binary = false;
+ conf.has_read_stdin = false;
conf.process = true;
+ conf.headers = true;
conf.color = true;
conf.lines = true;
- conf.has_read_stdin = false;
}
void clearstdin(void) {