<commit_before>module GitHUD.Terminal.Base (
  addColorToStringForShell
  ) where

import Control.Monad.Reader (ask)
import Control.Monad.Writer (tell)

import GitHUD.Terminal.Types

addColorToStringForShell :: Color               -- ^ The terminal color to use
                         -> ColorIntensity      -- ^ The intensity to use
                         -> String              -- ^ The string to output
                         -> ShellOutput
addColorToStringForShell color intensity str = do
  outputConfig <- ask
  let shell = getShell outputConfig
  tell $ startColorMarker color intensity shell
  tell $ str
  tell $ endColorMarker shell

startColorMarker :: Color
                 -> ColorIntensity
                 -> Shell
                 -> String
startColorMarker color intensity shell =
  applyShellMarkers shell $ terminalStartCode color intensity

endColorMarker :: Shell
               -> String
endColorMarker shell =
  applyShellMarkers shell $ terminalEndCode

applyShellMarkers :: Shell
                  -> String
                  -> String
applyShellMarkers ZSH = zshMarkZeroWidth
applyShellMarkers _ = id

zshMarkZeroWidth :: String
                 -> String
zshMarkZeroWidth str = "%{" `mappend` str `mappend` "%}"
<commit_msg>[Refactor] one line detailled ask<commit_after>module GitHUD.Terminal.Base (
  addColorToStringForShell
  ) where

import Control.Monad (liftM)
import Control.Monad.Reader (ask)
import Control.Monad.Writer (tell)

import GitHUD.Terminal.Types

addColorToStringForShell :: Color               -- ^ The terminal color to use
                         -> ColorIntensity      -- ^ The intensity to use
                         -> String              -- ^ The string to output
                         -> ShellOutput
addColorToStringForShell color intensity str = do
  shell <- liftM getShell $ ask
  tell $ startColorMarker color intensity shell
  tell $ str
  tell $ endColorMarker shell

startColorMarker :: Color
                 -> ColorIntensity
                 -> Shell
                 -> String
startColorMarker color intensity shell =
  applyShellMarkers shell $ terminalStartCode color intensity

endColorMarker :: Shell
               -> String
endColorMarker shell =
  applyShellMarkers shell $ terminalEndCode

applyShellMarkers :: Shell
                  -> String
                  -> String
applyShellMarkers ZSH = zshMarkZeroWidth
applyShellMarkers _ = id

zshMarkZeroWidth :: String
                 -> String
zshMarkZeroWidth str = "%{" `mappend` str `mappend` "%}"

{'fraction_non_alphanumeric': 0.06656163844033083, 'fraction_numerical': 0.0, 'mean_word_length': 2.1165644171779143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '636414', 'n_tokens_mistral': 630, 'n_tokens_neox': 617, 'n_words': 185}