X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=tt;h=46059434d82510efacb51cb1d2975da08f969e58;hb=e5c3ae92a01b721a4f9ac27daaed6b2dfff7a060;hp=81dd1a85da0cb119e835ada2cc6935f241494a71;hpb=e0e0fb20d7b5874eadea7e001e6aeda574f42e96;p=tt.git diff --git a/tt b/tt index 81dd1a8..4605943 100755 --- a/tt +++ b/tt @@ -1,6 +1,7 @@ #! /usr/bin/env racket ; vim: filetype=racket +; TODO optional text wrap ; TODO write ; TODO caching (use cache by default, unless explicitly asked for update) ; TODO timeline limits @@ -10,6 +11,8 @@ ; TODO named timelines ; TODO CLI params ; TODO config files +; TODO parse mentions: +; - @ | @ ; TODO highlight mentions ; TODO filter on mentions ; TODO highlight hashtags @@ -19,6 +22,21 @@ ; TODO concurrency ; TODO console logger colors by level ('error) ; TODO file logger ('debug) +; TODO commands: +; - r | read +; - see timeline ops above +; - w | write +; - arg or stdin +; - nick expand to URI +; - q | query +; - see timeline ops above +; - see hashtag and channels above +; - d | download +; - u | upload +; - calls user-configured command to upload user's own feed file to their server +; TODO user-agent format: / (+; @) +; - requires configurability +; - ref: https://twtxt.readthedocs.io/en/latest/user/discoverability.html #lang racket @@ -27,21 +45,26 @@ (require http-client) (require rfc3339-old) -(struct msg (tm_epoch tm_rfc3339 nick text)) +(struct msg (tm_epoch tm_rfc3339 nick uri text)) (struct feed (nick uri)) -(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 (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-tm_epoch msg]) #t) + (msg-nick msg) + (msg-uri msg) + (if odd 36 33) + (msg-text msg))) (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) +(define (str->msg nick uri str) (if (not (regexp-match? re-msg-begin str)) (begin (log-debug "Non-msg line from nick:~a, line:~a" nick str) @@ -62,13 +85,13 @@ [rfc3339-record:mday t] [rfc3339-record:month t] [rfc3339-record:year t])]) - (msg tm_epoch tm_rfc3339 nick tok_text)))))) + (msg tm_epoch tm_rfc3339 nick uri 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))) +(define (str->msgs nick uri str) + (filter-map (λ (line) (str->msg nick uri line)) (str->lines str))) (define (uri-fetch uri) (log-info "GET ~a" uri) @@ -80,10 +103,10 @@ ; TODO Handle redirects (if (= status 200) body (raise status))) -(define (timeline-print timeline) +(define (timeline-print out-format timeline) (for ([msg timeline] [i (in-naturals)]) - (msg-print (odd? i) msg))) + (msg-print out-format (odd? i) msg))) (define (feed->msgs feed) (log-info "downloading feed nick:~a uri:~a" @@ -104,7 +127,8 @@ (feed-uri feed) status) #f)]) - (str->msgs [feed-nick feed] [uri-fetch (feed-uri feed)]))) + (define uri (feed-uri feed)) + (str->msgs [feed-nick feed] uri [uri-fetch uri]))) ; TODO timeline contract : time-sorted list of messages (define (timeline feeds) @@ -120,6 +144,7 @@ (str->lines payload)] [feeds (map (λ (line) + ; TODO validation (define toks (string-split line)) (feed [list-ref toks 0] @@ -148,6 +173,7 @@ (date-display-format 'rfc2822) (define feeds (we-are-twtxt)) - (timeline-print (timeline feeds))) + (define out-format 'multi-line) + (timeline-print out-format (timeline feeds))) (main)