aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2023-06-09 13:52:14 -0400
committerShav Kinderlehrer <[email protected]>2023-06-09 13:56:16 -0400
commit925ba68c3ca97b8d437f95f3b329b50f43238907 (patch)
tree77938c5d4aa68fb7d06888517f80555b5c475b4b
parent1577a74d584bc8ea48aaea2adf137dda936247eb (diff)
downloadlat-925ba68c3ca97b8d437f95f3b329b50f43238907.tar.gz
lat-925ba68c3ca97b8d437f95f3b329b50f43238907.zip
Add auto-pager
-rw-r--r--.gitignore2
-rw-r--r--Makefile1
-rw-r--r--include/arg.h2
-rw-r--r--src/lib/arg.c6
-rw-r--r--src/main.c22
5 files changed, 21 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index cd68208..5951e7e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -130,5 +130,3 @@ $RECYCLE.BIN/
*.lnk
# End of https://www.toptal.com/developers/gitignore/api/c,macos,windows,linux,c
-
-build/
diff --git a/Makefile b/Makefile
index eaa3393..c847972 100644
--- a/Makefile
+++ b/Makefile
@@ -34,7 +34,6 @@ prep:
-@mkdir -p $(IDIR)
-@mkdir -p $(ODIR)
-@mkdir -p $(BINDIR)
- @echo $(BINDIR)/ >> .gitignore
.PHONY: clean
clean:
diff --git a/include/arg.h b/include/arg.h
index 944d002..0e5b389 100644
--- a/include/arg.h
+++ b/include/arg.h
@@ -2,7 +2,7 @@
#define ARG_H
#include <stdbool.h>
-#define LAT_VERSION "0.12.4"
+#define LAT_VERSION "0.13.0"
struct config {
bool isstdin;
diff --git a/src/lib/arg.c b/src/lib/arg.c
index 993f7fa..bb2928c 100644
--- a/src/lib/arg.c
+++ b/src/lib/arg.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdnoreturn.h>
+#include <sys/ioctl.h>
#include <unistd.h>
#include "arg.h"
@@ -24,9 +25,10 @@ void help(void) {
"binary\n"
"\t-r print everything (headers, line numbers, etc.) to "
"stdout (or equivalent)\n"
- "\t-p print file with the pager (uses less)\n"
+ "\t-p disable or enable pager (uses less)\n"
"\t-n <name> manually set the name of the file shown in the title\n"
- // "\t-e <program> NONFUNCTIONAL (will be added soon) link extension to lat\n"
+ // "\t-e <program> NONFUNCTIONAL (will be added soon) link extension
+ // to lat\n"
"\t-V show program version\n"
"\t-h display this help text\n\n");
printf("environment:\n"
diff --git a/src/main.c b/src/main.c
index 5d4a097..23e59b8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <sys/ioctl.h>
#include <unistd.h>
#include "arg.h"
@@ -52,10 +53,25 @@ void run(FILE *fp, char *filename, bool tty) {
struct filedata f;
f = readfile(fp, conf.isstdin);
+ // any/all processing to be done
+ // TODO: maybe multithread?
+ conf.process = (tty && !f.binary);
+ if (conf.process) { // file display processing
+ loadlines(&f);
+ }
+
if (conf.extension != NULL) {
// TODO
}
+ struct winsize w;
+
+ if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1 || w.ws_col != 0) {
+ if (w.ws_row <= f.lc + 5) {
+ conf.pager = !conf.pager;
+ }
+ }
+
if (conf.pager) {
st = popen("less", "w");
err = st;
@@ -78,12 +94,6 @@ void run(FILE *fp, char *filename, bool tty) {
printheadertop(filename, f.binary);
}
- // any/all processing to be done
- conf.process = (tty && !f.binary);
- if (conf.process) { // file display processing
- loadlines(&f);
- }
-
if (conf.process) {
int linecount = 1;
for (int i = 0; i < f.lc; i++) {