]> gitweb.factorcode.org Git - factor.git/commitdiff
curses: fix colors, add unit test
authorPhilipp Brüschweiler <blei42@gmail.com>
Thu, 25 Feb 2010 10:48:44 +0000 (11:48 +0100)
committerPhilipp Brüschweiler <blei42@gmail.com>
Sun, 3 Oct 2010 11:16:31 +0000 (13:16 +0200)
extra/curses/curses-tests.factor
extra/curses/curses.factor
extra/curses/ffi/ffi.factor

index a56f067911bc0b2a64789e28e3c3ce02545be500..9ffd1916812fabdeb8aca716bcf138df32cdace3 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors calendar curses kernel threads tools.test
-strings sequences ;
+strings sequences random ;
 IN: curses.tests
 
 : hello-curses ( -- )
@@ -14,6 +14,16 @@ IN: curses.tests
         2 seconds sleep
     ] with-curses ;
 
+: hello-curses-color ( -- )
+    <curses-window> [
+        "Hello Curses!" [
+            8 random 8 random ccolor addch
+        ] each crefresh
+        
+        2 seconds sleep
+    ] with-curses ;
+
 curses-ok? [
     [ ] [ hello-curses ] unit-test
+    [ ] [ hello-curses-color ] unit-test
 ] when
index 3f4ad187497bfac48dc85df9a87733d7f53ca6d2..dce102b04e2b2e27d7f4fd3f4aae0010c693208f 100644 (file)
@@ -1,14 +1,14 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.strings assocs byte-arrays
-classes.struct combinators continuations destructors
-fry io io.encodings.8-bit io.encodings.string io.encodings.utf8
-io.streams.c kernel libc locals math memoize multiline
-namespaces prettyprint sequences strings threads ;
-IN: curses
+USING: accessors alien.c-types alien.strings classes.struct
+combinators continuations destructors fry io.encodings.utf8
+kernel libc locals math memoize multiline namespaces sequences
+unix.ffi ;
 
 QUALIFIED-WITH: curses.ffi ffi
 
+IN: curses
+
 SYMBOL: current-window
 
 CONSTANT: COLOR_BLACK 0
@@ -244,6 +244,7 @@ MEMO: register-color ( fg bg -- n )
         1 n-registered-colors set
         \ register-color reset-memoized
         ffi:start_color curses-error
+        ffi:stdscr 0 f ffi:wcolor_set curses-error
     ] when ;
 
 PRIVATE>
@@ -376,10 +377,7 @@ PRIVATE>
 : all-attroff ( -- ) current-window get wall-attroff ;
 
 : wccolor ( foreground background window -- )
-    [
-        2dup [ COLOR_WHITE = ] [ COLOR_BLACK = ] bi* and
-        [ 2drop 0 ] [ register-color ] if ffi:COLOR_PAIR
-    ] dip ptr>> (wattron) ;
+    [ register-color ] dip ptr>> swap f ffi:wcolor_set curses-error ;
 
 : ccolor ( foreground background -- )
     current-window get wccolor ;
index af231c2f1f3b873289c99321b50ecb18d9e0a32e..dffdb37e2dee9a3b357fa3eca870219f0eb465dc 100644 (file)
@@ -254,6 +254,8 @@ C-GLOBAL: int COLOR_PAIRS
 
 : COLOR_PAIR ( n -- n' ) 8 shift ; inline foldable
 
+FUNCTION: int wcolor_set ( WINDOW* win, short color_pair_number, void* opts ) ;
+
 FUNCTION: int wattron ( WINDOW* win, int attrs ) ;
 FUNCTION: int wattroff ( WINDOW* win, int attrs ) ;
 FUNCTION: int wattrset ( WINDOW* win, int attrs ) ;