Skip to content

Commit 949d42f

Browse files
committed
Add initial external API for colored docs
1 parent 625482f commit 949d42f

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
, (<+>)
@@ -757,6 +768,43 @@ italic = styled (RShape Italic)
757768
underlined :: HasChars a => Doc a -> Doc a
758769
underlined = styled (RUnderline ULSingle)
759770

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

0 commit comments

Comments
 (0)