Alternate colors based on nick, rather than just msg
authorSiraaj Khandkar <siraaj@khandkar.net>
Tue, 16 Mar 2021 12:43:12 +0000 (08:43 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Tue, 16 Mar 2021 12:45:39 +0000 (08:45 -0400)
screenshot-multi.jpg
screenshot-single.jpg
tt.rkt

index c1ed4dc..7ad2b75 100644 (file)
Binary files a/screenshot-multi.jpg and b/screenshot-multi.jpg differ
index bfce443..1c93d14 100644 (file)
Binary files a/screenshot-single.jpg and b/screenshot-single.jpg differ
diff --git a/tt.rkt b/tt.rkt
index ebbecad..f0e856a 100644 (file)
--- a/tt.rkt
+++ b/tt.rkt
          [expected (sort (           filter-map    f xs) <)])
     (check-equal? actual expected "concurrent-filter-map")))
 
-(define (msg-print out-format odd msg)
-  (printf
-    (match out-format
-      ['single-line "~a  \033[1;37m<~a ~a>\033[0m  \033[0;~am~a\033[0m~n"]
-      ['multi-line  "~a~n\033[1;37m<~a ~a>\033[0m~n\033[0;~am~a\033[0m~n~n"]
-      [_           (raise (format "Invalid output format: ~a" out-format))])
-    (date->string (seconds->date [msg-ts_epoch msg]) #t)
-    (msg-nick msg)
-    (msg-uri  msg)
-    (if odd 36 33)
-    (msg-text msg)))
+(define msg-print
+  (let* ([colors (vector 36 33)]
+         [n      (vector-length colors)])
+    (λ (out-format color-i msg)
+       (printf
+         (match out-format
+           ['single-line "~a  \033[1;37m<~a ~a>\033[0m  \033[0;~am~a\033[0m~n"]
+           ['multi-line  "~a~n\033[1;37m<~a ~a>\033[0m~n\033[0;~am~a\033[0m~n~n"]
+           [_           (raise (format "Invalid output format: ~a" out-format))])
+         (date->string (seconds->date [msg-ts_epoch msg]) #t)
+         (msg-nick msg)
+         (msg-uri  msg)
+         (vector-ref colors (modulo color-i n))
+         (msg-text msg)))))
 
 (define re-msg-begin
   ; TODO Zulu offset. Maybe in several formats. Which ones?
               (raise status))))))
 
 (define (timeline-print out-format timeline)
-  (for ([msg timeline]
-        [i   (in-naturals)])
-       (msg-print out-format (odd? i) msg)))
+  (void (foldl (match-lambda**
+                 [((and m (msg _ _ nick _ _)) (cons prev-nick i))
+                  (let ([i (if (string=? prev-nick nick) i (+ 1 i))])
+                    (msg-print out-format i m)
+                    (cons nick i))])
+               (cons "" 0)
+               timeline)))
 
 (define (feed->msgs use-cache feed)
   (log-info "downloading feed nick:~a uri:~a"
This page took 0.035245 seconds and 4 git commands to generate.