gopher: handle query params, maybe (not tested).

db4
John Benediktsson 2014-12-17 13:38:29 -08:00
parent cba72871c9
commit 9a47d60873
1 changed files with 8 additions and 6 deletions

View File

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