     { [ lines>> ] [ columns>> ] [ y>> ] [ x>> ] } cleave ;
 
 : set-cbreak/raw ( cbreak raw -- )
-    [ drop raw ] [
-        [ cbreak ] [ nocbreak ] if
+    [ drop ffi:raw ] [
+        [ ffi:cbreak ] [ ffi:nocbreak ] if
     ] if curses-error ;
 
 : apply-options ( window -- )
     {
         [ [ cbreak>> ] [ raw>> ] bi set-cbreak/raw ]
-        [ echo>> [ echo ] [ noecho ] if curses-error ]
-        [ [ ptr>> ] [ scrollok>> >BOOLEAN ] bi scrollok curses-error ]
-        [ [ ptr>> ] [ leaveok>> >BOOLEAN ] bi leaveok curses-error ]
-        [ [ ptr>> ] [ keypad>> >BOOLEAN ] bi keypad curses-error ]
+        [ echo>> [ ffi:echo ] [ ffi:noecho ] if curses-error ]
+        [ [ ptr>> ] [ scrollok>> >BOOLEAN ] bi ffi:scrollok curses-error ]
+        [ [ ptr>> ] [ leaveok>> >BOOLEAN ] bi ffi:leaveok curses-error ]
+        [ [ ptr>> ] [ keypad>> >BOOLEAN ] bi ffi:keypad curses-error ]
     } cleave ;
 
 SYMBOL: n-registered-colors
 
 MEMO: register-color ( fg bg -- n )
-    [ n-registered-colors get ] 2dip init_pair curses-error
+    [ n-registered-colors get ] 2dip ffi:init_pair curses-error
     n-registered-colors [ get ] [ inc ] bi ;
+
+: init-colors ( -- )
+    ffi:has_colors [
+        1 n-registered-colors set
+        \ register-color reset-memoized
+        ffi:start_color curses-error
+    ] when ;
 
 PRIVATE>
 

CONSTANT: COLOR_CYAN  6
CONSTANT: COLOR_WHITE 7

: >BOOLEAN ( ? -- TRUE/FALSE ) TRUE FALSE ? ; inline

ERROR: curses-failed ;
ERROR: unsupported-curses-terminal ;

: curses-error ( n -- ) ERR = [ curses-failed ] when ;

: curses-ok? ( -- ? )
    { 0 1 2 } [ isatty 0 = not ] all? ;

! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.strings assocs byte-arrays
classes.struct combinators continuations destructors
fry io io.encodings.8-bit io.encodings.string io.encodings.utf8
io.streams.c kernel libc locals math memoize multiline
namespaces prettyprint sequences strings threads ;
IN: curses

QUALIFIED-WITH: curses.ffi ffi

SYMBOL: current-window

