Skip to content

Commit

Permalink
gopher: simplify.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Dec 20, 2014
1 parent c45e4e1 commit 9858753
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions extra/gopher/gopher.factor
Expand Up @@ -51,7 +51,7 @@ PRIVATE>

ERROR: not-a-gopher-url url ;

: gopher* ( url -- item-type byte-array )
: gopher ( url -- item-type byte-array )
dup url? [ >url ] unless
dup protocol>> "gopher" = [ not-a-gopher-url ] unless {
[ host>> ]
Expand Down Expand Up @@ -80,6 +80,16 @@ M: gopher-link >url
} cleave "gopher://%s:%s/%s%s" sprintf
] if >url ;

: gopher-link. ( gopher-link -- )
dup type>> CHAR: i = [
name>> print
] [
[ name>> ] keep [
presented ,,
COLOR: blue foreground ,,
] H{ } make format nl
] if ;

: gopher-text ( object -- lines )
utf8 decode string-lines { "." } split1 drop ;

Expand All @@ -91,33 +101,11 @@ M: gopher-link >url

PRIVATE>

: gopher ( url -- object )
gopher* swap {
{ A_TEXT [ gopher-text ] }
{ A_MENU [ gopher-menu ] }
{ A_INDEX [ gopher-menu ] }
{ A_GIF [ gopher-gif ] }
[ drop ]
} case ;

: gopher. ( url -- )
gopher {
{ [ dup byte-array? ] [ . ] }
{ [ dup image? ] [ image. ] }
[
[
dup gopher-link? [
dup type>> CHAR: i = [
name>> print
] [
[ name>> ] keep [
presented ,,
COLOR: blue foreground ,,
] H{ } make format nl
] if
] [
print
] if
] each
]
} cond ;
gopher swap {
{ A_TEXT [ gopher-text [ print ] each ] }
{ A_MENU [ gopher-menu [ gopher-link. ] each ] }
{ A_INDEX [ gopher-menu [ gopher-link. ] each ] }
{ A_GIF [ gopher-gif image. ] }
[ drop . ]
} case ;

0 comments on commit 9858753

Please sign in to comment.