From: Siraaj Khandkar Date: Tue, 16 Mar 2021 12:43:12 +0000 (-0400) Subject: Alternate colors based on nick, rather than just msg X-Git-Tag: 0.5.0~7 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=3d042e75d643b00caca07742b942ad6a206c026d;p=tt.git Alternate colors based on nick, rather than just msg --- diff --git a/screenshot-multi.jpg b/screenshot-multi.jpg index c1ed4dc..7ad2b75 100644 Binary files a/screenshot-multi.jpg and b/screenshot-multi.jpg differ diff --git a/screenshot-single.jpg b/screenshot-single.jpg index bfce443..1c93d14 100644 Binary files a/screenshot-single.jpg and b/screenshot-single.jpg differ diff --git a/tt.rkt b/tt.rkt index ebbecad..f0e856a 100644 --- a/tt.rkt +++ b/tt.rkt @@ -93,17 +93,20 @@ [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? @@ -200,9 +203,13 @@ (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"