Skip to content

Commit

Permalink
gopher: fix bug where empty lines weren't printed properly in menus.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Dec 21, 2014
1 parent 9858753 commit b681745
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions extra/gopher/gopher.factor
Expand Up @@ -67,9 +67,7 @@ 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
] if-empty ;
unclip swap "\t" split first4 gopher-link boa ;

M: gopher-link >url
dup type>> CHAR: h = [
Expand All @@ -93,19 +91,24 @@ M: gopher-link >url
: gopher-text ( object -- lines )
utf8 decode string-lines { "." } split1 drop ;

: gopher-gif ( object -- image )
"gif" (image-class) load-image* ;
: gopher-text. ( object -- )
gopher-text [ print ] each ;

: gopher-menu ( object -- links )
gopher-text [ <gopher-link> ] map ;
: gopher-gif. ( object -- )
"gif" (image-class) load-image* image. ;

: gopher-menu. ( object -- )
gopher-text [
[ nl ] [ <gopher-link> gopher-link. ] if-empty
] each ;

PRIVATE>

: gopher. ( url -- )
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. ] }
{ A_TEXT [ gopher-text. ] }
{ A_MENU [ gopher-menu. ] }
{ A_INDEX [ gopher-menu. ] }
{ A_GIF [ gopher-gif. ] }
[ drop . ]
} case ;

0 comments on commit b681745

Please sign in to comment.