commit d2b5815892c51b2d621b569f810b8705914b1b4f
parent ad5ffa451b6128105c297323c8df0242683d9ca3
Author: Szymon Mikulicz <szymon.mikulicz@posteo.net>
Date: Mon, 16 Mar 2026 18:15:07 +0100
Log if not tty
Diffstat:
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/libc.janet b/src/libc.janet
@@ -73,6 +73,7 @@
(ctry (c/sendfile out_fd in_fd offset/ptr count_)))
(defbind get_nprocs :int)
+(defbind isatty :int :int)
(defbind/str dirname)
(defbind/str basename)
(defbind/str mkdtemp)
diff --git a/src/main.janet b/src/main.janet
@@ -5,6 +5,7 @@
(import ./native/nftw)
(def columns ((libc/ioctl 1 :TIOCGWINSZ) 1))
+(def tty? (= (libc/isatty 1) 1))
(def spinner "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏")
(var ch (string/slice spinner 0 3))
@@ -14,9 +15,12 @@
(defn msg [state line logfile]
(file/write logfile line "\n")
- (def pre (string/format "\x1b[2K{%s}⸉%s⸊→" state ch))
- (prinf "%s%s\r" pre (string/slice line 0 (min (- columns (length pre)) (length line))))
- (flush))
+ (if tty?
+ (do
+ (def pre (string/format "\x1b[2K{%s}⸉%s⸊→" state ch))
+ (prinf "%s%s\r" pre (string/slice line 0 (max 0 (min (- columns (length pre)) (length line)))))
+ (flush))
+ (printf "{%s}→%s" state line)))
(defn prinfer [state logfile pipe]
(def buf @"")
@@ -44,7 +48,7 @@
(prinfer state logfile (proc :out))
(prinfer state logfile (proc :err))
(os/proc-wait proc)
- (while (= (get proc :return-code) nil)
+ (while (and tty? (nil? (get proc :return-code)))
(ev/sleep 0.2)
(set ch (rotate ch))
(prinf "{%s}⸉%s⸊\r" state ch)