hxbrief: Support --max-lines and Check non-overflow

master
Lennart Spitzner 2022-07-16 17:05:13 +02:00
parent 338df579e9
commit 86f952e572
1 changed files with 12 additions and 1 deletions

View File

@ -465,6 +465,7 @@ main :: IO ()
main = B.mainFromCmdParser $ do main = B.mainFromCmdParser $ do
B.reorderStart B.reorderStart
numLines :: Int <- B.addFlagReadParam "n" ["lines"] "LINES" (B.flagDefault 5) numLines :: Int <- B.addFlagReadParam "n" ["lines"] "LINES" (B.flagDefault 5)
maxLines <- B.addSimpleBoolFlag "" ["max-lines"] mempty
keepStdout <- B.addSimpleBoolFlag "" ["keep-out"] mempty keepStdout <- B.addSimpleBoolFlag "" ["keep-out"] mempty
keepStderr <- B.addSimpleBoolFlag "" ["keep-err"] mempty keepStderr <- B.addSimpleBoolFlag "" ["keep-err"] mempty
keepBoth <- B.addSimpleBoolFlag "" ["keep"] mempty keepBoth <- B.addSimpleBoolFlag "" ["keep"] mempty
@ -557,6 +558,16 @@ main = B.mainFromCmdParser $ do
$ [ () | keepStderr || keepBoth ] $ [ () | keepStderr || keepBoth ]
++ [ () | conflateStderr || conflateBoth ] ++ [ () | conflateStderr || conflateBoth ]
++ [ () | dropStderr || dropBoth ] ++ [ () | dropStderr || dropBoth ]
adjustedNumLines <- case termSizeMay of
Just (termLines, _) | maxLines -> pure $ max 1 (termLines - 3)
Just (termLines, _) | termLines < numLines + 3 -> do
let actual = max 1 (termLines - 3)
errorConcurrent
$ "Warning: output is too small, only showing "
++ show actual
++ " lines!\n"
pure actual
_ -> pure numLines
(lastLine, ecMay) <- displayConsoleRegions $ do (lastLine, ecMay) <- displayConsoleRegions $ do
initialState <- do initialState <- do
startTime <- getTime RealtimeCoarse startTime <- getTime RealtimeCoarse
@ -569,7 +580,7 @@ main = B.mainFromCmdParser $ do
in if length full < 80 then full else head rest in if length full < 80 then full else head rest
[labelStr] -> labelStr [labelStr] -> labelStr
_ -> error "too many labels!" _ -> error "too many labels!"
, c_lines = numLines , c_lines = adjustedNumLines
, c_keepStdout = if , c_keepStdout = if
| stdoutCheckCount > 1 -> error | stdoutCheckCount > 1 -> error
"too many keep/drop/conflate for stdout!" "too many keep/drop/conflate for stdout!"