From: Siraaj Khandkar Date: Tue, 10 Nov 2020 11:57:07 +0000 (-0500) Subject: Re-arrange for proximity and order X-Git-Tag: 0.1.0~14 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=e96264cc7f244700f04ce96cebef0760337c9ac2;p=tt.git Re-arrange for proximity and order --- diff --git a/tt b/tt index 0b590e3..5ea77b2 100755 --- a/tt +++ b/tt @@ -11,8 +11,16 @@ (struct msg (tm_epoch tm_rfc3339 nick text)) (struct feed (nick uri)) -(define (str->lines str) - (string-split str (regexp "[\r\n]+"))) +(define (msg-print odd m) + (printf "~a \033[1;37m<~a>\033[0m \033[0;~am~a\033[0m~n" + (date->string (seconds->date [msg-tm_epoch m]) #t) + [msg-nick m] + [if odd 36 33] + [msg-text m])) + +(define re-msg-begin + ; TODO Zulu offset. Maybe in several formats. Which ones? + (pregexp "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}")) (define (str->msg nick str) (if (not (regexp-match? re-msg-begin str)) @@ -37,6 +45,9 @@ [rfc3339-record:year t])]) (msg tm_epoch tm_rfc3339 nick tok_text)))))) +(define (str->lines str) + (string-split str (regexp "[\r\n]+"))) + (define (str->msgs nick str) (filter-map (λ (line) (str->msg nick line)) (str->lines str))) @@ -50,18 +61,6 @@ ; TODO Handle redirects (if (= status 200) body (raise status))) -(define re-msg-begin - ; TODO Zulu offset. Maybe in several formats. Which ones? - (let ([timestamp "[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}"]) - (pregexp (string-append "^" timestamp)))) - -(define (msg-print odd m) - (printf "~a \033[1;37m<~a>\033[0m \033[0;~am~a\033[0m~n" - (date->string (seconds->date [msg-tm_epoch m]) #t) - [msg-nick m] - [if odd 36 33] - [msg-text m])) - (define (timeline-print timeline) (for ([msg timeline] [i (in-naturals)]) @@ -113,7 +112,7 @@ lines)]) feeds)) -(define (logging) +(define (setup-logging) (define logger (make-logger #f #f 'debug #f)) (define log-chan (make-log-receiver logger 'debug)) (void (thread (λ () @@ -128,11 +127,12 @@ (current-logger logger)) (define (main) - (logging) - (define feeds (we-are-twtxt)) + (setup-logging) (current-http-response-auto #f) (current-http-user-agent "tt 0.0.0") (date-display-format 'rfc2822) + + (define feeds (we-are-twtxt)) (timeline-print (timeline feeds))) (main)