Skip to content

Commit 77ee0e8

Browse files
committed
Add initial external API for colored docs
1 parent af65639 commit 77ee0e8

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/Text/DocLayout.hs

+48
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ module Text.DocLayout (
5959
, bold
6060
, italic
6161
, underlined
62+
, fg
63+
, bg
64+
, Color
65+
, black
66+
, red
67+
, green
68+
, yellow
69+
, blue
70+
, magenta
71+
, cyan
72+
, white
6273
, empty
6374
-- * Functions for concatenating documents
6475
, (<+>)
@@ -754,6 +765,43 @@ italic = styled (RShape Italic)
754765
underlined :: HasChars a => Doc a -> Doc a
755766
underlined = styled (RUnderline ULSingle)
756767

768+
-- The Color type is here as an opaque alias to Color8 for the public interface
769+
-- and there's trivial smart constructors for the individual colors to
770+
-- hopefully allow for easier extension to supporting indexed and rgb colors in
771+
-- the future, without dramatically changing the public API.
772+
773+
type Color = Color8
774+
775+
fg :: HasChars a => Color -> Doc a -> Doc a
776+
fg = styled . RForeground . FG
777+
778+
bg :: HasChars a => Color -> Doc a -> Doc a
779+
bg = styled . RBackground . BG
780+
781+
blue :: Color
782+
blue = Blue
783+
784+
black :: Color
785+
black = Black
786+
787+
red :: Color
788+
red = Red
789+
790+
green :: Color
791+
green = Green
792+
793+
yellow :: Color
794+
yellow = Yellow
795+
796+
magenta :: Color
797+
magenta = Magenta
798+
799+
cyan :: Color
800+
cyan = Cyan
801+
802+
white :: Color
803+
white = White
804+
757805
-- | Returns width of a character in a monospace font: 0 for a combining
758806
-- character, 1 for a regular character, 2 for an East Asian wide character.
759807
-- Ambiguous characters are treated as width 1.

0 commit comments

Comments
 (0)