]> gitweb.factorcode.org Git - factor.git/commitdiff
Fix tools.time output in the TTY listener
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 1 May 2009 01:03:52 +0000 (20:03 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 1 May 2009 01:03:52 +0000 (20:03 -0500)
basis/io/styles/styles.factor
basis/strings/tables/tables-tests.factor
basis/strings/tables/tables.factor
basis/tools/time/time.factor

index c3bf5d2f28c9d0b548db71d6ba9d062a1986b2d4..2d25016919cb6ee96971d368590d886593babc29 100644 (file)
@@ -99,7 +99,11 @@ M: plain-writer make-block-stream
     nip <ignore-close-stream> ;
 
 M: plain-writer stream-write-table
-    [ drop format-table [ nl ] [ write ] interleave ] with-output-stream* ;
+    [
+        drop
+        [ [ >string ] map ] map format-table
+        [ nl ] [ write ] interleave
+    ] with-output-stream* ;
 
 M: plain-writer make-cell-stream 2drop <string-writer> ;
 
index a77312897adab0975ca67d4705774ed0ce32fdb5..9429772f4a63fcae526b0d354f442d2bba6dc491 100644 (file)
@@ -2,3 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: tools.test strings.tables ;
 IN: strings.tables.tests
+
+[ { "A  BB" "CC D" } ] [ { { "A" "BB" } { "CC" "D" } } format-table ] unit-test
+
+[ { "A C" "B " "D E" } ] [ { { "A\nB" "C" } { "D" "E" } } format-table ] unit-test
\ No newline at end of file
index c6ccba5a785683983eda531de38fb654cd3a85c8..51032264c7ad4c50aafdf4f50e8b02afcd6334c1 100644 (file)
@@ -1,21 +1,30 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel sequences fry math.order ;
+USING: kernel sequences fry math.order splitting ;
 IN: strings.tables
 
 <PRIVATE
 
+: map-last ( seq quot -- seq )
+    [ dup length <reversed> ] dip '[ 0 = @ ] 2map ; inline
+
+: max-length ( seq -- n )
+    [ length ] [ max ] map-reduce ;
+
+: format-row ( seq ? -- seq )
+    [
+        dup max-length
+        '[ _ "" pad-tail ] map
+    ] unless ;
+
 : format-column ( seq ? -- seq )
     [
-        dup [ length ] [ max ] map-reduce
+        dup max-length
         '[ _ CHAR: \s pad-tail ] map
     ] unless ;
 
-: map-last ( seq quot -- seq )
-    [ dup length <reversed> ] dip '[ 0 = @ ] 2map ; inline
-
 PRIVATE>
 
 : format-table ( table -- seq )
-    flip [ format-column ] map-last
-    flip [ " " join ] map ;
\ No newline at end of file
+    [ [ [ string-lines ] map ] dip format-row flip ] map-last concat
+    flip [ format-column ] map-last flip [ " " join ] map ;
\ No newline at end of file
index 269581730b2eb4c0a288ba04213a2275ba824f1d..65e87f976fc349987bfa7dd090cece07aa7b2d13 100644 (file)
@@ -9,18 +9,19 @@ IN: tools.time
     micros [ call micros ] dip - ; inline
 
 : time. ( time -- )
-    "== Running time ==" print nl 1000000 /f pprint " seconds" write ;
+    "== Running time ==" print nl 1000000 /f pprint " seconds" print ;
 
 : gc-stats. ( stats -- )
     5 cut*
     "== Garbage collection ==" print nl
+    "Times are in microseconds." print nl
     [
         6 group
         {
             "GC count:"
-            "Cumulative GC time (us):"
-            "Longest GC pause (us):"
-            "Average GC pause (us):"
+            "Total GC time:"
+            "Longest GC pause:"
+            "Average GC pause:"
             "Objects copied:"
             "Bytes copied:"
         } prefix
@@ -31,10 +32,10 @@ IN: tools.time
     [
         nl
         {
-            "Total GC time (us):"
+            "Total GC time:"
             "Cards scanned:"
             "Decks scanned:"
-            "Card scan time (us):"
+            "Card scan time:"
             "Code heap literal scans:"
         } swap zip simple-table.
     ] bi* ;