Skip to content

Commit 08225fe

Browse files
committed
Use underlining layer from ansi-terminal >= 1.1
This adds styling for underline colors. See also #183.
1 parent 8471fd2 commit 08225fe

File tree

6 files changed

+50
-31
lines changed

6 files changed

+50
-31
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,15 @@ and `onRgb#101060` for a deep purple background). Naturally, your terminal
517517
needs to support 24-bit RGB for this to work. When creating portable
518518
presentations, it might be better to stick with the named colours listed above.
519519

520+
To customize the color of the `underline`, combine the prefix with a color, for
521+
example:
522+
523+
```yaml
524+
patat:
525+
theme:
526+
strong: [underline, underlineVividBlue]
527+
```
528+
520529
### Syntax Highlighting
521530

522531
`patat` uses [Kate] Syntax Highlighting files. `patat` ships with support for

flake.nix

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
packages = [
2121
pkgs.cabal-install
2222
pkgs.entr
23+
pkgs.wezterm
2324
haskell.goldplate
2425
haskell.stylish-haskell
2526
(haskell.ghc.withPackages (p: inputs.self.packages.${system}.default.buildInputs))

lib/Patat/Theme.hs

+29-29
Original file line numberDiff line numberDiff line change
@@ -180,41 +180,41 @@ rgbToSgr layer rgbHex =
180180

181181
--------------------------------------------------------------------------------
182182
sgrToString :: Ansi.SGR -> Maybe String
183-
sgrToString (Ansi.SetColor layer intensity color) = Just $
184-
(\str -> case layer of
185-
Ansi.Foreground -> str
186-
Ansi.Background -> "on" ++ capitalize str) $
187-
(case intensity of
188-
Ansi.Dull -> "dull"
189-
Ansi.Vivid -> "vivid") ++
190-
(case color of
191-
Ansi.Black -> "Black"
192-
Ansi.Red -> "Red"
193-
Ansi.Green -> "Green"
194-
Ansi.Yellow -> "Yellow"
195-
Ansi.Blue -> "Blue"
196-
Ansi.Magenta -> "Magenta"
197-
Ansi.Cyan -> "Cyan"
198-
Ansi.White -> "White")
199-
200-
sgrToString (Ansi.SetUnderlining Ansi.SingleUnderline) = Just "underline"
201-
202-
sgrToString (Ansi.SetConsoleIntensity Ansi.BoldIntensity) = Just "bold"
203-
204-
sgrToString (Ansi.SetItalicized True) = Just "italic"
205-
206-
sgrToString (Ansi.SetRGBColor layer color) = Just $
207-
(\str -> case layer of
208-
Ansi.Foreground -> str
209-
Ansi.Background -> "on" ++ capitalize str) $
210-
"rgb#" ++ (toRGBHex $ toSRGB24 color)
183+
sgrToString sgr = case sgr of
184+
Ansi.SetColor layer intensity color -> Just $ layerPrefix layer $
185+
(case intensity of
186+
Ansi.Dull -> "dull"
187+
Ansi.Vivid -> "vivid") ++
188+
(case color of
189+
Ansi.Black -> "Black"
190+
Ansi.Red -> "Red"
191+
Ansi.Green -> "Green"
192+
Ansi.Yellow -> "Yellow"
193+
Ansi.Blue -> "Blue"
194+
Ansi.Magenta -> "Magenta"
195+
Ansi.Cyan -> "Cyan"
196+
Ansi.White -> "White")
197+
198+
Ansi.SetUnderlining Ansi.SingleUnderline -> Just "underline"
199+
200+
Ansi.SetConsoleIntensity Ansi.BoldIntensity -> Just "bold"
201+
202+
Ansi.SetItalicized True -> Just "italic"
203+
204+
Ansi.SetRGBColor layer color -> Just $ layerPrefix layer $
205+
"rgb#" ++ (toRGBHex $ toSRGB24 color)
206+
207+
_ -> Nothing
211208
where
212209
toRGBHex (RGB r g b) = concat $ map toHexByte [r, g, b]
213210
toHexByte x = showHex2 x ""
214211
showHex2 x | x <= 0xf = ("0" ++) . showHex x
215212
| otherwise = showHex x
216213

217-
sgrToString _ = Nothing
214+
layerPrefix layer str = case layer of
215+
Ansi.Foreground -> str
216+
Ansi.Background -> "on" ++ capitalize str
217+
Ansi.Underlining -> "underline" ++ capitalize str
218218

219219

220220
--------------------------------------------------------------------------------

patat.cabal

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Library
3333

3434
Build-depends:
3535
aeson >= 2.0 && < 2.3,
36-
ansi-terminal >= 0.6 && < 1.2,
36+
ansi-terminal >= 1.1 && < 1.2,
3737
ansi-wl-pprint >= 0.6 && < 1.1,
3838
async >= 2.2 && < 2.3,
3939
base >= 4.9 && < 5,
@@ -155,7 +155,7 @@ Test-suite patat-tests
155155

156156
Build-depends:
157157
patat,
158-
ansi-terminal >= 0.6 && < 1.2,
158+
ansi-terminal >= 1.1 && < 1.2,
159159
base >= 4.8 && < 5,
160160
directory >= 1.2 && < 1.4,
161161
pandoc >= 3.1 && < 3.7,

tests/golden/inputs/themes.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ patat:
44
bulletListMarkers: '-+'
55
emph: [onVividRed, underline]
66
strong: [rgb#f08000, onRgb#101060]
7+
header: [vividGreen, underline, underlineVividBlue]
78
...
89

10+
# Just a header
11+
912
- This is a simple list.
1013
* With _nested_ items.
1114
* One or two **bold**.
1215
- The list theming is customized a bit.
16+
17+
WezTerm is suitable for viewing this presentation.

tests/golden/outputs/themes.md.dump

+4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
 themes.md 
22

3+
[58:5:12;4;92m# Just a header
4+
35
 - This is a simple list.
46
 + With nested items.
57
 + One or two bold.
68

79
 - The list theming is customized a bit.
810

11+
WezTerm is suitable for viewing this presentation.
12+
913
 1 / 1 

0 commit comments

Comments
 (0)