Check if we're using ttys before starting curses, since initscr exits on error for some dumb reason

db4
Doug Coleman 2010-02-21 23:37:33 -06:00
parent 708c752f66
commit 957f2d9ff6
3 changed files with 10 additions and 3 deletions

View File

@ -101,6 +101,7 @@ FUNCTION: uid_t getuid ;
FUNCTION: uint htonl ( uint n ) ;
FUNCTION: ushort htons ( ushort n ) ;
! FUNCTION: int issetugid ;
FUNCTION: int isatty ( int fildes ) ;
FUNCTION: int ioctl ( int fd, ulong request, char* argp ) ;
FUNCTION: int lchown ( char* path, uid_t owner, gid_t group ) ;
FUNCTION: int listen ( int s, int backlog ) ;

View File

@ -14,5 +14,6 @@ IN: curses.tests
2000000 sleep
] with-curses ;
[
] [ hello-curses ] unit-test
curses-ok? [
[ ] [ hello-curses ] unit-test
] when

View File

@ -4,7 +4,7 @@ USING: accessors alien.c-types alien.strings assocs byte-arrays
combinators continuations destructors fry io.encodings.8-bit
io io.encodings.string io.encodings.utf8 kernel locals math
namespaces prettyprint sequences classes.struct
strings threads curses.ffi ;
strings threads curses.ffi unix.ffi ;
IN: curses
SYMBOL: curses-windows
@ -19,6 +19,7 @@ ERROR: duplicate-window window ;
ERROR: unnamed-window window ;
ERROR: window-not-found window ;
ERROR: curses-failed ;
ERROR: unsupported-curses-terminal ;
: get-window ( string -- window )
dup curses-windows get at*
@ -28,7 +29,11 @@ ERROR: curses-failed ;
: curses-error ( n -- ) ERR = [ curses-failed ] when ;
: curses-ok? ( -- ? )
{ 0 1 2 } [ isatty 0 = not ] all? ;
: with-curses ( quot -- )
curses-ok? [ unsupported-curses-terminal ] unless
H{ } clone curses-windows [
initscr curses-error
[