-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
saving my progress (not much progress...)
- Loading branch information
Showing
4 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
open! Core | ||
open Capytui | ||
module Catpuccin = Capytui_catpuccin | ||
open Bonsai.Let_syntax | ||
|
||
let component ~go_back = | ||
(* 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 | ||
Node.vcat | ||
[ Node.hcat | ||
[ Node.text | ||
~attrs: | ||
[ Attr.bold | ||
; Attr.foreground_color (Catpuccin.color ~flavor Mauve) | ||
; Attr.background_color (Catpuccin.color ~flavor Crust) | ||
] | ||
"Capymanga" | ||
; Node.text | ||
~attrs: | ||
[ Attr.foreground_color (Catpuccin.color ~flavor Flamingo) | ||
; Attr.background_color (Catpuccin.color ~flavor Crust) | ||
] | ||
" 2024" | ||
] | ||
; Node.hcat | ||
[ Node.text | ||
~attrs: | ||
[ Attr.foreground_color (Catpuccin.color ~flavor Text) | ||
; Attr.background_color (Catpuccin.color ~flavor Crust) | ||
] | ||
"powered by " | ||
; Node.text | ||
~attrs: | ||
[ Attr.bold | ||
; Attr.foreground_color (Catpuccin.color ~flavor Teal) | ||
; Attr.background_color (Catpuccin.color ~flavor Crust) | ||
] | ||
"MangaDex" | ||
] | ||
] | ||
in | ||
let%sub view = | ||
let%arr dimensions = dimensions | ||
and view = view in | ||
Node.center ~within:dimensions view | ||
in | ||
let%sub handler = | ||
let%arr go_back = 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 | ||
{ Component.view; handler; images = [] } | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
open! Core | ||
open Bonsai | ||
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%arr { height; width } = dimensions | ||
and flavor = 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%sub { view; images; handler } = | ||
let%arr page = page in | ||
match%sub page with | ||
| Manga_search { title } -> | ||
Manga_search.component ~dimensions ~title ~set_page | ||
| Manga_view { manga } -> | ||
Manga_viewer.component ~dimensions ~manga ~set_page ~go_back | ||
| Chapter_view { chapter } -> | ||
Chapter_viewer.component ~dimensions ~chapter ~go_back | ||
| About_page -> About.component ~go_back | ||
in | ||
let%sub () = Capytui.listen_to_events handler in | ||
let%arr view = view | ||
and images = images in | ||
view, images | ||
;; | ||
|
||
let app = | ||
Loading_state.register | ||
@@ Scanlation_group_cache.register | ||
@@ | ||
let%sub { page; set_page; go_back } = | ||
Navigation.component (Page.Manga_search { title = None }) | ||
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 | ||
Node.zcat [ content; backdrop ], images | ||
;; | ||
|
||
let command = | ||
let open Async in | ||
Command.async_or_error | ||
~summary:{|Capy manga!|} | ||
[%map_open.Command | ||
let () = return () in | ||
fun () -> | ||
let open Deferred.Or_error.Let_syntax in | ||
let app = | ||
app | ||
|> Outside_world.Manga_cover.register_real | ||
|> Outside_world.Manga_search.register_real | ||
|> Outside_world.Author.register_real | ||
|> Outside_world.Chapter_feed.register_real | ||
|> Outside_world.Chapter_images.register_real | ||
|> Outside_world.Scanlation_group.register_real | ||
in | ||
let%bind () = Capytui.start_with_images app in | ||
Deferred.Or_error.return ()] | ||
;; | ||
|
||
module For_testing = struct | ||
module Outside_world = Outside_world | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
open! Core | ||
open Bonsai | ||
|
||
type t = | ||
{ write_file : filename:string -> contents:string -> unit Effect.t | ||
; delete_file : filename:string -> unit Effect.t | ||
; curl_uri : uri:Uri.t -> string Effect.t | ||
} | ||
|
||
let default_unregistered = | ||
let fail_unregistered () = | ||
failwith | ||
"BUG in capymanga: Image prefetcher dynamic variable not registered!" | ||
in | ||
let write_file ~filename:_ ~contents:_ = fail_unregistered () in | ||
let delete_file ~filename:_ = fail_unregistered () in | ||
let curl_uri ~uri:_ = fail_unregistered () in | ||
{ write_file; delete_file; curl_uri } | ||
;; | ||
|
||
let variable = | ||
Dynamic_scope.create | ||
~name:"capymanga-image-prefetcher-outside-world-interactions" | ||
~fallback:default_unregistered | ||
() | ||
;; | ||
|
||
let register_real x = | ||
let write_file ~filename ~contents = | ||
let open Async.Deferred.Let_syntax in | ||
Capytui.Effect.of_deferred_fun | ||
(fun () -> | ||
let%bind writer = Async.Writer.open_file filename in | ||
Async.Writer.write writer contents; | ||
let%bind () = Async.Writer.flushed writer in | ||
Async.Writer.close writer) | ||
() | ||
in | ||
let delete_file ~filename = | ||
Capytui.Effect.of_sync_fun (fun () -> Core_unix.remove filename) () | ||
in | ||
let curl_uri ~uri = | ||
let open Async.Deferred.Let_syntax in | ||
Capytui.Effect.of_deferred_fun | ||
(fun () -> | ||
let%bind _, body = Cohttp_async.Client.get uri in | ||
let%bind string = Cohttp_async.Body.to_string body in | ||
return string) | ||
() | ||
in | ||
let real = { write_file; delete_file; curl_uri } in | ||
Bonsai.Dynamic_scope.set variable (Value.return real) ~inside:x | ||
;; | ||
|
||
module For_testing = struct | ||
let register_mock x = x | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
open! Core | ||
open Bonsai | ||
|
||
val register_real : 'a Computation.t -> 'a Computation.t | ||
|
||
module For_testing : sig | ||
val register_mock : 'a Computation.t -> 'a Computation.t | ||
end |