     [
         '[
             ffi:initscr curses-pointer-error
-            >>ptr dup apply-options
+            >>ptr
+            [ apply-global-options ] [ apply-window-options ] [ ] tri
+
             ffi:erase curses-error
             init-colors
+
             _ with-window
         ] [ ffi:endwin curses-error ] [ ] cleanup
     ] with-destructors ; inline

        ] [
            window-params ffi:newwin
        ] if* [ curses-error ] keep >>ptr &dispose
    ] [ apply-options ] bi ;

: with-window ( window quot -- )
    [ current-window ] dip with-variable ; inline

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

: apply-window-options ( window -- )
    {
        [ [ 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 ;

: apply-global-options ( window -- )
    [ [ cbreak>> ] [ raw>> ] bi set-cbreak/raw ]
    [ echo>> [ ffi:echo ] [ ffi:noecho ] if curses-error ]
    bi ;

SYMBOL: n-registered-colors

