diff options
author | Ben Sima <ben@bsima.me> | 2024-04-15 15:59:20 -0400 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2024-04-15 16:00:53 -0400 |
commit | d36b4360c9c359e6eea480b39e9699b1deae70f1 (patch) | |
tree | c5991b4b5e339d9f33eaca4fc12fa87a2e387b79 | |
parent | bceac781e4505a6e2089621012deee449fe62b11 (diff) |
Wrap bild log at the terminal-supplied width
Apparently `$COLUMNS` is a POSIX standard, which allows us to set the print
width to however wide the user's terminal is. This is a better UI on both wide
and narrow terminal layouts: on very narrow layouts, the terminal will properly
clear the line instead of doing the wrap-print thing it does when the line
overflows, and on wide layouts you can see more of the log message if you're
curious. This only works if you export `$COLUMNS` though, because bash only sets
the variable in interactive mode, so by default a running program doesn't see it.
<https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html>
-rw-r--r-- | .envrc | 1 | ||||
-rw-r--r-- | Biz/Bild.hs | 24 |
2 files changed, 15 insertions, 10 deletions
@@ -14,6 +14,7 @@ use nix # export CODEROOT=$PWD + export COLUMNS # # scripts for editing go here PATH_add $CODEROOT/Biz/Ide diff --git a/Biz/Bild.hs b/Biz/Bild.hs index cc10782..1ca0a2c 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -1011,16 +1011,20 @@ logs :: Conduit.ConduitT () ByteString (Conduit.ResourceT IO) () -> IO ByteString logs ns src = - Conduit.runConduitRes - <| src - .| Conduit.iterM - ( ByteString.filter (/= BSI.c2w '\n') - .> (\t -> Log.fmt ["info", "bild", nschunk ns, decodeUtf8 t]) - .> Text.take 79 - .> (<> "…\r") - .> putStr - ) - .| Conduit.foldC + Env.lookupEnv "COLUMNS" + -- is there a better way to set a default? + /> maybe 79 (readMaybe .> fromMaybe 79) + +> \columns -> + src + .| Conduit.iterM + ( ByteString.filter (/= BSI.c2w '\n') + .> (\t -> Log.fmt ["info", "bild", nschunk ns, decodeUtf8 t]) + .> Text.take (columns - 1) + .> (<> "…\r") + .> putStr + ) + .| Conduit.foldC + |> Conduit.runConduitRes nschunk :: Namespace -> Text nschunk = Namespace.toPath .> Text.pack |