commercialhaskell / rio

A standard library for Haskell
Other
836 stars 54 forks source link

Add colours to the `LogOption` constructor #222

Closed mpilgrem closed 4 years ago

mpilgrem commented 4 years ago

The motivation for this pull request is that the exisitng hard-coded colours in RIO.Process.withProcessTimeLog and RIO.Prelude.Logger.simpleLogFunc (for timestamps and locs) are not visible when using the Solarised Dark theme.

Tested on Windows 10 by sucessfully rebuilding stack (which depends on rio), with and without making use of the option to customise logger colours.

The defaults are the same as what was previously hard-coded and RIO.Prelude.Logger does not export the constructor of LogOption, so existing code depending on rio should not be affected.

A new LogColors type is exported, and an associated accessor (logFuncColorsL):

data LogColors = LogColors
  { -- | The color associated with each 'LogLevel'.
    logColorLogLevels :: !(LogLevel -> Utf8Builder)
    -- | The color of secondary content.
  , logColorSecondary :: !Utf8Builder
    -- | The color of accents, which are indexed by 'Int'.
  , logColorAccents :: !(Int -> Utf8Builder)
  }

timestamps and locs in simpleLogFunc use the colour of secondary content. withProcessTimeLog uses accent colour 0 to highlight the duration time.

mpilgrem commented 4 years ago

Since my original pull request, I have changed the type in the three setLog... functions from Text to Utf8Builder. Originally, I reasoned that Text was a more user-friendly type for those functions but now I think that it is wrong to impose the Text -> Utf8Builder overhead on all users.