Support sort order reversal 0.8.0
authorSiraaj Khandkar <siraaj@khandkar.net>
Sat, 20 Mar 2021 22:35:24 +0000 (18:35 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Sat, 20 Mar 2021 22:35:24 +0000 (18:35 -0400)
info.rkt
tt.rkt

index 0c2f57b..599236f 100644 (file)
--- a/info.rkt
+++ b/info.rkt
@@ -6,7 +6,7 @@
 (define pkg-desc
   "twtxt client")
 (define version
-  "0.7.0")
+  "0.8.0")
 (define pkg-authors
   '("Siraaj Khandkar <siraaj@khandkar.net>"))
 (define deps
diff --git a/tt.rkt b/tt.rkt
index c0e2c5c..4b90055 100644 (file)
--- a/tt.rkt
+++ b/tt.rkt
   (void (concurrent-filter-map num_workers feed-download feeds)))
 
 ; TODO timeline contract : time-sorted list of messages
-(define (timeline-read feeds)
+; timeline-read : (U 'old->new 'new->old) -> (Listof Feeds) -> (Listof Msg)
+(define (timeline-read order feeds)
+  (define cmp (match order
+                ['old->new <]
+                ['new->old >]))
   (sort (append* (filter-map feed->msgs feeds))
-        (λ (a b) [< (msg-ts_epoch a) (msg-ts_epoch b)])))
+        (λ (a b) (cmp (msg-ts_epoch a) (msg-ts_epoch b)))))
 
 (define (str->feed str)
   ; TODO validation
              (timeline-download num_workers (file->feeds filename))
              ))]
         [(or "r" "read")
-         (let ([out-format 'multi-line])
+         (let ([out-format 'multi-line]
+               [order      'old->new])
            (command-line
              #:program
              "tt read"
+             #:once-each
+             [("-r" "--rev")
+              "Reverse displayed timeline order."
+              (set! order 'new->old)]
              #:once-any
              [("-s" "--short")
               "Short output format"
               "Long output format"
               (set! out-format 'multi-line)]
              #:args (filename)
-             (timeline-print out-format (timeline-read (file->feeds filename)))))]
+             (timeline-print out-format (timeline-read order (file->feeds filename)))))]
         ))))
This page took 0.033725 seconds and 4 git commands to generate.