2 | module Control.NCurses.Pretty
4 | import Text.PrettyPrint.Prettyprinter.Render.NCurses
5 | import Control.NCurses
7 | import Control.Monad.State
8 | import public Text.PrettyPrint.Prettyprinter.Doc
9 | import Control.Indexed
15 | color : (name : String) -> HasColor name s => Doc (Attribute s) -> Doc (Attribute s)
16 | color name = annotate (Color (Named name))
19 | defaultColor : Doc (Attribute s) -> Doc (Attribute s)
20 | defaultColor = annotate (Color DefaultColors)
23 | underline : Doc (Attribute s) -> Doc (Attribute s)
24 | underline = annotate Underline
27 | standout : Doc (Attribute s) -> Doc (Attribute s)
28 | standout = annotate Standout
31 | reverse : Doc (Attribute s) -> Doc (Attribute s)
32 | reverse = annotate Reverse
35 | blink : Doc (Attribute s) -> Doc (Attribute s)
36 | blink = annotate Blink
39 | dim : Doc (Attribute s) -> Doc (Attribute s)
43 | bold : Doc (Attribute s) -> Doc (Attribute s)
44 | bold = annotate Bold
47 | protected : Doc (Attribute s) -> Doc (Attribute s)
48 | protected = annotate Protected
51 | invisible : Doc (Attribute s) -> Doc (Attribute s)
52 | invisible = annotate Invisible
54 | record Const (s : CursesState) a where
56 | runConst : NCurses a s s
58 | Functor (Const s) where
59 | map f = C . map f . runConst
61 | Applicative (Const s) where
63 | (C x) <*> (C y) = C (x <<*>> y)
65 | Monad (Const s) where
66 | (C x) >>= f = C $
do
70 | Attrs : CursesState -> Type
71 | Attrs s = List (Attribute s)
73 | AttrState : CursesState -> Type
74 | AttrState s = StateT (Attrs s) (Const s) ()
77 | renderDoc : IsActive s => SimpleDocStream (Attribute s) -> NCurses () s s
78 | renderDoc = runConst . evalStateT [] . go
80 | go : SimpleDocStream (Attribute s) -> AttrState s
82 | go (SChar ch rest) = (lift $
C (putCh ch)) *> go rest
83 | go (SText _ text rest) = (lift $
C (putStr text)) *> go rest
84 | go (SLine i rest) = do
85 | (MkPosition row col) <- lift $
C getPos
86 | lift . C $
move (MkPosition (S row) (cast i))
88 | go (SAnnPop rest) = do
89 | (last :: attrs) <- get
91 | lift . C $
disableAttr last
94 | go (SAnnPush attr rest) = do
95 | lift . C $
enableAttr attr
100 | printDoc : IsActive s => {default defaultLayoutOptions layoutOptions : LayoutOptions} -> Doc (Attribute s) -> NCurses () s s
101 | printDoc {layoutOptions} = renderDoc . layoutPretty layoutOptions