The System.Console.ANSI
package has additional options for ColorIntensity = Vivid | Dull
. Would you accept a PR adding support for this style of formatting?
I took a quick look at the source, and it looks like it should be possible with the following steps:
|
data Modifier = Modifier |
|
{ modColorFG :: OnlyOne Color, |
|
modColorBG :: OnlyOne Color, |
|
modBold :: Status, |
|
modUnderline :: Status, |
|
modSwapFgBg :: Status |
|
} |
|
deriving (Show, Eq) |
|
modToSGR mod colorF = |
|
catMaybes |
|
[ colorF ANSI.Foreground <$> getColor modColorFG, |
|
colorF ANSI.Background <$> getColor modColorBG, |
|
ANSI.SetConsoleIntensity <$> getIntensity, |
|
ANSI.SetUnderlining <$> getUnderlining, |
|
ANSI.SetSwapForegroundBackground <$> getSwapForegroundBackground |
|
] |
|
where |
|
getColor :: (Modifier -> OnlyOne Color) -> Maybe Color |
|
getColor f = unOne (f mod) |
|
getIntensity :: Maybe ANSI.ConsoleIntensity |
|
getIntensity = case modBold mod of |
|
Off -> Nothing |
|
On -> Just ANSI.BoldIntensity |
|
getUnderlining :: Maybe ANSI.Underlining |
|
getUnderlining = case modUnderline mod of |
|
Off -> Nothing |
|
On -> Just ANSI.SingleUnderline |
|
getSwapForegroundBackground :: Maybe Bool |
|
getSwapForegroundBackground = case modSwapFgBg mod of |
|
Off -> Nothing |
|
On -> Just True |
- allow the modifier to override the default value of
ANSI.Dull
set by Simple and TermRGB cases
|
renderMod :: RenderMode -> (Text, Modifier) -> [RenderInstruction] |
|
renderMod mode (t, m) = |
|
case mode of |
|
Plain -> |
|
-- Only render text, no modifiers. |
|
[RenderText t] |
|
Simple -> |
|
-- Terminal supports basic 16 colors. |
|
let color l = ANSI.SetColor l ANSI.Dull . Color.colorAsANSI |
|
in renderToSGR t m color |
|
Term256 -> |
|
-- Terminal supports the 256-color palette. |
|
let color l = ANSI.SetPaletteColor l . Color.colorAsIndex256 |
|
in renderToSGR t m color |
|
TermRGB -> |
|
-- Super terminal! |
|
let color l c = case Color.colorAsRGB c of |
|
Left ac -> ANSI.SetColor l ANSI.Dull ac |
|
Right rgb -> ANSI.SetRGBColor l rgb |
|
in renderToSGR t m color |