0 | module NCurses.Core.Color
6 | %foreign libncurses "start_color"
7 | prim__startColor : PrimIO ()
9 | %foreign libncurses "init_pair"
10 | prim__initColorPair : Int -> Int -> Int -> PrimIO ()
12 | %foreign libhelper "black_color"
13 | prim__blackColor : PrimIO Int
15 | %foreign libhelper "red_color"
16 | prim__redColor : PrimIO Int
18 | %foreign libhelper "green_color"
19 | prim__greenColor : PrimIO Int
21 | %foreign libhelper "yellow_color"
22 | prim__yellowColor : PrimIO Int
24 | %foreign libhelper "blue_color"
25 | prim__blueColor : PrimIO Int
27 | %foreign libhelper "magenta_color"
28 | prim__magentaColor : PrimIO Int
30 | %foreign libhelper "cyan_color"
31 | prim__cyanColor : PrimIO Int
33 | %foreign libhelper "white_color"
34 | prim__whiteColor : PrimIO Int
50 | Black == Black = True
52 | Green == Green = True
53 | Yellow == Yellow = True
55 | Magenta == Magenta = True
57 | White == White = True
61 | show Black = "Black"
63 | show Green = "Green"
64 | show Yellow = "Yellow"
66 | show Magenta = "Magenta"
68 | show White = "White"
70 | getColor : HasIO io => Color -> io Int
71 | getColor color = case color of
72 | Black => primIO $
prim__blackColor
73 | Red => primIO $
prim__redColor
74 | Green => primIO $
prim__greenColor
75 | Yellow => primIO $
prim__yellowColor
76 | Blue => primIO $
prim__blueColor
77 | Magenta => primIO $
prim__magentaColor
78 | Cyan => primIO $
prim__cyanColor
79 | White => primIO $
prim__whiteColor
84 | data ColorPair = MkColorPair Nat Color Color
88 | (MkColorPair idx1 f1 b1) == (MkColorPair idx2 f2 b2) = idx1 == idx2 && f1 == f2 && b1 == b2
91 | Show ColorPair where
92 | show (MkColorPair idx foreground background) = "\{show idx}: \{show foreground}/\{show background}"
98 | (.idx) : ColorPair -> Nat
99 | (.idx) (MkColorPair n f b) = n
102 | (.foreground) : ColorPair -> Color
103 | (.foreground) (MkColorPair n f b) = f
106 | (.background) : ColorPair -> Color
107 | (.background) (MkColorPair n f b) = b
119 | defaultColorPair : ColorPair
120 | defaultColorPair = MkColorPair 0 White Black
131 | initColorPair : HasIO io => Nat -> (fg : Color) -> (bg : Color) -> io ColorPair
132 | initColorPair idx fg bg =
133 | do bgColor <- getColor bg
134 | fgColor <- getColor fg
135 | let actualIdx = (S idx)
136 | primIO $
prim__initColorPair (cast actualIdx) fgColor bgColor
137 | pure (MkColorPair actualIdx fg bg)
141 | startColor : HasIO io => io ()
142 | startColor = primIO $
prim__startColor