| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Shrun.Logging.Formatting
Contents
Description
Provides Log formatting functionality.
Synopsis
- formatConsoleLog :: KeyHideSwitch -> ConsoleLoggingEnv -> Log -> ConsoleLog
- formatFileLog :: (HasCallStack, MonadTime m) => KeyHideSwitch -> FileLoggingEnv -> Log -> m FileLog
- logToColor :: Log -> Color
- logToPrefix :: Log -> Text
- levelToColor :: LogLevel -> Color
- levelToPrefix :: LogLevel -> Text
- formatCommand :: KeyHideSwitch -> Maybe (Truncation 'TruncCommandName) -> CommandP1 -> UnlinedText
- concatWithLineTrunc :: Maybe (Truncation 'TruncLine, Maybe Natural) -> Text -> Text -> Text
- displayCmd :: CommandP1 -> KeyHideSwitch -> UnlinedText
- stripChars :: forall (t :: StripControlType). UnlinedText -> StripControl t -> UnlinedText
- brackets :: Bool -> Text -> Text
- formatCommandText :: Text -> UnlinedText
High-level
formatConsoleLog :: KeyHideSwitch -> ConsoleLoggingEnv -> Log -> ConsoleLog Source #
Formats a log to be printed to the console.
formatFileLog :: (HasCallStack, MonadTime m) => KeyHideSwitch -> FileLoggingEnv -> Log -> m FileLog Source #
Low-level
Utils
formatCommand :: KeyHideSwitch -> Maybe (Truncation 'TruncCommandName) -> CommandP1 -> UnlinedText Source #
concatWithLineTrunc :: Maybe (Truncation 'TruncLine, Maybe Natural) -> Text -> Text -> Text Source #
Combines a prefix p and msg m with possible line truncation. If no
truncation is given then concatWithLineTrunc is equivalent to p <> m.
If we are given some line truncation l, then we derive
k := l - prefix_len -- k is clamped to zero
and return
prefix <> t'
where t' is t truncated to k chars. Notice the prefix is always
included untarnished.
displayCmd :: CommandP1 -> KeyHideSwitch -> UnlinedText Source #
Pretty show for Command. If the command has a key, and KeyHideSwitch is
KeyHideOff then we return the key. Otherwise we return the command itself.
>>>displayCmd (MkCommandP Nothing "some long command") KeyHideOn"some long command"
>>>displayCmd (MkCommandP Nothing "some long command") KeyHideOff"some long command"
>>>displayCmd (MkCommandP (Just "long") "some long command") KeyHideOn"some long command"
>>>displayCmd (MkCommandP (Just "long") "some long command") KeyHideOff"long"
stripChars :: forall (t :: StripControlType). UnlinedText -> StripControl t -> UnlinedText Source #
Applies the given StripControl to the Text.
StripControlAll: Strips whitespace + all control chars.StripControlSmart: Strips whitespace + 'ansi control' chars.StripControlNone: Strips whitespace.
brackets :: Bool -> Text -> Text Source #
Surrounds text with brackets, appending a space if the boolean is True.
Examples
>>>brackets False "text""[text]"
>>>brackets True "text""[text] "
formatCommandText :: Text -> UnlinedText Source #
Replace newlines with whitespace before stripping, so any strings separated by newlines do not get smashed together.