Skip to content

Commit

Permalink
Migrated repo to new bonsai api
Browse files Browse the repository at this point in the history
  • Loading branch information
Enoumy committed Jan 5, 2025
1 parent 8dbeb2a commit 35da0c7
Show file tree
Hide file tree
Showing 83 changed files with 1,404 additions and 1,358 deletions.
1 change: 0 additions & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ parse-docstrings = true
wrap-comments = true
line-endings = lf

version = 0.26.2
22 changes: 10 additions & 12 deletions app/capymanga/src/about.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ open Capytui
module Catpuccin = Capytui_catpuccin
open Bonsai.Let_syntax

let component ~go_back =
let component ~go_back (local_ graph) =
(* TODO: Make this prettier. Also figure out a way to nicely center align
text... *)
let%sub dimensions = Capytui.terminal_dimensions in
let%sub flavor = Catpuccin.flavor in
let%sub view =
let%arr flavor = flavor in
let dimensions = Capytui.terminal_dimensions graph in
let flavor = Catpuccin.flavor graph in
let view =
let%arr flavor in
Node.vcat
[ Node.hcat
[ Node.text
Expand Down Expand Up @@ -43,20 +43,18 @@ let component ~go_back =
]
]
in
let%sub view =
let%arr dimensions = dimensions
and view = view in
let view =
let%arr dimensions and view in
Node.center ~within:dimensions view
in
let%sub handler =
let%arr go_back = go_back in
let handler =
let%arr go_back in
fun (event : Event.t) ->
match event with
| `Key ((`Backspace | `Escape), []) | `Key (`ASCII ('q' | '?'), []) ->
go_back
| _ -> Effect.Ignore
in
let%arr view = view
and handler = handler in
let%arr view and handler in
{ Component.view; handler; images = [] }
;;
5 changes: 4 additions & 1 deletion app/capymanga/src/about.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ open! Core
open Capytui
open Bonsai

val component : go_back:unit Effect.t Value.t -> Component.t Computation.t
val component
: go_back:unit Effect.t Bonsai.t
-> local_ Bonsai.graph
-> Component.t Bonsai.t
37 changes: 17 additions & 20 deletions app/capymanga/src/capymanga.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,45 @@ open Bonsai.Let_syntax
open Capytui
module Catpuccin = Capytui_catpuccin

let backdrop =
let%sub dimensions = Capytui.terminal_dimensions in
let%sub flavor = Catpuccin.flavor in
let backdrop (local_ graph) =
let dimensions = Capytui.terminal_dimensions graph in
let flavor = Catpuccin.flavor graph in
let%arr { height; width } = dimensions
and flavor = flavor in
and flavor in
Node.vcat
(List.init height ~f:(fun _ ->
Node.text
~attrs:[ Attr.background_color (Catpuccin.color ~flavor Crust) ]
(String.make width ' ')))
;;

let content ~(page : Page.t Value.t) ~set_page ~go_back =
let%sub dimensions = Capytui.terminal_dimensions in
let content ~(page : Page.t Bonsai.t) ~set_page ~go_back (local_ graph) =
let dimensions = Capytui.terminal_dimensions graph in
let%sub { view; images; handler } =
match%sub page with
| Manga_search { title } ->
Manga_search.component ~dimensions ~title ~set_page
Manga_search.component ~dimensions ~title ~set_page graph
| Manga_view { manga } ->
Manga_viewer.component ~dimensions ~manga ~set_page ~go_back
Manga_viewer.component ~dimensions ~manga ~set_page ~go_back graph
| Chapter_view { chapter } ->
Chapter_viewer.component ~dimensions ~chapter ~go_back
| About_page -> About.component ~go_back
Chapter_viewer.component ~dimensions ~chapter ~go_back graph
| About_page -> About.component ~go_back graph
in
let%sub () = Capytui.listen_to_events handler in
let%arr view = view
and images = images in
let () = Capytui.listen_to_events handler graph in
let%arr view and images in
view, images
;;

let app =
Loading_state.register
@@ Scanlation_group_cache.register
@@
@@ fun (local_ graph) ->
let%sub { page; set_page; go_back } =
Navigation.component (Page.Manga_search { title = None })
Navigation.component (Page.Manga_search { title = None }) graph
in
let%sub content, images = content ~page ~set_page ~go_back in
let%sub backdrop = backdrop in
let%arr backdrop = backdrop
and images = images
and content = content in
let%sub content, images = content ~page ~set_page ~go_back graph in
let%sub backdrop = backdrop graph in
let%arr backdrop and images and content in
Node.zcat [ content; backdrop ], images
;;

Expand Down
2 changes: 1 addition & 1 deletion app/capymanga/src/capymanga.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ open! Core
open Bonsai
open Capytui

val app : (Node.t * Image.t list) Computation.t
val app : local_ Bonsai.graph -> (Node.t * Image.t list) Bonsai.t
val command : Command.t

module For_testing : sig
Expand Down
Loading

0 comments on commit 35da0c7

Please sign in to comment.