Skip to content

Commit

Permalink
Subtract one from 'line-trunc detect' option
Browse files Browse the repository at this point in the history
This avoids the terminal adding a newline once the terminal line is full.
  • Loading branch information
tbidne committed Jun 8, 2024
1 parent 85f1cab commit 6a8e079
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ the major/minor/patch definitions apply to the application's interface / usage
* Added GHC 9.10 support.

### Fixed
* Line truncation `detect` option now subtracts one, so terminals do not add
an extra newline.
* More `HasCallStack` annotations for better callstacks in case something goes
wrong.
* Increase default `--command-log-read-size` to `16 kb` to better prevent
Expand Down
6 changes: 5 additions & 1 deletion src/Shrun/Configuration/Data/Truncation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ configToLineTrunc ::
m (Maybe (Truncation TruncLine))
configToLineTrunc Disabled = pure Nothing
configToLineTrunc Without = pure Nothing
configToLineTrunc (With Detected) = Just . MkTruncation <$> getTerminalWidth
configToLineTrunc (With Detected) =
-- We subtract one because otherwise we can fill the entire terminal with a
-- log, which will automatically add a newline. The point of this option is
-- to avoid multiple lines, hence the subtraction.
Just . MkTruncation . (\x -> x - 1) <$> getTerminalWidth
configToLineTrunc (With (Undetected x)) = pure $ Just x
{-# INLINEABLE configToLineTrunc #-}
4 changes: 2 additions & 2 deletions test/integration/Integration/Miscellaneous.hs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ lineTruncDetect = testPropertyNamed desc "lineTruncDetect"
args = ["-c", getIntConfig "misc", "cmd1"]

expected =
[ #coreConfig % #consoleLogging % #lineTrunc % _Just ^?=@ Just 87,
#coreConfig % #fileLogging %? #lineTrunc % _Just ^?=@ Just 87
[ #coreConfig % #consoleLogging % #lineTrunc % _Just ^?=@ Just 86,
#coreConfig % #fileLogging %? #lineTrunc % _Just ^?=@ Just 86
]

testFileSizeModeNothing :: TestTree
Expand Down

0 comments on commit 6a8e079

Please sign in to comment.