shrun-0.9: A utility program for running shell commands concurrently.
Safe HaskellNone
LanguageGHC2021

Shrun.Logging.Formatting

Description

Provides Log formatting functionality.

Synopsis

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 #

Formats a Log into a FileLog. Applies prefix and timestamp.

Low-level

logToColor :: Log -> Color Source #

Transforms log to a color based on its LogLevel.

logToPrefix :: Log -> Text Source #

Transforms log to a prefix based on its LogLevel.

levelToPrefix :: LogLevel -> Text Source #

Maps LogLevel to 'Prefix'.

Utils

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.

brackets :: Bool -> Text -> Text Source #

Surrounds text with brackets, appending a space if the boolean is True.

Examples

Expand
>>> 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.