From 5763e5bc21c93ed94f23e29104d00451040f680a Mon Sep 17 00:00:00 2001 From: Gipson62 Date: Fri, 30 Aug 2024 20:35:52 +0200 Subject: [PATCH 1/4] fix: issues with windows displaying images --- Cargo.lock | 144 ++++++++++++++++++++++++++++++++++++++---------- Cargo.toml | 1 + src/view/app.rs | 3 +- 3 files changed, 117 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 619360d..bc536c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -365,7 +365,7 @@ dependencies = [ "js-sys", "num-traits", "wasm-bindgen", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -1135,7 +1135,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -1588,6 +1588,7 @@ dependencies = [ "toml", "tui-input", "tui-widget-list", + "win-term", "zip 2.1.6", ] @@ -1893,7 +1894,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -3155,6 +3156,16 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" +[[package]] +name = "win-term" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a52476e4dd2a481b877596fbb43182d28d5efe2c3e50791fe73f25d391ceab5" +dependencies = [ + "windows", + "windows-sys 0.59.0", +] + [[package]] name = "winapi" version = "0.3.9" @@ -3177,13 +3188,77 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core 0.58.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", ] [[package]] @@ -3201,7 +3276,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] @@ -3221,18 +3305,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -3243,9 +3327,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -3255,9 +3339,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -3267,15 +3351,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -3285,9 +3369,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -3297,9 +3381,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -3309,9 +3393,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -3321,9 +3405,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" diff --git a/Cargo.toml b/Cargo.toml index 666f40f..4bed30f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,3 +45,4 @@ clap = { version = "4.4.5", features = ["derive", "cargo"] } zip = "2.1.6" toml = "0.8.19" epub-builder = "0.7.4" +win-term = "0.1.1" diff --git a/src/view/app.rs b/src/view/app.rs index ad0bc0e..afa0c42 100644 --- a/src/view/app.rs +++ b/src/view/app.rs @@ -285,7 +285,8 @@ fn get_picker() -> Option { fn get_picker() -> Option { // Todo! figure out how to get the size of the terminal on windows // I think with the winapi it is possible - let mut picker = Picker::new((10, 17)); + let size = win_term::get_size_of_the_font().unwrap(); + let mut picker = Picker::new((size.width as u16, size.height as u16)); let protocol = picker.guess_protocol(); From d39930a662bb0bce0d773f3582a91f48dea10824 Mon Sep 17 00:00:00 2001 From: Gipson62 Date: Sat, 31 Aug 2024 19:54:08 +0200 Subject: [PATCH 2/4] fix: issue with the external use of a crate win-term => unsafe windows-sys --- Cargo.lock | 78 ++----------------------------------------------- Cargo.toml | 4 ++- src/main.rs | 1 - src/view/app.rs | 30 +++++++++++++++---- 4 files changed, 30 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc536c1..0308a44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1135,7 +1135,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core 0.52.0", + "windows-core", ] [[package]] @@ -1588,7 +1588,7 @@ dependencies = [ "toml", "tui-input", "tui-widget-list", - "win-term", + "windows-sys 0.59.0", "zip 2.1.6", ] @@ -3156,16 +3156,6 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" -[[package]] -name = "win-term" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a52476e4dd2a481b877596fbb43182d28d5efe2c3e50791fe73f25d391ceab5" -dependencies = [ - "windows", - "windows-sys 0.59.0", -] - [[package]] name = "winapi" version = "0.3.9" @@ -3188,16 +3178,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows" -version = "0.58.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" -dependencies = [ - "windows-core 0.58.0", - "windows-targets 0.52.6", -] - [[package]] name = "windows-core" version = "0.52.0" @@ -3207,60 +3187,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-core" -version = "0.58.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" -dependencies = [ - "windows-implement", - "windows-interface", - "windows-result", - "windows-strings", - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-implement" -version = "0.58.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "windows-interface" -version = "0.58.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "windows-result" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" -dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-strings" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" -dependencies = [ - "windows-result", - "windows-targets 0.52.6", -] - [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 4bed30f..c2d1df8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,4 +45,6 @@ clap = { version = "4.4.5", features = ["derive", "cargo"] } zip = "2.1.6" toml = "0.8.19" epub-builder = "0.7.4" -win-term = "0.1.1" + +[target.'cfg(windows)'.dependencies] +windows-sys = { version = "0.59.0", features = ["Win32_Foundation", "Win32_System_Console", "Win32_UI_HiDpi"]} diff --git a/src/main.rs b/src/main.rs index 97daefc..db100ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -#![forbid(unsafe_code)] #![allow(dead_code)] #![allow(deprecated)] use std::time::Duration; diff --git a/src/view/app.rs b/src/view/app.rs index afa0c42..90210bb 100644 --- a/src/view/app.rs +++ b/src/view/app.rs @@ -280,13 +280,33 @@ fn get_picker() -> Option { }) .filter(|picker| picker.protocol_type != ProtocolType::Halfblocks) } - #[cfg(target_os = "windows")] fn get_picker() -> Option { - // Todo! figure out how to get the size of the terminal on windows - // I think with the winapi it is possible - let size = win_term::get_size_of_the_font().unwrap(); - let mut picker = Picker::new((size.width as u16, size.height as u16)); + use windows_sys::Win32::System::Console::GetConsoleWindow; + use windows_sys::Win32::UI::HiDpi::GetDpiForWindow; + + struct FontSize { + pub width: u16, + pub height: u16, + } + + let size: FontSize = match unsafe { GetDpiForWindow(GetConsoleWindow()) } { + 96 => FontSize { + width: 9, + height: 20, + }, + 120 => FontSize { + width: 12, + height: 25, + }, + 144 => FontSize { + width: 14, + height: 32, + }, + _ => unimplemented!("Other DPIs then 96 (100%), 120 (125%) and 144 (150%) are supported as of now"), + }; + + let mut picker = Picker::new((size.width, size.height)); let protocol = picker.guess_protocol(); From 59e675c5658f15d12bb76da88abbc696c1ba8b93 Mon Sep 17 00:00:00 2001 From: Gipson62 Date: Sat, 31 Aug 2024 21:49:46 +0200 Subject: [PATCH 3/4] fix: adding a default FontSize, so people with unsupported dpi will still have the app running --- src/view/app.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/view/app.rs b/src/view/app.rs index 90210bb..26c85e0 100644 --- a/src/view/app.rs +++ b/src/view/app.rs @@ -289,6 +289,14 @@ fn get_picker() -> Option { pub width: u16, pub height: u16, } + impl Default for FontSize { + fn default() -> Self { + FontSize { + width: 17, + height: 38 + } + } + } let size: FontSize = match unsafe { GetDpiForWindow(GetConsoleWindow()) } { 96 => FontSize { @@ -303,7 +311,7 @@ fn get_picker() -> Option { width: 14, height: 32, }, - _ => unimplemented!("Other DPIs then 96 (100%), 120 (125%) and 144 (150%) are supported as of now"), + _ => FontSize::default(), }; let mut picker = Picker::new((size.width, size.height)); From bd4cdf174660712bca796019a8da4fc8561d8e2c Mon Sep 17 00:00:00 2001 From: josuebarretogit Date: Sat, 31 Aug 2024 17:40:34 -0500 Subject: [PATCH 4/4] chore: format code reminder to automate formatting process and run `cargo fmt --check` only once in workflows --- src/view/app.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/view/app.rs b/src/view/app.rs index 26c85e0..b4ff5e8 100644 --- a/src/view/app.rs +++ b/src/view/app.rs @@ -293,7 +293,7 @@ fn get_picker() -> Option { fn default() -> Self { FontSize { width: 17, - height: 38 + height: 38, } } }