 : (wgetch) ( window -- key )
     ffi:wgetch [ curses-error ] keep ; inline
 
+: (wattroff) ( attribute window-ptr -- )
+    swap ffi:wattroff curses-error ; inline
+
+: (wattron) ( attribute window-ptr -- )
+    swap ffi:wattron curses-error ; inline
+
 PRIVATE>
 
 : wcrefresh ( window -- ) ptr>> (wcrefresh) ;
 : crefresh ( -- ) current-window get wcrefresh ;
 
+: wcnl ( window -- ) [ "\n" ] dip ptr>> (wcwrite) ;
+: cnl ( -- ) current-window get wcnl ;
+
 : wcwrite ( string window -- ) ptr>> (wcwrite) ;
 : cwrite ( string -- ) current-window get wcwrite ;
-
-: wcnl ( window -- ) [ "\n" ] dip ptr>> (wcwrite) ;
-: cnl ( -- ) current-window get wcnl ;
 
 : wcprint ( string window -- )
     ptr>> [ (wcwrite) ] [ "\n" swap (wcwrite) ] bi ;

: insert-line ( string y -- )
    current-window get winsert-line ;

: wccolor ( foreground background window -- )
    [
        2dup [ COLOR_WHITE = ] [ COLOR_BLACK = ] bi* and
        [ 2drop 0 ] [ register-color ] if ffi:COLOR_PAIR
    ] dip ptr>> swap ffi:wattron curses-error ;

: ccolor ( foreground background -- )
    current-window get wccolor ;

: with-curses ( window quot -- )
    curses-ok? [ unsupported-curses-terminal ] unless
    [
        '[
            ffi:initscr curses-pointer-error
            >>ptr dup apply-options
            ffi:erase curses-error
            init-colors
            _ with-window
        ] [ ffi:endwin curses-error ] [ ] cleanup
    ] with-destructors ; inline

TUPLE: curses-terminal < disposable
