]> gitweb.factorcode.org Git - factor.git/commitdiff
Check if we're using ttys before starting curses, since initscr exits on error for...
authorDoug Coleman <doug.coleman@gmail.com>
Mon, 22 Feb 2010 05:37:33 +0000 (23:37 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 22 Feb 2010 05:38:18 +0000 (23:38 -0600)
basis/unix/ffi/ffi.factor
extra/curses/curses-tests.factor
extra/curses/curses.factor

index 3882f6fc809c4d7ac79a84c6f30ffa4e9cfec69e..10346cff2cd7b1ff1100e561629fc7ab95fda9a6 100644 (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 ) ;
index 21463b207bf7e0e0adb23a41a8bacf6516ce8e9e..bd98a7aff1a2da06cf3b33248563aed62b3e9bd4 100644 (file)
@@ -14,5 +14,6 @@ IN: curses.tests
         2000000 sleep
     ] with-curses ;
 
-[
-] [ hello-curses ] unit-test
+curses-ok? [
+    [ ] [ hello-curses ] unit-test
+] when
index 69c6503aa282346657e3e6b760591b55ea658a37..dfb1b8672a0f1bc2a03266fd88b386a748151a66 100644 (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
         [