From: Siraaj Khandkar Date: Sat, 20 Mar 2021 22:35:24 +0000 (-0400) Subject: Support sort order reversal X-Git-Tag: 0.8.0 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=a4899240b58d00d8fbc6f1066c1dcd98583170c7;p=tt.git Support sort order reversal --- diff --git a/info.rkt b/info.rkt index 0c2f57b..599236f 100644 --- 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 ")) (define deps diff --git a/tt.rkt b/tt.rkt index c0e2c5c..4b90055 100644 --- a/tt.rkt +++ b/tt.rkt @@ -241,9 +241,13 @@ (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 @@ -326,10 +330,15 @@ (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" @@ -338,5 +347,5 @@ "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)))))] ))))