2 | libncurses : String -> String
3 | libncurses fn = "C:" ++ fn ++ ",libncurses,ncurses.h"
5 | libhelper : String -> String
6 | libhelper fn = "C:" ++ fn ++ ",libncurses-idris,curses-helpers.h"
8 | %foreign libhelper "ncurses_err"
9 | prim__err : PrimIO Int
11 | %foreign libhelper "std_win"
12 | prim__stdWindow : PrimIO AnyPtr
14 | %foreign libncurses "newwin"
15 | prim__newWindow : Int -> Int -> Int -> Int -> PrimIO AnyPtr
18 | %foreign libncurses "delwin"
19 | prim__deleteWindow : AnyPtr -> PrimIO Int
22 | %foreign libncurses "mvwin"
23 | prim__moveWindow : AnyPtr -> Int -> Int -> PrimIO Int
26 | %foreign libncurses "wresize"
27 | prim__resizeWindow : AnyPtr -> Int -> Int -> PrimIO Int
29 | %foreign libncurses "getmaxx"
30 | prim__maxXWindow : AnyPtr -> PrimIO Int
32 | %foreign libncurses "getmaxy"
33 | prim__maxYWindow : AnyPtr -> PrimIO Int
35 | %foreign libncurses "getcury"
36 | prim__getYWindow : AnyPtr -> PrimIO Int
38 | %foreign libncurses "getcurx"
39 | prim__getXWindow : AnyPtr -> PrimIO Int
41 | %foreign libncurses "getbegy"
42 | prim__begYWindow : AnyPtr -> PrimIO Int
44 | %foreign libncurses "getbegx"
45 | prim__begXWindow : AnyPtr -> PrimIO Int
47 | %foreign libncurses "refresh"
48 | prim__refresh : PrimIO ()
50 | %foreign libncurses "wrefresh"
51 | prim__refreshWindow : AnyPtr -> PrimIO ()
53 | %foreign libncurses "clear"
54 | prim__clear : PrimIO ()
56 | %foreign libncurses "wclear"
57 | prim__clearWindow : AnyPtr -> PrimIO ()
59 | %foreign libncurses "erase"
60 | prim__erase : PrimIO ()
62 | %foreign libncurses "werase"
63 | prim__eraseWindow : AnyPtr -> PrimIO ()
65 | %foreign libhelper "print"
66 | prim__print : String -> String -> PrimIO ()
68 | %foreign libhelper "printWindow"
69 | prim__printWindow : AnyPtr -> String -> String -> PrimIO ()
71 | %foreign libncurses "addch"
72 | prim__addChar : Char -> PrimIO ()
74 | %foreign libncurses "waddch"
75 | prim__addCharWindow : AnyPtr -> Char -> PrimIO ()
85 | %foreign libhelper "mvPrint"
86 | prim__mvPrint : Int -> Int -> String -> String -> PrimIO ()
88 | %foreign libhelper "mvPrintWindow"
89 | prim__mvPrintWindow : AnyPtr -> Int -> Int -> String -> String -> PrimIO ()
91 | %foreign libncurses "vline"
92 | prim__verticalLine : Char -> Int -> PrimIO ()
94 | %foreign libncurses "wvline"
95 | prim__verticalLineWindow : AnyPtr -> Char -> Int -> PrimIO ()
97 | %foreign libncurses "hline"
98 | prim__horizontalLine : Char -> Int -> PrimIO ()
100 | %foreign libncurses "whline"
101 | prim__horizontalLineWindow : AnyPtr -> Char -> Int -> PrimIO ()
106 | %foreign libncurses "wborder"
107 | prim__borderWindow : AnyPtr
108 | -> (l : Char) -> (r : Char) -> (t : Char) -> (b : Char)
109 | -> (tl : Char) -> (tr : Char) -> (bl : Char) -> (br : Char)
112 | %foreign libncurses "move"
113 | prim__move : Int -> Int -> PrimIO ()
115 | %foreign libncurses "wmove"
116 | prim__moveInWindow : AnyPtr -> Int -> Int -> PrimIO ()
118 | %foreign libncurses "initscr"
119 | prim__initScr : PrimIO ()
121 | %foreign libncurses "endwin"
122 | prim__endWin : PrimIO ()
124 | boolToInt : Bool -> Int
125 | boolToInt False = 0
138 | data Window = Win AnyPtr
142 | stdWindow : HasIO io => io Window
143 | stdWindow = Win <$> (primIO $
prim__stdWindow)
147 | newWindow : HasIO io => (height : Nat) -> (width : Nat) -> (y : Nat) -> (x : Nat) -> io Window
148 | newWindow height width y x = Win <$> (primIO $
prim__newWindow (cast height) (cast width) (cast y) (cast x))
154 | deleteWindow : HasIO io => Window -> io Bool
155 | deleteWindow (Win win) = do
156 | err <- primIO $
prim__err
157 | res <- primIO $
prim__deleteWindow win
167 | moveWindow : HasIO io => Window -> (y : Nat) -> (x : Nat) -> io Bool
168 | moveWindow (Win win) y x = do
169 | err <- primIO $
prim__err
170 | res <- primIO $
prim__moveWindow win (cast y) (cast x)
178 | getWindowPos' : HasIO io => Window -> io (Nat, Nat)
179 | getWindowPos' (Win win) = do y <- (primIO $
prim__begYWindow win)
180 | x <- (primIO $
prim__begXWindow win)
181 | pure (fromInteger (cast y), fromInteger (cast x))
187 | setWindowSize : HasIO io => Window -> (rows : Nat) -> (cols : Nat) -> io Bool
188 | setWindowSize (Win win) rows cols = do
189 | err <- primIO $
prim__err
190 | res <- primIO $
prim__resizeWindow win (cast rows) (cast cols)
198 | getMaxSize' : HasIO io => Window -> io (Nat, Nat)
199 | getMaxSize' (Win win) = do y <- (primIO $
prim__maxYWindow win)
200 | x <- (primIO $
prim__maxXWindow win)
201 | pure (fromInteger (cast y), fromInteger (cast x))
204 | getYPos' : HasIO io => Window -> io Nat
205 | getYPos' (Win win) = map cast . primIO $
prim__getYWindow win
208 | getYPos : HasIO io => io Nat
209 | getYPos = getYPos' !stdWindow
212 | getXPos' : HasIO io => Window -> io Nat
213 | getXPos' (Win win) = map cast . primIO $
prim__getXWindow win
216 | getXPos : HasIO io => io Nat
217 | getXPos = getXPos' !stdWindow
223 | refresh : HasIO io => io ()
224 | refresh = primIO $
prim__refresh
228 | refresh' : HasIO io => Window -> io ()
229 | refresh' (Win win) = primIO $
prim__refreshWindow win
245 | clear : HasIO io => io ()
246 | clear = primIO $
prim__clear
260 | clear' : HasIO io => Window -> io ()
261 | clear' (Win win) = primIO $
prim__clearWindow win
267 | erase : HasIO io => io ()
268 | erase = primIO $
prim__erase
272 | erase' : HasIO io => Window -> io ()
273 | erase' (Win win) = primIO $
prim__eraseWindow win
276 | nPutCh : HasIO io => Char -> io ()
277 | nPutCh ch = primIO $
prim__addChar ch
280 | nPutCh' : HasIO io => Window -> Char -> io ()
281 | nPutCh' (Win win) ch = primIO $
prim__addCharWindow win ch
284 | nPutStr : HasIO io => String -> io ()
285 | nPutStr str = primIO $
prim__print "%s" str
288 | nPutStr' : HasIO io => Window -> String -> io ()
289 | nPutStr' (Win win) str = primIO $
prim__printWindow win "%s" str
292 | nPutStrLn : HasIO io => String -> io ()
293 | nPutStrLn str = primIO $
prim__print "%s\n" str
296 | nPutStrLn' : HasIO io => Window -> String -> io ()
297 | nPutStrLn' (Win win) str = primIO $
prim__printWindow win "%s\n" str
303 | nPutStrAt : HasIO io => (row : Nat) -> String -> io ()
304 | nPutStrAt row str = primIO $
prim__mvPrint (cast row) 0 "%s" str
308 | nPutStrAt' : HasIO io => Window -> (row : Nat) -> String -> io ()
309 | nPutStrAt' (Win win) row str = primIO $
prim__mvPrintWindow win (cast row) 0 "%s" str
313 | nVerticalLine : HasIO io => Char -> Nat -> io ()
314 | nVerticalLine ch n = primIO $
prim__verticalLine ch (cast n)
319 | nVerticalLine' : HasIO io => Window -> Char -> Nat -> io ()
320 | nVerticalLine' (Win win) ch n = primIO $
prim__verticalLineWindow win ch (cast n)
324 | nHorizontalLine : HasIO io => Char -> Nat -> io ()
325 | nHorizontalLine ch n = primIO $
prim__horizontalLine ch (cast n)
330 | nHorizontalLine' : HasIO io => Window -> Char -> Nat -> io ()
331 | nHorizontalLine' (Win win) ch n = primIO $
prim__horizontalLineWindow win ch (cast n)
336 | data BorderChar = Custom Char | Default
347 | nWindowBorder : HasIO io =>
349 | -> (left : BorderChar)
350 | -> (right : BorderChar)
351 | -> (top : BorderChar)
352 | -> (bottom : BorderChar)
353 | -> (topLeft : BorderChar)
354 | -> (topRight : BorderChar)
355 | -> (bottomLeft : BorderChar)
356 | -> (bottomRight : BorderChar)
358 | nWindowBorder (Win win) left right top bottom topLeft topRight bottomLeft bottomRight =
359 | primIO $
prim__borderWindow win (b left) (b right) (b top) (b bottom)
360 | (b topLeft) (b topRight) (b bottomLeft) (b bottomRight)
362 | b : BorderChar -> Char
364 | b Default = (cast 0)
370 | nDefaultWindowBorder : HasIO io => Window -> io ()
371 | nDefaultWindowBorder win = nWindowBorder win Default Default Default Default
372 | Default Default Default Default
376 | nMoveCursor : HasIO io => (row : Nat) -> (col : Nat) -> io ()
377 | nMoveCursor row col = primIO $
prim__move (cast row) (cast col)
381 | nMoveCursor' : HasIO io => Window -> (row : Nat) -> (col : Nat) -> io ()
382 | nMoveCursor' (Win win) row col = primIO $
prim__moveInWindow win (cast row) (cast col)
392 | initNCurses : HasIO io => io ()
393 | initNCurses = primIO $
prim__initScr
398 | deinitNCurses : HasIO io => io ()
399 | deinitNCurses = primIO $
prim__endWin