#lang racket/base (require racket/class racket/date racket/list racket/match "fs.rkt" "framework.rkt") (module+ test (require rackunit)) (define (timestamp->string ts) (date->string (seconds->date ts #t) #t)) (define meowbb-post-view% (class activity% (init-field posts) (init-field modtimes) (init-field path) (define post (first (hash-ref (hash-ref* posts path) *post-index*))) (define root (new header/footer% [header (new label% [label-text (format "meowbb : ~a" (cons (post-forum post) (post-path post)))])] [body (new scroll-pane% [body (new text-pane% [content (post-content post)])])] [footer (new label% [label-text "[JK] scroll | [Q] back"])])) (super-new [root root]) (define/override (on-event e) (match e ["q" 'quit] [_ 'continue])))) (define meowbb-post-list% (class activity% (init-field posts) (init-field modtimes) (init-field forum) (define sorted (sorted-level posts modtimes (list forum))) (define entries (for/list ([posts-in (in-list sorted)]) (define post (first (hash-ref posts-in *post-index*))) (define modtime (hash-ref modtimes (cons (post-forum post) (post-path post)))) (list (last (post-path post)) (post-author post) (timestamp->string modtime)))) (define root (new header/footer% [header (new label% [label-text (format "meowbb : ~a" forum)])] [body (new scroll-pane% [body (new table% [headers '("title" "author" "updated")] [cells entries])])] [footer (new label% [label-text "[JK] navigate | [ENTER] select | [Q] back"])])) (super-new [root root]) (define/override (on-event e) (match e ["q" 'quit] [(app-event _ 'selection row) (define post (first (hash-ref (list-ref sorted row) *post-index*))) (new meowbb-post-view% [posts posts] [modtimes modtimes] [path (cons forum (post-path post))])] [_ 'continue])))) (define meowbb-forum-list% (class activity% (init-field posts) (init-field modtimes) (define forums (sort (hash-keys posts) stringstring (hash-ref modtimes (list forum)))))) (define root (new header/footer% [header (new label% [label-text "meowbb : forums"])] [body (new scroll-pane% [body (new table% [headers '("forum" "updated")] [cells entries])])] [footer (new label% [label-text "[JK] navigate | [ENTER] select | [Q] quit"])])) (super-new [root root]) (define/override (on-event e) (match e ["q" 'quit] [(app-event _ 'selection row) (define forum (list-ref forums row)) (new meowbb-post-list% [posts posts] [modtimes modtimes] [forum forum])] [_ 'continue])) (define/override (on-deactivated) "bye meow ~"))) (define (tui-main) ;; gang (date-display-format 'iso-8601) (displayln "fetching users") (define users (list-users)) (displayln "fetching posts") (define posts (get-posts users)) (displayln "calculting modtimes") (define modtimes (make-hash)) (void (dfs-modtime posts '() modtimes)) (run-application "meowbb" (new meowbb-forum-list% [posts posts] [modtimes modtimes]))) (module+ test ;; tests lol (check-equal? (+ 2 2) 4)) (module+ main (require racket/cmdline) (command-line #:program "meowbb" #:args () (tui-main)))