]> gitweb.factorcode.org Git - factor.git/commitdiff
markup cleanups, removed terpri*, help responder and browser responder improvements
authorSlava Pestov <slava@factorcode.org>
Sat, 21 Jan 2006 07:37:39 +0000 (07:37 +0000)
committerSlava Pestov <slava@factorcode.org>
Sat, 21 Jan 2006 07:37:39 +0000 (07:37 +0000)
24 files changed:
contrib/httpd/browser-responder.factor
contrib/httpd/html-tags.factor
contrib/httpd/html.factor
contrib/httpd/http-client.factor
contrib/httpd/xml.factor
doc/handbook/streams.facts
library/help/help.factor
library/help/markup.factor
library/help/stylesheet.factor
library/io/duplex-stream.factor
library/io/null-stream.factor
library/io/plain-stream.factor
library/io/stdio.factor
library/io/stdio.facts
library/io/stream.factor
library/io/stream.facts
library/io/string-streams.factor
library/io/styles.factor
library/io/styles.facts
library/tools/describe.factor
library/ui/panes.factor
library/ui/paragraphs.factor
library/ui/presentations.factor
library/win32/win32-stream.factor

index d3fc96ba5d8ec79d51a1cd58003d2615d7381399..f0e75bfca992bd4b6b310f7bb5913d84f559f27d 100644 (file)
@@ -4,11 +4,11 @@
 ! modification, are permitted provided that the following conditions are met:
 ! 
 ! 1. Redistributions of source code must retain the above copyright notice,
-!    this list of conditions and the following disclaimer.
+!        this list of conditions and the following disclaimer.
 ! 
 ! 2. Redistributions in binary form must reproduce the above copyright notice,
-!    this list of conditions and the following disclaimer in the documentation
-!    and/or other materials provided with the distribution.
+!        this list of conditions and the following disclaimer in the documentation
+!        and/or other materials provided with the distribution.
 ! 
 ! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 ! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
@@ -29,81 +29,63 @@ USING: cont-responder hashtables help html io kernel lists
 memory namespaces prettyprint sequences words xml ;
 
 : option ( current text -- )
-  #! Output the HTML option tag for the given text. If
-  #! it is equal to the current string, make the option selected.
-  2dup = [
-    "<option selected>" write
-  ] [
-    "<option>" write
-  ] if      
-  chars>entities write 
-  "</option>\n" write drop ;
+    #! Output the HTML option tag for the given text. If
+    #! it is equal to the current string, make the option selected.
+    2dup = [
+        "<option selected>" write
+    ] [
+        "<option>" write
+    ] if            
+    chars>entities write 
+    "</option>\n" write drop ;
 
 : vocab-list ( vocab -- )
-  #! Write out the HTML for the list of vocabularies. Make the currently 
-  #! selected vocab be 'vocab'.
-  <select "vocab" =name "width: 200" =style "20" =size "document.forms.main.submit()" =onchange select> 
-    vocabs [ over swap option ] each drop
-  </select> ;
+    #! Write out the HTML for the list of vocabularies. Make the currently 
+    #! selected vocab be 'vocab'.
+    <select "vocab" =name "width: 200" =style "20" =size "document.forms.main.submit()" =onchange select> 
+        vocabs [ over swap option ] each drop
+    </select> ;
 
 : word-list ( vocab word -- )
-  #! Write out the HTML for the list of words in a vocabulary. Make the 'word' item
-  #! the currently selected option.
-  <select "word" =name "width: 200" =style "20" =size "document.forms.main.submit()" =onchange select> 
-    swap words natural-sort
-    [ word-name over swap option ] each drop
-  </select> ;
+    #! Write out the HTML for the list of words in a vocabulary. Make the 'word' item
+    #! the currently selected option.
+    <select "word" =name "width: 200" =style "20" =size "document.forms.main.submit()" =onchange select> 
+        swap words natural-sort
+        [ word-name over swap option ] each drop
+    </select> ;
 
 : word-source ( vocab word -- )
-  #! Write the source for the given word from the vocab as HTML.
-  swap lookup [ [ help ] with-html-stream ] when* ;
+    #! Write the source for the given word from the vocab as HTML.
+    swap lookup [ [ (help) ] with-html-stream ] when* ;
 
 : browser-body ( vocab word -- )
-  #! Write out the HTML for the body of the main browser page.
-  <table "100%" =width table> 
-    <tr>  
-      <td> <b> "Vocabularies" write </b> </td>
-      <td> <b> "Words" write </b> </td>
-      <td> <b> "Documentation" write </b> </td>
-    </tr>
-    <tr>  
-      <td "top" =valign "width: 200" =style td> over vocab-list </td> 
-      <td "top" =valign "width: 200" =style td> 2dup word-list </td> 
-      <td "top" =valign td> word-source </td> 
-    </tr>
-  </table> ;
+    #! Write out the HTML for the body of the main browser page.
+    <table "100%" =width table> 
+        <tr>
+            <td> <b> "Vocabularies" write </b> </td>
+            <td> <b> "Words" write </b> </td>
+            <td> <b> "Documentation" write </b> </td>
+        </tr>
+        <tr>    
+            <td "top" =valign "width: 200" =style td> over vocab-list </td> 
+            <td "top" =valign "width: 200" =style td> 2dup word-list </td> 
+            <td "top" =valign td> word-source </td> 
+        </tr>
+    </table> ;
 
 : browser-title ( vocab word -- )
-  #! Output the HTML title for the browser.
-  <title> 
-    "Factor Browser - " write 
-    swap write
-    " - " write
-    write
-  </title> ;
-
-: browser-style ( -- )
-  #! Stylesheet for browser pages
-  <style>
-    "A:link { text-decoration:none}\n" write
-    "A:visited { text-decoration:none}\n" write
-    "A:active { text-decoration:none}\n" write
-    "A:hover, A.nav:hover { border: 1px solid black; text-decoration: none; margin: 0px }\n" write
-    "A { margin: 1px }" write
-  </style> ;
+    #! Output the HTML title for the browser.
+    [ "Factor Browser - " % swap % " - " % % ] "" make ;
 
 : browse ( vocab word -- )
-  #! Display a Smalltalk like browser for exploring words.
-  [
-    <html> 
-      <head> 2dup browser-title browser-style </head>
-      <body> 
-        <form "main" =name "" =action "get" =method form> browser-body </form>
-      </body>
-    </html> 
-  ] show-final ;
+    #! Display a Smalltalk like browser for exploring words.
+    [
+        2dup browser-title [
+            <form "main" =name "" =action "get" =method form> browser-body </form>
+        ] html-document
+    ] show-final ;
 
 : browser-responder ( -- )
-  #! Start the Smalltalk-like browser.
-  "vocab" "query" get hash [ "browser-responder" ] unless*
-  "word" "query" get hash [ "browse" ] unless* browse ;
+    #! Start the Smalltalk-like browser.
+    "vocab" "query" get hash [ "browser-responder" ] unless*
+    "word" "query" get hash [ "browse" ] unless* browse ;
index c7d1bffd2b271d574e25af937b411dbada90867d..60dd90c9050a4c76678fe2f6608634d94453cf23 100644 (file)
@@ -72,6 +72,10 @@ USE: sequences
 !
 ! <input "text" =type "name" =name "20" =size input/>
 
+SYMBOL: html
+
+: write-html H{ { html t } } format ;
+
 : attrs>string ( alist -- string )
     #! Convert the attrs alist to a string
     #! suitable for embedding in an html tag.
@@ -81,7 +85,7 @@ USE: sequences
     #! With the attribute namespace on the stack, get the attributes
     #! and write them to standard output. If no attributes exist, write
     #! nothing.
-    "attrs" get attrs>string write ;
+    "attrs" get attrs>string write-html ;
 
 : html-word ( name def -- )
     #! Define 'word creating' word to allow
@@ -90,7 +94,7 @@ USE: sequences
  
 : <foo> "<" swap ">" append3 ;
 
-: do-<foo> <foo> write ;
+: do-<foo> <foo> write-html ;
 
 : def-for-html-word-<foo> ( name -- )
     #! Return the name and code for the <foo> patterned
@@ -99,7 +103,7 @@ USE: sequences
 
 : <foo "<" swap append ;
 
-: do-<foo write H{ } clone >n V{ } clone "attrs" set ;
+: do-<foo write-html H{ } clone >n V{ } clone "attrs" set ;
 
 : def-for-html-word-<foo ( name -- )
     #! Return the name and code for the <foo patterned
@@ -108,7 +112,7 @@ USE: sequences
 
 : foo> ">" append ;
 
-: do-foo> write-attributes n> drop ">" write ;
+: do-foo> write-attributes n> drop ">" write-html ;
 
 : def-for-html-word-foo> ( name -- )
     #! Return the name and code for the foo> patterned
@@ -120,7 +124,7 @@ USE: sequences
 : def-for-html-word-</foo> ( name -- )
     #! Return the name and code for the </foo> patterned
     #! word.    
-    </foo> dup [ write ] cons html-word define-close ;
+    </foo> dup [ write-html ] cons html-word define-close ;
 
 : <foo/> [ "<" % % "/>" % ] "" make ;
 
index 330bcbf3c98bbccb9127e54163a6aa5bd6956054..7700ef0ccad854d63141ccac3253ff34e36286dd 100644 (file)
@@ -1,15 +1,18 @@
-! Copyright (C) 2004, 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
+! Copyright (C) 2004, 2006 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
 IN: html
 USING: generic hashtables help http io kernel lists math
 namespaces sequences strings styles words xml ;
 
 : hex-color, ( triplet -- )
-    3 swap head [ 255 * >fixnum >hex 2 CHAR: 0 pad-left % ] each ;
+    3 swap head
+    [ 255 * >fixnum >hex 2 CHAR: 0 pad-left % ] each ;
 
-: fg-css, ( color -- ) "color: #" % hex-color, "; " % ;
+: fg-css, ( color -- )
+    "color: #" % hex-color, "; " % ;
 
-: bg-css, ( color -- ) "background-color: #" % hex-color, "; " % ;
+: bg-css, ( color -- )
+    "background-color: #" % hex-color, "; " % ;
 
 : style-css, ( flag -- )
     dup
@@ -53,15 +56,12 @@ namespaces sequences strings styles words xml ;
     ] if ;
 
 : div-css-style ( style -- str )
-    drop "" ;
-    ! [
-    !     H{
-    !         { foreground  [ fg-css,        ] }
-    !         { font        [ font-css,      ] }
-    !         { font-style  [ style-css,     ] }
-    !         { font-size   [ size-css,      ] }
-    !     } hash-apply
-    ! ] "" make ;
+    [
+        H{
+            { page-color   [ bg-css,        ] }
+            ! { border-color [ font-css,      ] }
+        } hash-apply
+    ] "" make ;
 
 : div-tag ( style quot -- )
     over div-css-style dup empty? [
@@ -87,6 +87,9 @@ namespaces sequences strings styles words xml ;
         call
     ] if* ;
 
+: do-escaping ( string style -- string )
+    html swap hash [ chars>entities ] unless ;
+
 GENERIC: browser-link-href ( presented -- href )
 
 M: word browser-link-href
@@ -111,16 +114,6 @@ M: object browser-link-href
     presented pick hash browser-link-href
     [ <a =href a> call </a> ] [ call ] if* ;
 
-TUPLE: wrapper-stream scope ;
-
-C: wrapper-stream ( stream -- stream )
-    2dup set-delegate [
-        >r stdio associate r> set-wrapper-stream-scope
-    ] keep ;
-
-: with-wrapper ( stream quot -- )
-    >r wrapper-stream-scope r> bind ; inline
-
 TUPLE: nested-stream ;
 
 C: nested-stream [ set-delegate ] keep ;
@@ -129,62 +122,62 @@ M: nested-stream stream-close drop ;
 
 TUPLE: html-stream ;
 
+C: html-stream ( stream -- stream ) [ set-delegate ] keep ;
+
 M: html-stream stream-write1 ( char stream -- )
     >r ch>string r> stream-write ;
 
-M: html-stream stream-write ( char stream -- )
-    [ chars>entities write ] with-wrapper ;
+: delegate-write delegate stream-write ;
+
+M: html-stream stream-write ( str stream -- )
+    >r chars>entities r> delegate-write ;
 
 M: html-stream stream-format ( str style stream -- )
     [
         [
             [
-                [ drop chars>entities write ] span-tag
+                [
+                    do-escaping stdio get delegate-write
+                ] span-tag
             ] file-link-tag
         ] browser-link-tag
-    ] with-wrapper ;
+    ] with-stream* ;
 
-: pre-tag ( stream style quot -- )
+: pre-tag ( style quot -- )
     wrap-margin rot hash [
         call
     ] [
-        over [ [ <pre> ] with-wrapper call ] keep
-        [ </pre> ] with-wrapper
+        <pre> call </pre>
     ] if ;
 
 M: html-stream with-nested-stream ( quot style stream -- )
-    swap [
-        [ <nested-stream> swap with-stream ] pre-tag
-    ] div-tag ;
-
-M: html-stream stream-terpri [ <br/> ] with-wrapper ;
-
-M: html-stream stream-terpri* [ <br/> ] with-wrapper ;
-
-C: html-stream ( stream -- stream )
-    #! Wraps the given stream in an HTML stream. An HTML stream
-    #! converts special characters to entities when being
-    #! written, and supports writing attributed strings with
-    #! the following attributes:
-    #!
-    #! foreground - an rgb triplet in a list
-    #! background - an rgb triplet in a list
-    #! font
-    #! font-style
-    #! font-size
-    #! file
-    #! word
-    #! vocab
-    [ >r <wrapper-stream> r> set-delegate ] keep ;
+    [
+        [
+            [
+                stdio get <nested-stream> swap with-stream*
+            ] pre-tag
+        ] div-tag
+    ] with-stream* ;
+
+M: html-stream stream-terpri [ <br/> ] with-stream* ;
 
 : with-html-stream ( quot -- )
-    [ stdio [ <html-stream> ] change  call ] with-scope ;
+    stdio get <html-stream> swap with-stream* ;
+
+: default-css ( -- )
+  <style>
+    "A:link { text-decoration:none}" print
+    "A:visited { text-decoration:none}" print
+    "A:active { text-decoration:none}" print
+    "A:hover, A.nav:hover { border: 1px solid black; text-decoration: none; margin: -1px }" print
+  </style> ;
 
 : html-document ( title quot -- )
     swap chars>entities dup
     <html>
         <head>
             <title> write </title>
+            default-css
         </head>
         <body>
             <h1> write </h1>
index 2983bc46f02a31eaaa2cda9f1d395f51a842b2f5..b0fd3401a991654a9f09cbf475170748d9d7a3a2 100644 (file)
@@ -34,18 +34,18 @@ sequences io strings ;
 
 DEFER: http-get
 
-: do-redirect ( code headers stream -- code headers stream )
+: do-redirect ( code headers string -- code headers string )
     #! Should this support Location: headers that are
     #! relative URLs?
     pick 302 = [
-        stream-close "Location" swap hash nip http-get
+        drop "Location" swap hash nip http-get
     ] when ;
 
 : http-get ( url -- code headers stream )
     #! Opens a stream for reading from an HTTP URL.
     parse-url over parse-host <client> [
-        [ get-request read-response ] with-stream*
-    ] keep do-redirect ;
+        get-request read-response stdio get contents
+    ] with-stream do-redirect ;
 
 : download ( url file -- )
     #! Downloads the contents of a URL to a file.
@@ -60,8 +60,10 @@ DEFER: http-get
         crlf
     ] keep write ;
 
-: http-post ( content-type content url -- code headers stream )
+: http-post ( content-type content url -- code headers string )
     #! Make a POST request. The content is URL encoded for you.
     parse-url over parse-host <client> [
-        [ post-request flush read-response ] with-stream*
+        [
+            post-request flush read-response stdio get contents
+        ] with-stream
     ] keep ;
index 0c11914b017fb61ab5d74a8d4afd23c9fcdd02db..60bd418f1fdf4608287a1b1fdf05432026f97f3d 100644 (file)
@@ -293,11 +293,8 @@ M: unclosed error.
     "Tags: " print
     unclosed-tags [ "  <" write write ">" print ] each ;
 
-: seq-last ( seq -- last )
-    [ length 1 - ] keep nth ;
-
 : push-datum ( object -- )
-    xml-stack get seq-last cdr push ;
+    xml-stack get peek cdr push ;
 
 GENERIC: process ( object -- )
 
@@ -315,8 +312,8 @@ M: closer process
     closer-name xml-stack get pop uncons
     >r [ 
         opener-name [
-           2dup = [ 2drop ] [ swap <mismatched> throw ] if
-       ] keep
+            2dup = [ 2drop ] [ swap <mismatched> throw ] if
+        ] keep
     ] keep opener-props r> <tag> push-datum ;
 
 : initialize-xml-stack ( -- )
@@ -325,7 +322,7 @@ M: closer process
 : xml ( string -- tag )
     #! Produces a tree of XML nodes
     [
-       initialize-xml-stack
+        initialize-xml-stack
         [ process ] xml-each
         xml-stack get
         dup length 1 = [ <unclosed> throw ] unless
@@ -407,7 +404,7 @@ TUPLE: process-missing process tag ;
 M: process-missing error.
     "Tag <" write
     process-missing-tag tag-name write
-    "> not implemented on process process " write
+    "> not implemented on process " write
     dup process-missing-process word-name print ;
 
 : run-process ( tag word -- )
index 7ee5b70eb70104ce0f251a63963accbdeae9236e..16bf07225ab3f53f5a3aed58b7715eff62274d88 100644 (file)
@@ -39,7 +39,6 @@ $terpri
 { $subsection stream-write1 }
 { $subsection stream-write }
 { $subsection stream-terpri }
-{ $subsection stream-terpri* }
 { $subsection stream-format }
 { $subsection with-nested-stream }
 "If your stream supports the first three but not the rest, wrap it in a " { $link <plain-writer> } ", which provides plain text implementations of the stream formatting words (the so called " { $emphasis "extended stream output protocol" } ")." ;
@@ -68,7 +67,6 @@ ARTICLE: "stdio" "The default stream"
 { $subsection write }
 { $subsection print }
 { $subsection terpri }
-{ $subsection terpri* }
 { $subsection format }
 { $subsection with-nesting }
 "A pair of combinators support rebinding the " { $link stdio } " variable:"
@@ -94,8 +92,7 @@ ARTICLE: "character-styles" "Character styles"
 { $subsection font-size }
 { $subsection font-style }
 { $subsection presented }
-{ $subsection file }
-{ $subsection word-break } ;
+{ $subsection file } ;
 
 ARTICLE: "paragraph-styles" "Paragraph styles"
 "Paragraph styles for " { $link with-nested-stream } ":"
index 57f578e080bf38bb463f28b3604fa41f149ea411..2ab2c4400f3834311f7c3cc9fcd4d86f706f708a 100644 (file)
@@ -1,15 +1,18 @@
 IN: help
-USING: arrays hashtables io kernel ;
+USING: arrays hashtables io kernel namespaces ;
+
+SYMBOL: last-block
 
 : (help) ( topic -- )
     default-style [
-        [ article-content print-element ] with-nesting* terpri*
-    ] with-style ;
+        last-block on article-content print-element
+    ] with-nesting* terpri ;
 
 DEFER: $heading
 
 : help ( topic -- )
-    dup article-title $heading (help) ;
+    default-style [ dup article-title $heading ] with-style
+    (help) ;
 
 : glossary ( name -- ) <term> help ;
 
index 5106fbf6bdc5869ee6d9805c6eac486251fed4e8..c207ea3a93c89bdc781b264f015f7d0cc8bd0ac3 100644 (file)
@@ -19,37 +19,26 @@ parser prettyprint sequences strings styles vectors words ;
 PREDICATE: array simple-element
     dup empty? [ drop t ] [ first word? not ] if ;
 
-: write-term ( string -- )
-    dup terms get hash [
-        dup <term> presented associate [ format* ] with-style
-    ] [
-        format*
-    ] if ;
+M: string print-element last-block off format* ;
 
-M: string print-element
-    " " split
-    [ dup empty? [ drop ] [ write-term ] if ]
-    [ bl ] interleave ;
+M: array print-element unswons* execute ;
 
-M: array print-element
-    unswons* execute ;
-
-M: word print-element
-    { } swap execute ;
+M: word print-element { } swap execute ;
 
 : ($span) ( content style -- )
-    [ print-element ] with-style ;
+    last-block off [ print-element ] with-style ;
 
-: ($block) ( content style -- )
-    terpri*
-    [ [ print-element ] with-nesting* ] with-style
-    terpri* ;
+: ($block) ( quot -- )
+    last-block [ [ terpri ] unless f ] change
+    call
+    terpri
+    last-block on ; inline
 
 ! Some spans
 
-: $heading heading-style ($block) ;
+: $heading [ heading-style ($span) ] ($block) ;
 
-: $subheading subheading-style ($block) ;
+: $subheading [ subheading-style ($span) ] ($block) ;
 
 : $snippet snippet-style ($span) ;
 
@@ -57,18 +46,19 @@ M: word print-element
 
 : $url url-style ($span) ;
 
-: $terpri terpri terpri drop ;
+: $terpri last-block off terpri terpri drop ;
 
 ! Some blocks
-M: simple-element print-element [ print-element ] each ;
+M: simple-element print-element
+    [ print-element ] each ;
 
 : ($code) ( presentation quot -- )
-    terpri* 
-    code-style [
-        >r current-style swap presented pick set-hash r>
-        with-nesting
-    ] with-style
-    terpri* ; inline
+    [
+        code-style [
+            >r current-style swap presented pick set-hash r>
+            with-nesting
+        ] with-style
+    ] ($block) ; inline
 
 : $code ( content -- )
     "\n" join dup <input> [ format* ] ($code) ;
@@ -82,11 +72,16 @@ M: simple-element print-element [ print-element ] each ;
     ] if* ;
 
 : $stack-effect ( word -- )
-    stack-effect [ "Stack effect" $subheading $snippet ] when* ;
+    stack-effect [
+        "Stack effect" $subheading $snippet
+    ] when* ;
+
+: $vocabulary ( content -- )
+    "Vocabulary" $subheading $snippet ;
 
 : $synopsis ( content -- )
     first dup
-    word-vocabulary [ "Vocabulary" $subheading $snippet ] when*
+    word-vocabulary [ $vocabulary ] when*
     dup parsing? [ $syntax ] [ $stack-effect ] if ;
 
 : $description ( content -- )
@@ -99,21 +94,20 @@ M: simple-element print-element [ print-element ] each ;
     "Examples" $subheading print-element ;
 
 : $warning ( content -- )
-    terpri*
-    current-style warning-style hash-union [
-        "Warning" $subheading print-element
-    ] with-nesting
-    terpri* ;
+    [
+        current-style warning-style hash-union [
+            "Warning" $subheading print-element
+        ] with-nesting
+    ] ($block) ;
 
 : textual-list ( seq quot -- )
-    [ "," format* bl ] interleave ; inline
+    [ ", " print-element ] interleave ; inline
 
 : $see ( content -- )
-    code-style [ [ first see ] with-nesting* ] with-style ;
+    code-style [ first see ] with-nesting* ;
 
 : $example ( content -- )
-    first2 swap dup <input>
-    [
+    first2 swap dup <input> [
         input-style [ format* ] with-style terpri format*
     ] ($code) ;
 
@@ -129,15 +123,16 @@ M: link article-content link-name article-content ;
 DEFER: help
 
 : $subsection ( object -- )
-    terpri*
-    subsection-style [
-        first dup article-title swap <link>
-        dup [ link-name (help) ] curry
-        simple-outliner
-    ] with-style ;
+    [
+        subsection-style [
+            first dup article-title swap <link>
+            dup [ link-name (help) ] curry
+            simple-outliner
+        ] with-style
+    ] ($block) ;
 
 : $link ( article -- )
-    first dup word? [
+    last-block off first dup word? [
         pprint
     ] [
         link-style [
@@ -145,9 +140,6 @@ DEFER: help
         ] with-style
     ] if ;
 
-: $glossary ( element -- )
-    first dup <term> simple-object ;
-
 : $definition ( content -- )
     "Definition" $subheading $see ;
 
@@ -155,19 +147,24 @@ DEFER: help
     "See also" $subheading [ 1array $link ] textual-list ;
 
 : $values ( content -- )
-    "Arguments and values" $subheading [
-        unswons* $snippet " -- " format* print-element
-    ] [
-        terpri
-    ] interleave ;
+    "Arguments and values" $subheading
+    [ unswons* $snippet " -- " format* print-element ]
+    [ terpri ] interleave ;
 
 : $predicate ( content -- )
     { { "object" "an object" } } $values
-    "Tests if the object is an instance of the " $description
-    $link " class." format* ;
+    [
+        "Tests if the object is an instance of the " ,
+        { $link } swap append ,
+        " class." ,
+    ] { } make $description ;
 
 : $list ( content -- )
-    terpri* [ "- " format* print-element terpri* ] each ;
+    [
+        [
+            list-element-style [ print-element ] with-nesting*
+        ] ($block)
+    ] each ;
 
 : $errors ( content -- )
     "Errors" $subheading print-element ;
@@ -192,4 +189,5 @@ DEFER: help
     { { "x" "a complex number" } { "y" "a complex number" } } $values ;
 
 : $io-error
+    drop
     "Throws an error if the I/O operation fails." $errors ;
index f438b61b54cfeb622e226492c62473b4a1952e63..02e70e1a56c6851f49f28c0b8cc61f1f5df89b50 100644 (file)
@@ -50,3 +50,6 @@ USING: styles ;
         { border-color { 1 0 0 1 } }
         { border-width 5 }
     } ;
+
+: list-element-style
+    H{ { border-color { 0.8 0.8 0.8 1 } } { border-width 5 } } ;
index 0d25450d73882c3379067f02ca213cbd7f4ef8a6..9d296be3f76418f7c3417b8f09a99a7a1d42b83f 100644 (file)
@@ -26,9 +26,6 @@ M: duplex-stream stream-write
 M: duplex-stream stream-terpri
     duplex-stream-out stream-terpri ;
 
-M: duplex-stream stream-terpri*
-    duplex-stream-out stream-terpri* ;
-
 M: duplex-stream stream-format
     duplex-stream-out stream-format ;
 
index d795f6228032e7c5b682b4e6441ae58780876412..c710d23816eac6424013cd67f14c495b89e99285 100644 (file)
@@ -12,7 +12,6 @@ M: f stream-read 2drop f ;
 M: f stream-write1 2drop ;
 M: f stream-write 2drop ;
 M: f stream-terpri drop ;
-M: f stream-terpri* drop ;
 M: f stream-flush drop ;
 
 M: f stream-format 3drop ;
index 85d47ed7a8ffd428d7c6efb62e903ed1ca3cf85c..3074a616f3032914f78438a9ac36efc346bec504 100644 (file)
@@ -6,7 +6,6 @@ TUPLE: plain-writer ;
 C: plain-writer ( stream -- stream ) [ set-delegate ] keep ;
 
 M: plain-writer stream-terpri CHAR: \n swap stream-write1 ;
-M: plain-writer stream-terpri* stream-terpri ;
 M: plain-writer stream-format nip stream-write ;
 M: plain-writer with-nested-stream ( quot style stream -- )
-    [ stdio set drop call ] with-scope ;
+    nip swap with-stream* ;
index 34c7ea91e75866d7ebcebfb961778087f0be0ba4..feef6c47ab84760c6039cedf4ae8ad0574ca66da 100644 (file)
@@ -18,7 +18,6 @@ SYMBOL: stdio
 : flush ( -- ) stdio get stream-flush ;\r
 \r
 : terpri ( -- ) stdio get stream-terpri ;\r
-: terpri* ( -- ) stdio get stream-terpri* ;\r
 : format ( string style -- ) stdio get stream-format ;\r
 \r
 : with-nesting ( style quot -- )\r
@@ -26,12 +25,11 @@ SYMBOL: stdio
 \r
 : print ( string -- ) stdio get stream-print ;\r
 \r
-: with-stream ( stream quot -- )\r
-    [ swap stdio set [ close ] cleanup ] with-scope ; inline\r
-\r
 : with-stream* ( stream quot -- )\r
-    [ swap stdio set [ close rethrow ] recover ] with-scope ;\r
-    inline\r
+    [ swap stdio set call ] with-scope ; inline\r
+\r
+: with-stream ( stream quot -- )\r
+    swap [ [ close ] cleanup ] with-stream* ; inline\r
 \r
 SYMBOL: style-stack\r
 \r
@@ -49,10 +47,10 @@ SYMBOL: style-stack
 \r
 : format* ( string -- ) current-style format ;\r
 \r
-: bl ( -- ) H{ { word-break t } } [ " " format* ] with-style ;\r
+: bl ( -- ) " " format* ;\r
 \r
-: with-nesting* ( quot -- )\r
-    current-style swap with-nesting ; inline\r
+: with-nesting* ( style quot -- )\r
+    swap [ current-style swap with-nesting ] with-style ; inline\r
 \r
 : write-object ( object quot -- )\r
     >r presented associate r> with-style ;\r
@@ -61,7 +59,7 @@ SYMBOL: style-stack
     [ format* ] write-object ;\r
 \r
 : write-outliner ( content caption -- )\r
-    >r outline associate r> with-nesting terpri ;\r
+    >r outline associate r> with-nesting* ;\r
 \r
 : simple-outliner ( string object content -- )\r
     [ simple-object ] write-outliner ;\r
index 96f20371bfaee1ef1251050b52670a375e1b5820..1a1359ad69565e28cfaaac07c55ebc1f1b005f54 100644 (file)
@@ -45,10 +45,6 @@ HELP: terpri "( -- )"
 { $contract "Writes a line terminator to the " { $link stdio } " stream. If the stream does buffering, output may not be performed immediately; use " { $link flush } " to force output." }
 $io-error ;
 
-HELP: terpri* "( -- )"
-{ $contract "Writes a line terminator to the " { $link stdio } " stream, unless the stream is already positioned at the start of a line, in which case this word does nothing. If the stream does buffering, output may not be performed immediately; use " { $link flush } " to force output." }
-$io-error ;
-
 HELP: format "( str style -- )"
 { $values { "str" "a string" } { "style" "a hashtable" } }
 { $contract "Writes formatted text to the " { $link stdio } " stream. If the stream does buffering, output may not be performed immediately; use " { $link flush } " to force output." }
@@ -73,7 +69,8 @@ HELP: with-stream "( stream quot -- )"
 
 HELP: with-stream* "( stream quot -- )"
 { $values { "stream" "an input or output stream" } { "quot" "a quotation" } }
-{ $description "Calls the quotation in a new dynamic scope, with the " { $link stdio } " variable rebound to  " { $snippet "stream" } ". The stream is closed if the quotation throws an error, however it is " { $emphasis "not" } " closed if the quotation returns without incident." }
+{ $description "Calls the quotation in a new dynamic scope, with the " { $link stdio } " variable rebound to  " { $snippet "stream" } "." }
+{ $notes "This word differs from " { $link with-stream } " in that if an error is thrown while the quotation is executing, the stream is " { $emphasis "not" } " closed." }
 { $see-also with-stream } ;
 
 HELP: style-stack f
index d8395c9d3c3d0dcffc167df03975c04a1323e6c9..3c6733b77ce52ab7591c0b007ec2064ea4b9408b 100644 (file)
@@ -13,7 +13,6 @@ GENERIC: stream-write1 ( char stream -- )
 GENERIC: stream-write  ( string stream -- )
 GENERIC: stream-flush  ( stream -- )
 GENERIC: stream-terpri ( stream -- )
-GENERIC: stream-terpri* ( stream -- )
 GENERIC: stream-format ( string style stream -- )
 GENERIC: with-nested-stream ( quot style stream -- )
 
index de9afeeadd6ff90cf283c096b87ea57ba820f854..6a90108aac933475eb0166c3c5e2dd8004b3faed 100644 (file)
@@ -47,11 +47,6 @@ HELP: stream-terpri "( stream -- )"
 { $contract "Writes a line terminator. If the stream does buffering, output may not be performed immediately; use " { $link stream-flush } " to force output." }
 $io-error ;
 
-HELP: stream-terpri* "( stream -- )"
-{ $values { "stream" "an output stream" } }
-{ $contract "Writes a line terminator unless the stream is already positioned at the start of a line, in which case this word does nothing. If the stream does buffering, output may not be performed immediately; use " { $link stream-flush } " to force output." }
-$io-error ;
-
 HELP: stream-format "( str style stream -- )"
 { $values { "str" "a string" } { "style" "a hashtable" } { "stream" "an output stream" } }
 { $contract "Writes formatted text to the stream. If the stream does buffering, output may not be performed immediately; use " { $link stream-flush } " to force output."
index 6dcc7207b25786e2251f95e87620c94ead4d7e74..10aef0ca9dac74fffd55c733ffd874b26bcf6c91 100644 (file)
@@ -13,9 +13,8 @@ M: sbuf stream-flush drop ;
     512 <sbuf> <plain-writer> ;
 
 : string-out ( quot -- str )
-    [
-        <string-writer> stdio set call stdio get >string
-    ] with-scope ; inline
+    <string-writer> [ call stdio get >string ] with-stream* ;
+    inline
 
 ! Reversed string buffers support the stream input protocol.
 M: sbuf stream-read1 ( sbuf -- char/f )
index d3df55707de40e850149549532eed5638fa197ef..8adbaed138b213aaab0a10e001b40a0db0abc616 100644 (file)
@@ -15,7 +15,6 @@ SYMBOL: font-size
 SYMBOL: font-style
 SYMBOL: presented
 SYMBOL: file
-SYMBOL: word-break
 
 ! Paragraph styles
 SYMBOL: page-color
index 77b371444b1c9cb0fc89670fd3d6d622ae65d39b..44890187bc1182ad26526f71812c5f4184987982 100644 (file)
@@ -62,10 +62,6 @@ HELP: presented f
 HELP: file f
 { $description "Character style. A pathname associated with the text. In the Factor HTTP server, this is rendered as a link to this path on the server." } ;
 
-HELP: word-break f
-{ $description "Character style. Denotes that this text is a point in the text where the line can be wrapped." }
-{ $see-also bl } ;
-
 HELP: page-color f
 { $description "Paragraph style. Background color of the paragraph block, denoted by a sequence of four numbers between 0 and 1 (red, green, blue and alpha)." } 
 { $examples
index 5c69cb5650be34eceee1ae42925e10d46a62b90a..83799be830b17dfad458b867c8ab2d7d586a2334 100644 (file)
@@ -79,13 +79,14 @@ DEFER: describe
 
 : sheet. ( sheet -- )
     dup format-sheet swap peek
-    [ dup [ describe ] curry simple-outliner ] 2each ;
+    [ dup [ describe ] curry simple-outliner terpri ] 2each ;
 
 : describe ( object -- ) dup summary print sheet sheet. ;
 
 : sequence-outliner ( seq quot -- | quot: obj -- )
     swap [
-        [ unparse-short ] keep rot dupd curry simple-outliner
+        [ unparse-short ] keep rot dupd curry
+        simple-outliner terpri
     ] each-with ;
 
 : words. ( vocab -- )
index 1a415597af007f3bafacf1b62180b467ac2aa7c2..c7d3d754ed70e9e412927db0467006db92af292a 100644 (file)
@@ -99,10 +99,6 @@ M: pane stream-terpri ( pane -- )
     over pane-output add-incremental
     prepare-line ;
 
-M: pane stream-terpri* ( pane -- )
-    dup pane-current gadget-children empty?
-    [ dup stream-terpri ] unless drop ;
-
 : pane-write ( pane seq -- )
     [ over pane-current stream-write ]
     [ dup stream-terpri ] interleave drop ;
@@ -139,11 +135,14 @@ M: pane stream-format ( string style pane -- )
 
 M: pane stream-close ( pane -- ) drop ;
 
+: ?terpri
+    dup pane-current gadget-children empty?
+    [ dup stream-terpri ] unless drop ;
+
 : with-pane ( pane quot -- )
     #! Clear the pane and run the quotation in a scope with
     #! stdio set to the pane.
-    over pane-clear over >r with-stream*
-    r> stream-terpri* ; inline
+    over pane-clear over >r with-stream* r> ?terpri ; inline
 
 : make-pane ( quot -- pane )
     #! Execute the quotation with output to an output-only pane.
index 168afe6425f5765b47c959467baec3f8f68263f8..89c309d5726afaa78eedbd2c37616b3e39d1df6d 100644 (file)
@@ -5,7 +5,8 @@ namespaces sequences ;
 ! A word break gadget
 TUPLE: word-break-gadget ;
 
-C: word-break-gadget ( gadget -- gadget ) [ set-delegate ] keep ;
+C: word-break-gadget ( gadget -- gadget )
+    [ set-delegate ] keep ;
 
 ! A gadget that arranges its children in a word-wrap style.
 TUPLE: paragraph margin ;
index d7025b371a7b832e3377cefe80ae018d5ed9d6ae..123ab7591882fe5403acbfda04cfec09ca0ab62e 100644 (file)
@@ -5,18 +5,6 @@ USING: arrays gadgets gadgets-borders gadgets-labels
 gadgets-layouts gadgets-outliner gadgets-panes hashtables io
 kernel sequences strings styles ;
 
-! Utility pseudo-stream for implementation of panes
-
-UNION: gadget-stream pack paragraph ;
-
-M: gadget-stream stream-close ( stream -- ) drop ;
-
-M: gadget-stream stream-write ( string stream -- )
-    over empty? [ 2drop ] [ >r <label> r> add-gadget ] if ;
-
-M: gadget-stream stream-write1 ( char stream -- )
-    >r ch>string r> stream-write ;
-
 ! Character styles
 
 : apply-style ( style gadget key quot -- style gadget )
@@ -39,22 +27,14 @@ M: gadget-stream stream-write1 ( char stream -- )
 : apply-command-style ( style gadget -- style gadget )
     presented [ <command-button> ] apply-style ;
 
-: apply-break-style ( style gadget -- style gadget )
-    word-break [ drop <word-break-gadget> ] apply-style ;
-
 : <presentation> ( style text -- gadget )
     <label>
     apply-foreground-style
     apply-background-style
     apply-font-style
-    apply-break-style
     apply-command-style
     nip ;
 
-M: gadget-stream stream-format ( string style stream -- )
-    pick empty? pick hash-empty? and
-    [ 3drop ] [ >r swap <presentation> r> add-gadget ] if ;
-
 ! Paragraph styles
 
 : apply-wrap-style ( style pane -- style pane )
@@ -95,3 +75,47 @@ M: gadget-stream stream-format ( string style stream -- )
 
 M: pane with-nested-stream ( quot style stream -- )
     >r <nested-pane> r> write-gadget ;
+
+! Stream utilities
+M: pack stream-close ( stream -- ) drop ;
+
+M: paragraph stream-close ( stream -- ) drop ;
+
+: gadget-write ( string gadget -- )
+    over empty? [ 2drop ] [ >r <label> r> add-gadget ] if ;
+
+M: pack stream-write ( string stream -- ) gadget-write ;
+
+: gadget-bl ( style stream -- )
+    >r " " <presentation> <word-break-gadget> r> add-gadget ;
+
+M: paragraph stream-write ( string stream -- )
+    swap " " split
+    [ over gadget-write ] [ H{ } over gadget-bl ] interleave
+    drop ;
+
+: gadget-write1 ( char gadget -- )
+    >r ch>string r> stream-write ;
+
+M: pack stream-write1 ( char stream -- ) gadget-write1 ;
+
+M: paragraph stream-write1 ( char stream -- )
+    over CHAR: \s =
+    [ H{ } swap gadget-bl drop ] [ gadget-write1 ] if ;
+
+: gadget-format ( string style stream -- )
+    pick empty? pick hash-empty? and
+    [ 3drop ] [ >r swap <presentation> r> add-gadget ] if ;
+
+M: pack stream-format ( string style stream -- )
+    gadget-format ;
+
+M: paragraph stream-format ( string style stream -- )
+    presented pick hash [
+        gadget-format
+    ] [
+        rot " " split
+        [ pick pick gadget-format ]
+        [ 2dup gadget-bl ] interleave
+        2drop
+    ] if ;
index 3c1c1ec0d41a77295a1a9edcfe9f51fcaa9ea5bc..df1b1586cdd1ed99cd0e825cd3abb968cc176d7f 100644 (file)
@@ -139,9 +139,6 @@ M: win32-stream stream-readln ( stream -- str )
 M: win32-stream stream-terpri
     win32-stream-this [ CHAR: \n do-write ] bind ;
 
-M: win32-stream stream-terpri*
-    win32-stream-this stream-terpri ;
-
 M: win32-stream stream-flush ( stream -- )
     win32-stream-this [ maybe-flush-output ] bind ;
 
@@ -167,7 +164,6 @@ M: win32-stream expire ( stream -- )
         timeout get [ millis cutoff get > [ handle get CancelIo ] when ] when
     ] bind ;
 
-USE: inspector
 M: win32-stream with-nested-stream ( quot style stream -- )
     win32-stream-this [ drop stream get swap with-stream* ] bind ;