0 | module NCurses.Core.Attribute
3 | import NCurses.Core.Color
7 | %foreign libncurses "wchgat"
8 | prim__changeAtWindow : AnyPtr -> Int -> Int -> Int -> AnyPtr -> PrimIO ()
10 | %foreign libncurses "mvchgat"
11 | prim__mvChangeAt : Int -> Int -> Int -> Int -> Int -> AnyPtr -> PrimIO ()
13 | %foreign libncurses "mvwchgat"
14 | prim__mvChangeAtWindow : AnyPtr -> Int -> Int -> Int -> Int -> Int -> AnyPtr -> PrimIO ()
16 | %foreign libncurses "attrset"
17 | prim__setAttr : Int -> PrimIO ()
19 | %foreign libncurses "wattrset"
20 | prim__setAttrWindow : AnyPtr -> Int -> PrimIO ()
22 | %foreign libncurses "attroff"
23 | prim__disableAttr : Int -> PrimIO ()
25 | %foreign libncurses "wattroff"
26 | prim__disableAttrWindow : AnyPtr -> Int -> PrimIO ()
28 | %foreign libncurses "attron"
29 | prim__enableAttr : Int -> PrimIO ()
31 | %foreign libncurses "wattron"
32 | prim__enableAttrWindow : AnyPtr -> Int -> PrimIO ()
34 | %foreign libhelper "normal_attr"
35 | prim__normalAttr : PrimIO Int
37 | %foreign libhelper "underline_attr"
38 | prim__underlineAttr : PrimIO Int
40 | %foreign libhelper "standout_attr"
41 | prim__standoutAttr : PrimIO Int
43 | %foreign libhelper "reverse_attr"
44 | prim__reverseAttr : PrimIO Int
46 | %foreign libhelper "blink_attr"
47 | prim__blinkAttr : PrimIO Int
49 | %foreign libhelper "dim_attr"
50 | prim__dimAttr : PrimIO Int
52 | %foreign libhelper "bold_attr"
53 | prim__boldAttr : PrimIO Int
55 | %foreign libhelper "protected_attr"
56 | prim__protectedAttr : PrimIO Int
58 | %foreign libhelper "invisible_attr"
59 | prim__invisibleAttr : PrimIO Int
61 | %foreign libhelper "color_pair_attr"
62 | prim__colorPairAttr : Int -> PrimIO Int
64 | %foreign libncurses "bkgd"
65 | prim__setBackground : Int -> PrimIO ()
67 | %foreign libncurses "wbkgd"
68 | prim__setBackgroundWindow : AnyPtr -> Int -> PrimIO ()
72 | data Attribute = Normal
85 | Normal == Normal = True
86 | Underline == Underline = True
87 | Standout == Standout = True
88 | Reverse == Reverse = True
89 | Blink == Blink = True
92 | Protected == Protected = True
93 | Invisible == Invisible = True
94 | (CP c1) == (CP c2) = c1 == c2
98 | Show Attribute where
99 | show Normal = "Normal"
100 | show Underline = "Underline"
101 | show Standout = "Standout"
102 | show Reverse = "Reverse"
103 | show Blink = "Blink"
106 | show Protected = "Protected"
107 | show Invisible = "Invisible"
108 | show (CP c) = "Color (\{show c})"
112 | getAttribute : HasIO io => Attribute -> io Int
113 | getAttribute attr = case attr of
114 | Normal => primIO $
prim__normalAttr
115 | Underline => primIO $
prim__underlineAttr
116 | Standout => primIO $
prim__standoutAttr
117 | Reverse => primIO $
prim__reverseAttr
118 | Blink => primIO $
prim__blinkAttr
119 | Dim => primIO $
prim__dimAttr
120 | Bold => primIO $
prim__boldAttr
121 | Protected => primIO $
prim__protectedAttr
122 | Invisible => primIO $
prim__invisibleAttr
123 | (CP cp) => primIO $
prim__colorPairAttr (cast cp.idx)
133 | nSetAttr : HasIO io => Attribute -> io ()
134 | nSetAttr attr = do attribute <- getAttribute attr
135 | primIO $
prim__setAttr attribute
142 | nSetAttr' : HasIO io => Window -> Attribute -> io ()
143 | nSetAttr' (Win win) attr = do attribute <- getAttribute attr
144 | primIO $
prim__setAttrWindow win attribute
155 | nEnableAttr : HasIO io => Attribute -> io ()
156 | nEnableAttr attr = do attribute <- getAttribute attr
157 | primIO $
prim__enableAttr attribute
165 | nEnableAttr' : HasIO io => Window -> Attribute -> io ()
166 | nEnableAttr' (Win win) attr = do attribute <- getAttribute attr
167 | primIO $
prim__enableAttrWindow win attribute
178 | nDisableAttr : HasIO io => Attribute -> io ()
179 | nDisableAttr attr = do attribute <- getAttribute attr
180 | primIO $
prim__disableAttr attribute
188 | nDisableAttr' : HasIO io => Window -> Attribute -> io ()
189 | nDisableAttr' (Win win) attr = do attribute <- getAttribute attr
190 | primIO $
prim__disableAttrWindow win attribute
198 | nChangeAttrAt : HasIO io
201 | -> (len : Maybe Nat)
205 | nChangeAttrAt row col len attr cp =
206 | let length = the Int (maybe (-
1) cast len)
208 | do attribute <- getAttribute attr
210 | prim__mvChangeAt (cast row) (cast col) length attribute (cast cp.idx) prim__getNullAnyPtr
216 | nChangeAttr' : HasIO io
218 | -> (len : Maybe Nat)
222 | nChangeAttr' (Win win) len attr cp =
223 | let length = the Int (maybe (-
1) cast len)
225 | do attribute <- getAttribute attr
227 | prim__changeAtWindow win length attribute (cast cp.idx) prim__getNullAnyPtr
233 | nChangeAttrAt' : HasIO io
237 | -> (len : Maybe Nat)
241 | nChangeAttrAt' (Win win) row col len attr cp =
242 | let length = the Int (maybe (-
1) cast len)
244 | do attribute <- getAttribute attr
246 | prim__mvChangeAtWindow win (cast row) (cast col) length attribute (cast cp.idx) prim__getNullAnyPtr
250 | setBackground : HasIO io => ColorPair -> io ()
251 | setBackground cp = do
252 | cp <- primIO $
prim__colorPairAttr (cast cp.idx)
253 | primIO $
prim__setBackground cp
257 | setBackground' : HasIO io => Window -> ColorPair -> io ()
258 | setBackground' (Win win) cp = do
259 | cp <- primIO $
prim__colorPairAttr (cast cp.idx)
260 | primIO $
prim__setBackgroundWindow win cp