         init-terminal
         ffi:initscr curses-pointer-error drop
         dup ptr>> ffi:set_term curses-pointer-error drop
-    ] dip apply-options ;
+    ] dip [ apply-global-options ] [ apply-window-options ] bi ;
     
 <PRIVATE
 

        [ ffi:cbreak ] [ ffi:nocbreak ] if
    ] if curses-error ;

: apply-options ( window -- )
    {
        [ [ cbreak>> ] [ raw>> ] bi set-cbreak/raw ]
        [ 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


    [
        '[
            ffi:initscr curses-pointer-error
            >>ptr
            [ apply-global-options ] [ apply-window-options ] [ ] tri

            ffi:erase curses-error
            init-colors

            _ with-window
        ] [ ffi:endwin curses-error ] [ ] cleanup
    ] with-destructors ; inline
