TUI forum client in racket for unix.lgbt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

130 lines
3.7 KiB

  1. #lang racket/base
  2. (require racket/class racket/date racket/list racket/match
  3. "fs.rkt"
  4. "framework.rkt")
  5. (module+ test
  6. (require rackunit))
  7. (define (timestamp->string ts)
  8. (date->string (seconds->date ts #t) #t))
  9. (define meowbb-post-view%
  10. (class activity%
  11. (init-field posts)
  12. (init-field modtimes)
  13. (init-field path)
  14. (define post (first (hash-ref (hash-ref* posts path) *post-index*)))
  15. (define root
  16. (new header/footer%
  17. [header (new label% [label-text (format "meowbb : ~a"
  18. (cons (post-forum post) (post-path post)))])]
  19. [body (new scroll-pane%
  20. [body (new text-pane% [content (post-content post)])])]
  21. [footer (new label% [label-text "[JK] scroll | [Q] back"])]))
  22. (super-new [root root])
  23. (define/override (on-event e)
  24. (match e
  25. ["q" 'quit]
  26. [_ 'continue]))))
  27. (define meowbb-post-list%
  28. (class activity%
  29. (init-field posts)
  30. (init-field modtimes)
  31. (init-field forum)
  32. (define sorted (sorted-level posts modtimes (list forum)))
  33. (define entries
  34. (for/list ([posts-in (in-list sorted)])
  35. (define post (first (hash-ref posts-in *post-index*)))
  36. (define modtime (hash-ref modtimes (cons (post-forum post) (post-path post))))
  37. (list (last (post-path post)) (post-author post)
  38. (timestamp->string modtime))))
  39. (define root
  40. (new header/footer%
  41. [header (new label% [label-text (format "meowbb : ~a" forum)])]
  42. [body (new scroll-pane%
  43. [body (new table%
  44. [headers '("title" "author" "updated")]
  45. [cells entries])])]
  46. [footer (new label% [label-text "[JK] navigate | [ENTER] select | [Q] back"])]))
  47. (super-new [root root])
  48. (define/override (on-event e)
  49. (match e
  50. ["q" 'quit]
  51. [(app-event _ 'selection row)
  52. (define post (first (hash-ref (list-ref sorted row) *post-index*)))
  53. (new meowbb-post-view% [posts posts] [modtimes modtimes]
  54. [path (cons forum (post-path post))])]
  55. [_ 'continue]))))
  56. (define meowbb-forum-list%
  57. (class activity%
  58. (init-field posts)
  59. (init-field modtimes)
  60. (define forums (sort (hash-keys posts) string<?))
  61. (define entries
  62. (for/list ([forum (in-list forums)])
  63. (list forum (timestamp->string (hash-ref modtimes (list forum))))))
  64. (define root
  65. (new header/footer%
  66. [header (new label% [label-text "meowbb : forums"])]
  67. [body (new scroll-pane%
  68. [body (new table%
  69. [headers '("forum" "updated")]
  70. [cells entries])])]
  71. [footer (new label% [label-text "[JK] navigate | [ENTER] select | [Q] quit"])]))
  72. (super-new [root root])
  73. (define/override (on-event e)
  74. (match e
  75. ["q" 'quit]
  76. [(app-event _ 'selection row)
  77. (define forum (list-ref forums row))
  78. (new meowbb-post-list% [posts posts] [modtimes modtimes] [forum forum])]
  79. [_ 'continue]))
  80. (define/override (on-deactivated)
  81. "bye meow ~")))
  82. (define (tui-main)
  83. ;; gang
  84. (date-display-format 'iso-8601)
  85. (displayln "fetching users")
  86. (define users (list-users))
  87. (displayln "fetching posts")
  88. (define posts (get-posts users))
  89. (displayln "calculting modtimes")
  90. (define modtimes (make-hash))
  91. (void (dfs-modtime posts '() modtimes))
  92. (run-application "meowbb" (new meowbb-forum-list% [posts posts] [modtimes modtimes])))
  93. (module+ test
  94. ;; tests lol
  95. (check-equal? (+ 2 2) 4))
  96. (module+ main
  97. (require racket/cmdline)
  98. (command-line
  99. #:program "meowbb"
  100. #:args ()
  101. (tui-main)))