 : (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 ;

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

TUPLE: curses-terminal < disposable

CONSTANT: COLOR_CYAN  6
CONSTANT: COLOR_WHITE 7

CONSTANT: A_NORMAL      0
CONSTANT: A_ATTRIBUTES  -256
CONSTANT: A_CHARTEXT    255
CONSTANT: A_COLOR       65280
CONSTANT: A_STANDOUT    65536
CONSTANT: A_UNDERLINE   131072
CONSTANT: A_REVERSE     262144
CONSTANT: A_BLINK       524288
CONSTANT: A_DIM         1048576
CONSTANT: A_BOLD        2097152
CONSTANT: A_ALTCHARSET  4194304
CONSTANT: A_INVIS       8388608
CONSTANT: A_PROTECT     16777216
CONSTANT: A_HORIZONTAL  33554432
CONSTANT: A_LEFT        67108864
CONSTANT: A_LOW         134217728
CONSTANT: A_RIGHT       268435456
CONSTANT: A_TOP         536870912
CONSTANT: A_VERTICAL    1073741824

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

