diff --git a/app/capymanga/src/chapter_viewer.ml b/app/capymanga/src/chapter_viewer.ml index 68ac199..c76a9ca 100644 --- a/app/capymanga/src/chapter_viewer.ml +++ b/app/capymanga/src/chapter_viewer.ml @@ -118,10 +118,18 @@ let image_viewer let%arr dimensions = dimensions and url = url and is_fullscreen = is_full_screen in - let dimensions = { dimensions with height = dimensions.height - 2 } in + (* NOTE: We subtract 2 from the height and the width so that tmux works + properly. There seems to be some misunderstanding between kitty and + tmux on where the screen starts and ends leading to funny visual + artifacts. *) + let dimensions = + { Dimensions.height = dimensions.height - 2 + ; width = dimensions.width - 2 + } + in { Image.url ; row = (if is_fullscreen then 1 else 3) - ; column = 0 + ; column = 1 ; dimensions ; scale = true } diff --git a/app/capymanga/test/test_data/dune b/app/capymanga/test/test_data/dune index 6642001..4e9d640 100644 --- a/app/capymanga/test/test_data/dune +++ b/app/capymanga/test/test_data/dune @@ -13,6 +13,7 @@ ./mangadex_author_test_data.json ./mob_psycho_mangadex_chapter_feed_test_data.json ./mangadex_scanlation_group_test_data.json + ./mangadex_manga_chapter_images_dummy.json ;; ) (action diff --git a/app/capymanga/test/test_data/mangadex_api_dummy_data.ml b/app/capymanga/test/test_data/mangadex_api_dummy_data.ml index cc839fa..3c2b152 100644 --- a/app/capymanga/test/test_data/mangadex_api_dummy_data.ml +++ b/app/capymanga/test/test_data/mangadex_api_dummy_data.ml @@ -40,3 +40,10 @@ let scanlation_group_dummy_response : Scanlation_group.t Entity.t Lazy.t = (Yojson.Safe.from_string Embedded_files.mangadex_scanlation_group_test_data_dot_json)) ;; + +let mangadex_dummy_chapter_images : Chapter_images.t Lazy.t = + lazy + (Chapter_images.t_of_yojson + (Yojson.Safe.from_string + Embedded_files.mangadex_manga_chapter_images_dummy_dot_json)) +;; diff --git a/app/capymanga/test/test_data/mangadex_api_dummy_data.mli b/app/capymanga/test/test_data/mangadex_api_dummy_data.mli index d59056e..64881d4 100644 --- a/app/capymanga/test/test_data/mangadex_api_dummy_data.mli +++ b/app/capymanga/test/test_data/mangadex_api_dummy_data.mli @@ -6,3 +6,4 @@ val one_punch_man_dummy_cover_response : Cover.t Entity.t Lazy.t val one_punch_man_dummy_author_response : Author.t Entity.t Lazy.t val mob_psycho_dummy_chapter_feed_response : Chapter.t Collection.t Lazy.t val scanlation_group_dummy_response : Scanlation_group.t Entity.t Lazy.t +val mangadex_dummy_chapter_images : Chapter_images.t Lazy.t diff --git a/app/capymanga/test/test_data/mangadex_manga_chapter_images_dummy.json b/app/capymanga/test/test_data/mangadex_manga_chapter_images_dummy.json new file mode 100644 index 0000000..ba1f01a --- /dev/null +++ b/app/capymanga/test/test_data/mangadex_manga_chapter_images_dummy.json @@ -0,0 +1,65 @@ +{ + "result": "ok", + "baseUrl": "https://cmdxd98sb0x3yprd.mangadex.network", + "chapter": { + "hash": "ad9bc794465f484c0e0a83d2e1203ec9", + "data": [ + "1-0355bd816263921442f6403307d3c0eee024258c285e2e4d25403cdeb1c7b3de.png", + "2-2fba3ab1a8b73d414d857ded1692e9ec0dfda4787dd62134b4669b39c39c816a.png", + "3-3a1bd44846b9f54d0459dcaf4d98809fa12af749cbecb04f487f3e0fba652937.png", + "4-1e7aac9402dcc1e810a924b6ef4ee38b65529d65fa1cd35632ade44037bf0982.png", + "5-e42b7fc14231630f03691e348c84fcf994aeb0ff8c85f6038efc7c44172e2fd2.png", + "6-be4981541a94e04aa684bb9534c4d5c49150286c3c19abc83536cb30dccbb0c3.png", + "7-10f11f1a477e56556ad61114fac3e392835c53dc9dc8d9bd4072f0fc153ad09f.png", + "8-9829b266dd7500378ebb101661db2068b4f89b98a8e64a9ddf752a3e5c3303fc.png", + "9-b5420a3e6828f1433b02f9fd18be38d8ce46b5551b25f2b2ad8ec31395869dd3.png", + "10-e9a2198d4d836bd1ab810e778862eaef6e82acca7c8bfead4e0ece5f7c3508f4.png", + "11-2bc81b0e60ec7e56cc888204201df63bf8466601b829c06d1ae398fed10ffa82.png", + "12-36fca58fadaa973e527ac1da0509e711eded3054343b7d99040eb7c34d127f43.png", + "13-91a44d79fcbff6c3b0a59828a1f59341c5a6bf193388740be21e27e851092a2d.png", + "14-1b2a1461772058aaf72e8bc8364d8246d2c94aac6b225ce7097262afa3c81238.png", + "15-bda8741f4ff574f2e3e5dc5972b4113d2fe76df4baff408bbcc8d37f64a72355.png", + "16-d9f2a49d6875c5de99e9e10f531f31c9aef536ab4ee70eeaa409b5ffed4fb25f.png", + "17-b1074943b6d75a6dc0ec7b0b6b7a471cdcf78a5498c42575a7089067ae04ec82.png", + "18-dc7cdcd53a3d99de7badcb5bcd7fd6223b965988034026f2945bbe9543881e78.png", + "19-4d2cd7ddc041a8b06e510f3dc8cbd3cd138d0bb2eea9548a15284437fe64c1a3.png", + "20-f9d9a5899eb8b5980c2b21d075c888adcf19cc3b7d11c074c9bba9dd04938151.png", + "21-6dfb74445b3c243f61f8acb16740f8b2324078a6468920d7cf8a86652f94339e.png", + "22-aca0e178e7da4f95730ecf8d93eeab620d976b9d257011c3d89e0027dd49f1fe.png", + "23-1402b1df9446c09a1180485c0c64866e5d5cd880b5252de8748ff6ec9f8942b1.png", + "24-9b20f84efbd574d147dd86884ffd80bc5dc1e942f58a2dc7264827abbb823b1c.png", + "25-053a29f2c197236859f0a4cc065b652f66edb3743a6da7966cd4e501dbb954c4.png", + "26-67f61570594fa23e6163365e68b286a38ef532d6a9cb802ced2da93d3df03c86.png", + "27-191f57130a5d2a1b1af1e48ba4be7d16ffe7c3b68cb5dd84e0bfcddb0a2d8da4.png" + ], + "dataSaver": [ + "1-2b06f7cba184a57f4ad9ccb976d8d8197d979a5bcf15fa79c0f8003a17713c6c.jpg", + "2-dd831260cf6804034319c679dfe22c28099a772c95caa2422181d4e0736bf605.jpg", + "3-229f4bb8b43387ec50a474ca4b1cff2ac85592561e949d1d1bd4745044127dd9.jpg", + "4-6033d951d971edb62d1047c64d6986fc34958891ccab7a543c43cf0c81ed1f0e.jpg", + "5-d7b9f4d5f7efe971954d8407bba64af8f0adb4557a00fbc62f5a540984c39070.jpg", + "6-1fc676be305982adfaf3c1ba2cdb84e62a36e43558ce0ef02d4bb087569d1da8.jpg", + "7-41881bca3928563112037f5f5cc4704e98408d834c01487d859a73fc29cde805.jpg", + "8-a6c1a550bd1d3b31130fbd3327a7884d71980b3d1c13f2cd95f7223dea569288.jpg", + "9-c43b30f06285dfe843d7a5cd01711bcd47903da5943130f4117f34cd018aa86c.jpg", + "10-34859a6dcf5eca58b8a1584a7c0be7ea87b8cc74e346115dbd77ca315030c20c.jpg", + "11-fd8a88346da1747fcdeccc62ed5a90c4825e361f0b6de318b0e83327f9a8b574.jpg", + "12-f84efba634e91a159f15e5af4e383121ea0355ec2ecf6382f2c95993fee236da.jpg", + "13-094807dc471bb570f85a0476eb5f0d3fd709c7aa720b42fe79069869d8aa11b7.jpg", + "14-19344674d2ac6b9948fac2c7842cf4f55c3df11e0f8f0806c5e2af528dfee48a.jpg", + "15-69e5d6dd9b2e6fc49286ffa77266f627c28a80bf14579b05885b4749fc55ed58.jpg", + "16-6b694fd02a9abc77abc1a5473ea3a617224628bbf92fe2fe88ff3924b36e1f71.jpg", + "17-d4a4f474e82be7f8bbb022c5ce692a343bc1d27df558b1976f31be6c08694085.jpg", + "18-7f20036e2a6f7ea66257ffb722f41a57dcda6a65876b87878a69788c94491684.jpg", + "19-76e9828d881f559ab0831e2f42ed1e57ef370e5268d2c885a1c4d1813350ca5b.jpg", + "20-e8cc8206ca88e3ac11222c27fbb5b41f12d5b3700b8749622b363ae7292f0965.jpg", + "21-9b98aaef63b6dad88a56df98a80f7c21aa64f9037f7561ee1b6ec6433a13b937.jpg", + "22-83fda1b8567ba85c69b31fa11758699add6782c0d6c6e15ddfb3664d77014d19.jpg", + "23-dd8eb8c54caaad0d3ef6fb64cecf4fb9cc3a2b641842e5d9ecb9a3d5b37a59d5.jpg", + "24-f224ce649ecc3218992ceefad9e2a19a55c584ffa4aa7011799d78ea9f4b6fbd.jpg", + "25-8409ad3563954a9ebfe8bfd4058386d110320fcc7de2824158e2b3744b6e3d5a.jpg", + "26-1c013a24e5e62a4947ca39b6fa3417ee365bf272abe488990ed17e4cd08e03ab.jpg", + "27-872566fd7d3b16e31a3e0796322dda429bf378b8c9a15af22fcfc95a4f3e0ed3.jpg" + ] + } +} diff --git a/app/capymanga/test/test_util.ml b/app/capymanga/test/test_util.ml index 6b529fe..4327966 100644 --- a/app/capymanga/test/test_util.ml +++ b/app/capymanga/test/test_util.ml @@ -31,6 +31,11 @@ let default_scalation_group ~scanlation_group_id:(_ : string) = (Ok (force Mangadex_api_dummy_data.scanlation_group_dummy_response)) ;; +let default_manga_chapter_images ~chapter_id:(_ : string) = + Effect.return + (Ok (force Mangadex_api_dummy_data.mangadex_dummy_chapter_images)) +;; + let mock_chainsaw_man_response = lazy (Manga.t_of_yojson @@ -297,6 +302,7 @@ let create_handle ?(author = Value.return default_author) ?(chapter_feed = Value.return default_chapter_feed) ?(scanlation_group = Value.return default_scalation_group) + ?(chapter_images = Value.return default_manga_chapter_images) ?(initial_dimensions = { Dimensions.width = 120; height = 30 }) () = @@ -333,6 +339,14 @@ let create_handle in scanlation_group ~scanlation_group_id in + let chapter_images = + let%map chapter_images = chapter_images in + fun ~chapter_id -> + let%bind.Effect () = + Effect.print_s [%message "[chapter_id]" (chapter_id : string)] + in + chapter_images ~chapter_id + in let chapter_feed = let%map chapter_feed = chapter_feed in fun ~manga_id ~ascending ?limit ?offset () -> @@ -353,6 +367,7 @@ let create_handle @@ Outside_world.Author.register_mock author @@ Outside_world.Chapter_feed.register_mock chapter_feed @@ Outside_world.Scanlation_group.register_mock scanlation_group + @@ Outside_world.Chapter_images.register_mock chapter_images @@ let%sub image, images = Capymanga.app in let%arr image = image diff --git a/app/capymanga/test/test_util.mli b/app/capymanga/test/test_util.mli index 8b8fafc..b87f0c5 100644 --- a/app/capymanga/test/test_util.mli +++ b/app/capymanga/test/test_util.mli @@ -18,6 +18,7 @@ val create_handle -> ?author:Outside_world.Author.t Value.t -> ?chapter_feed:Outside_world.Chapter_feed.t Value.t -> ?scanlation_group:Outside_world.Scanlation_group.t Value.t + -> ?chapter_images:Outside_world.Chapter_images.t Value.t -> ?initial_dimensions:Dimensions.t -> unit -> (Result_spec.t, Result_spec.incoming) Handle.t diff --git a/app/capymanga/test/test_viewer.ml b/app/capymanga/test/test_viewer.ml index 65d2df7..788aa04 100644 --- a/app/capymanga/test/test_viewer.ml +++ b/app/capymanga/test/test_viewer.ml @@ -226,5 +226,83 @@ let%expect_test "Manga viewer" = │ one punch. He decides to put his new Vol 16 Ch 100.01 ① scanlation by Hunlight Scans │ │ skill to good use by becoming a hero. Vol 6 Ch 45 scanlation by Hunlight Scans │ └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ + |}]; + Capytui_test.send_event handle (`Key (`Enter, [])); + Handle.recompute_view handle; + Handle.show handle; + [%expect + {| + ([chapter_id] (chapter_id 00e9c6ab-0ff6-4967-9d86-448e6245e61b)) + ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ │ + │ Capymanga powered by Mangadex ⣾ Backspace go back f go fullscreen 1/27 │ + │ │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .............................((url https://cmdxd98sb0x3yprd.mangadex.network/data-saver............................. │ + │ ............................./ad9bc794465f484c0e0a83d2e1203ec9/1-2b06f7cba184a57f4ad9cc............................. │ + │ .............................b976d8d8197d979a5bcf15fa79c0f8003a17713c6c.jpg)(row 3)(col............................. │ + │ .............................umn 1)(dimensions((height 25)(width 116)))(scale true))................................ │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ .................................................................................................................... │ + │ │ + │ │ + └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ + |}]; + (* Testing going full screen. *) + Capytui_test.send_event handle (`Key (`ASCII 'f', [])); + Handle.recompute_view handle; + Handle.show handle; + [%expect + {| + ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ .............................((url https://cmdxd98sb0x3yprd.mangadex.network/data-saver/.............................. │ + │ .............................ad9bc794465f484c0e0a83d2e1203ec9/1-2b06f7cba184a57f4ad9ccb9.............................. │ + │ .............................76d8d8197d979a5bcf15fa79c0f8003a17713c6c.jpg)(row 1)(column.............................. │ + │ ............................. 1)(dimensions((height 28)(width 118)))(scale true))..................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ ...................................................................................................................... │ + │ │ + └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ |}] ;;