Compare commits

...

12 Commits

Author SHA1 Message Date
Lennart Spitzner 49ffea3f2e Implement filter for console escape codes (behind flag)
--filter-escape-sequences filters output from the subprocess
so that backspace is respected, color codes and cursor
movement get ignored. In general the subprocess should be
configured to produce plain output instead, though.
2023-02-20 18:22:37 +01:00
Lennart Spitzner ac6997be19 Show per-line wall clock info 2023-02-20 15:00:45 +01:00
Lennart Spitzner ca93157c6e Support second-level headers 2022-12-12 18:48:28 +01:00
Lennart Spitzner 8956098913 Support error-start/stop for capturing regex-matched error output 2022-12-12 17:10:17 +01:00
Lennart Spitzner 095eab90dc Support headers 2022-12-12 13:03:09 +01:00
Lennart Spitzner 33019050c5 Add more butcher docs 2022-12-08 18:13:13 +01:00
Lennart Spitzner 72d7a1d601 Capture per-line time taken, improve time output 2022-12-08 18:12:51 +01:00
Lennart Spitzner 0878254f71 Switch default behaviour: keep both stdout/stderr by default 2022-12-08 15:45:19 +01:00
Lennart Spitzner 26ae1fc40d Change flag semantics: match prefix by default
New variants summarize-any, skip-any, yield-any to match
anywhere in the input lines
2022-12-08 15:44:39 +01:00
Lennart Spitzner d8fa897a70 Support regexes via regex-pcre 2022-12-08 15:42:44 +01:00
Lennart Spitzner c3cc2e8170 Refactor from String to Text 2022-12-07 16:46:58 +01:00
Lennart Spitzner 118b8ddef2 Update seaaye.nix versions/pins 2022-12-07 13:27:20 +01:00
4 changed files with 594 additions and 366 deletions

View File

@ -33,7 +33,10 @@ executable hxbrief
async >=2.2.3 && <2.3,
transformers >=0.5.6.2 &&<0.6,
clock >=0.8 &&<0.9,
pretty >=1.1.3.6 && <1.2
pretty >=1.1.3.6 && <1.2,
text >=1.2.4,
regex-base >=0.94 && <0.95,
regex-pcre-builtin >=0.95 && < 0.96
hs-source-dirs: src-hxbrief
default-language: Haskell2010
ghc-options: -rtsopts -threaded -Wall

View File

@ -4,23 +4,24 @@
{
hackage-8-10 = {
resolver = "hackage";
index-state = "2021-07-01T00:00:00Z";
index-state = "2022-07-01T00:00:00Z";
ghc-ver = "ghc8107";
};
hackage-9-01 = {
hackage-9-00 = {
resolver = "hackage";
index-state = "2021-07-01T00:00:00Z";
ghc-ver = "ghc901";
index-state = "2022-07-01T00:00:00Z";
ghc-ver = "ghc902";
enabled = false;
};
hackage-9-02 = {
resolver = "hackage";
index-state = "2021-11-01T00:00:00Z";
ghc-ver = "ghc921";
index-state = "2022-07-01T00:00:00Z";
ghc-ver = "ghc925";
enabled = false;
};
};
module-flags = [
# { enableLibraryProfiling = true; }
# N.B.: There are haskell-nix module options. See the haskell-nix docs
# for details. Also, be careful about typos: In many cases you
# will not get errors but the typo'd flag will just not have any

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,9 @@
module Util where
import qualified Data.Char as Char
import Data.Text ( Text )
import qualified Data.Text as Text
import qualified System.Console.ANSI as Ansi
import System.Exit ( ExitCode
( ExitFailure
@ -11,27 +14,60 @@ import System.Exit ( ExitCode
)
t :: String -> Text
t = Text.pack
fGrey :: String
fGrey = Ansi.setSGRCode [Ansi.SetColor Ansi.Foreground Ansi.Dull Ansi.White]
fWhite :: String
fWhite = Ansi.setSGRCode [Ansi.SetColor Ansi.Foreground Ansi.Vivid Ansi.White]
fWhiteDis :: String
fWhiteDis = ""
fRedDis :: String
fRedDis = "" -- TODO disabled until the bug is fixed.
fGrey :: Text
fGrey =
t $ Ansi.setSGRCode [Ansi.SetColor Ansi.Foreground Ansi.Dull Ansi.White]
fWhite :: Text
fWhite =
t $ Ansi.setSGRCode [Ansi.SetColor Ansi.Foreground Ansi.Vivid Ansi.White]
fWhiteDis :: Text
fWhiteDis = t ""
fRedDis :: Text
fRedDis = t "" -- TODO disabled until the bug is fixed.
-- setFGColorDull Ansi.Red
fReset :: String
fReset = Ansi.setSGRCode [Ansi.Reset]
fReset :: Text
fReset = t $ Ansi.setSGRCode [Ansi.Reset]
setFGColorVivid :: Ansi.Color -> String
setFGColorVivid :: Ansi.Color -> Text
setFGColorVivid c =
Ansi.setSGRCode [Ansi.SetColor Ansi.Foreground Ansi.Vivid c]
setFGColorDull :: Ansi.Color -> String
setFGColorDull c = Ansi.setSGRCode [Ansi.SetColor Ansi.Foreground Ansi.Dull c]
t $ Ansi.setSGRCode [Ansi.SetColor Ansi.Foreground Ansi.Vivid c]
setFGColorDull :: Ansi.Color -> Text
setFGColorDull c =
t $ Ansi.setSGRCode [Ansi.SetColor Ansi.Foreground Ansi.Dull c]
showEC :: ExitCode -> String
showEC :: ExitCode -> Text
showEC = \case
ExitSuccess -> setFGColorVivid Ansi.Green ++ "0" ++ fReset
ExitFailure i -> setFGColorVivid Ansi.Red ++ show i ++ fReset
ExitSuccess -> setFGColorVivid Ansi.Green <> t "0" <> fReset
ExitFailure i -> setFGColorVivid Ansi.Red <> t (show i) <> fReset
filterEscapeFunc :: Text -> Text
filterEscapeFunc input = go Text.empty input
where
isSpecial c = Char.isControl c
go clean open = case Text.break isSpecial open of
(a, b) -> case Text.uncons b of
Nothing -> clean <> a
Just ('\x07', rest) -> go (clean <> a) rest -- bell
Just ('\x08', rest) -> if Text.null a -- backspace
then if Text.null clean
then go clean rest
else go (Text.init clean) rest
else go (clean <> Text.init a) rest
Just ('\x09', rest) -> -- tab
go (clean <> a <> Text.pack " ") rest
Just ('\x1b', rest) -> -- esc
clean <> a <> case Text.uncons rest of
Nothing -> Text.empty
Just ('\x5b', more) -> finishEscape more
Just ('\x9b', more) -> finishEscape more
Just (_ , more) -> filterEscapeFunc more
Just (_, rest) -> go (clean <> a) rest
finishEscape remain = case Text.uncons remain of
Nothing -> remain
Just (c, rest) -> if c >= '\x40' && c <= '\x7e'
then filterEscapeFunc rest
else finishEscape rest