]> gitweb.factorcode.org Git - factor.git/commitdiff
new vocab twitter.prettyprint: styled printing of twitter statuses
authorJoe Groff <arcata@gmail.com>
Sun, 27 Jun 2010 18:09:49 +0000 (11:09 -0700)
committerJoe Groff <arcata@gmail.com>
Sun, 27 Jun 2010 18:09:49 +0000 (11:09 -0700)
extra/twitter/prettyprint/prettyprint.factor [new file with mode: 0644]

diff --git a/extra/twitter/prettyprint/prettyprint.factor b/extra/twitter/prettyprint/prettyprint.factor
new file mode 100644 (file)
index 0000000..3f84611
--- /dev/null
@@ -0,0 +1,58 @@
+USING: accessors continuations fry http.client images.loader
+images.loader.private images.viewer io io.styles kernel memoize
+prettyprint sequences twitter ;
+IN: twitter.prettyprint
+
+MEMO: load-http-image ( url -- image/f )
+    '[ _
+        [ http-get [ check-response drop ] dip ]
+        [ image-class ] bi load-image*
+    ] [ drop f ] recover ;
+
+: user-image ( user -- image/f )
+    profile-image-url>> load-http-image ;
+
+CONSTANT: tweet-table-style 
+    H{ { table-gap { 5 5 } } } 
+
+CONSTANT: tweet-username-style 
+    H{
+        { font-style bold }
+    } 
+
+CONSTANT: tweet-text-style 
+    H{
+        { font-name "sans-serif" }
+        { font-size 18 }
+    } 
+
+CONSTANT: tweet-metadata-style
+    H{
+        { font-size 10 }
+    } 
+
+: tweet. ( status -- )
+    tweet-table-style [
+        [
+            [ dup user>> user-image [ image. ] when* ] with-cell
+            [
+                tweet-text-style [
+                    tweet-username-style [
+                        dup user>> screen-name>> write
+                    ] with-style
+                    " " write dup text>> print
+
+                    tweet-metadata-style [
+                        dup created-at>> write
+                        " via " write
+                        dup source>> write
+                    ] with-style
+                ] with-style
+            ] with-cell
+        ] with-row
+    ] tabular-output nl
+    drop ;
+
+: friends-timeline. ( -- )      friends-timeline [ tweet. ] each ;
+: public-timeline.  ( -- )      public-timeline  [ tweet. ] each ;
+: user-timeline.    ( user -- ) user-timeline    [ tweet. ] each ;