From c6e0d99ead7cdc4e1e1b59d5bd84a528d3a8f3d8 Mon Sep 17 00:00:00 2001 From: Tommy Bidne Date: Sat, 25 May 2024 08:06:52 +1200 Subject: [PATCH] Simplify log formatting --- src/Shrun/Logging/Formatting.hs | 39 ++++++++++++++------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/Shrun/Logging/Formatting.hs b/src/Shrun/Logging/Formatting.hs index 57ced1d8..2b047d74 100644 --- a/src/Shrun/Logging/Formatting.hs +++ b/src/Shrun/Logging/Formatting.hs @@ -149,30 +149,23 @@ coreFormatting :: Log -> Text coreFormatting mLineTrunc mCommandNameTrunc stripControl keyHide log = - let line = case log ^. #cmd of - Nothing -> - let totalPrefix = brackets True logPrefix - in concatWithLineTrunc - mLineTrunc - totalPrefix - msgStripped - Just cmd -> - let cmd' = - formatCommand - keyHide - mCommandNameTrunc - cmd - totalPrefix = - mconcat - [ brackets False logPrefix, - cmd' - ] - in concatWithLineTrunc - mLineTrunc - totalPrefix - msgStripped - in line + concatWithLineTrunc mLineTrunc prefix msgStripped where + -- prefix is something like "[Success] " or "[Command][some cmd] ". + -- Notice this does not include ANSI codes or a timestamp. + prefix = case log ^. #cmd of + Nothing -> brackets True logPrefix + Just cmd -> + let cmd' = + formatCommand + keyHide + mCommandNameTrunc + cmd + in mconcat + [ brackets False logPrefix, + cmd' + ] + msgStripped = stripChars (log ^. #msg) stripControl logPrefix = logToPrefix log