]> gitweb.factorcode.org Git - factor.git/commitdiff
gopher: handle query params, maybe (not tested).
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 17 Dec 2014 21:38:29 +0000 (13:38 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 17 Dec 2014 21:38:29 +0000 (13:38 -0800)
extra/gopher/gopher.factor

index 3a12c56f4c3fab1a896f41426a03000bd00df69e..88dae14b2ae5b4957fca0f3fd16e998dfbb09905 100644 (file)
@@ -5,8 +5,8 @@ USING: accessors byte-arrays colors.constants combinators
 formatting fry images images.loader images.loader.private
 images.viewer io io.encodings.binary io.encodings.string
 io.encodings.utf8 io.sockets io.styles kernel make math
-math.parser namespaces prettyprint sequences splitting strings
-urls vocabs ;
+math.parser namespaces present prettyprint sequences splitting
+summary urls vocabs ;
 
 IN: gopher
 
@@ -45,8 +45,8 @@ CONSTANT: A_PLUS_SOUND CHAR: <
 : get-gif ( selector -- image )
     get-binary "gif" (image-class) load-image* ;
 
-: get-text ( selector query/f -- lines )
-    [ "\t" glue ] when* "\r\n" append
+: get-text ( selector -- lines )
+    "?" split1 [ "\t" glue ] when* "\r\n" append
     utf8 encode write flush
     input-stream get (stream-contents-by-block)
     utf8 decode string-lines
@@ -54,6 +54,8 @@ CONSTANT: A_PLUS_SOUND CHAR: <
 
 TUPLE: gopher-link type name selector host port ;
 
+M: gopher-link summary >url present ;
+
 : <gopher-link> ( item -- gopher-link )
     [ "" ] [
         unclip swap "\t" split first4 gopher-link boa
@@ -69,13 +71,13 @@ M: gopher-link >url
     ] if >url ;
 
 : get-menu ( selector -- lines )
-    get-text [ <gopher-link> ] map ;
+    get-text [ <gopher-link> ] map ;
 
 : get-selector ( selector -- stuff )
     "/" split1 "" or swap
     dup length 1 > [ string>number ] [ first ] if
     {
-        { A_TEXT [ get-text ] }
+        { A_TEXT [ get-text ] }
         { A_MENU [ get-menu ] }
         { A_INDEX [ get-menu ] }
         { A_GIF [ get-gif ] }