0 | module Text.PrettyPrint.Prettyprinter.Render.NCurses
2 | import Control.Monad.State
5 | import NCurses.Core.Attribute
6 | import NCurses.Core.Color
7 | import Text.PrettyPrint.Prettyprinter.Doc
8 | import Text.PrettyPrint.Prettyprinter.Render.Terminal
13 | color : ColorPair -> Doc Attribute -> Doc Attribute
14 | color colorPair = annotate (CP colorPair)
17 | underline : Doc Attribute -> Doc Attribute
18 | underline = annotate Underline
21 | standout : Doc Attribute -> Doc Attribute
22 | standout = annotate Standout
25 | reverse : Doc Attribute -> Doc Attribute
26 | reverse = annotate Reverse
29 | blink : Doc Attribute -> Doc Attribute
30 | blink = annotate Blink
33 | dim : Doc Attribute -> Doc Attribute
37 | bold : Doc Attribute -> Doc Attribute
38 | bold = annotate Bold
41 | protected : Doc Attribute -> Doc Attribute
42 | protected = annotate Protected
45 | invisible : Doc Attribute -> Doc Attribute
46 | invisible = annotate Invisible
53 | toANSI : Attribute -> AnsiStyle
54 | toANSI Normal = [Reset]
55 | toANSI Underline = [SetStyle SingleUnderline]
56 | toANSI Standout = [SetStyle DoubleUnderline]
58 | toANSI Blink = [SetBlink Slow]
59 | toANSI Dim = [SetStyle Faint]
60 | toANSI Bold = [SetStyle Bold]
61 | toANSI Protected = []
62 | toANSI Invisible = []
63 | toANSI (CP colorPair) = [ SetForeground (toSgr colorPair.foreground)
64 | , SetBackground (toSgr colorPair.background)
67 | toSgr : Color.Color -> SGR.Color
71 | toSgr Yellow = Yellow
73 | toSgr Magenta = Magenta
78 | AttrState = StateT (List Attribute) IO ()
81 | renderNCurses : HasIO io => SimpleDocStream Attribute -> io ()
82 | renderNCurses = liftIO . evalStateT [] . go
84 | go : SimpleDocStream Attribute -> AttrState
86 | go (SChar ch rest) = lift (nPutCh ch) *> go rest
87 | go (SText _ text rest) = lift (nPutStr text) *> go rest
88 | go (SLine i rest) = do
90 | lift $
nMoveCursor (S y) (cast i)
92 | go (SAnnPop rest) = do
93 | (last :: attrs) <- get
95 | lift $
nDisableAttr last
98 | go (SAnnPush attr rest) = do
99 | lift $
nEnableAttr attr