From 3010c7be8d05ead10917a46e14636dd0bdeb508b Mon Sep 17 00:00:00 2001 From: 7sDream Date: Thu, 9 Jan 2025 16:47:21 +0800 Subject: [PATCH] style: fix lint error and typo, update deps --- Cargo.lock | 215 ++++++++++++++++++++++--------- Cargo.toml | 13 +- src/loader/cmap.rs | 16 +-- src/one_char.rs | 2 +- src/preview/terminal/ui/event.rs | 2 +- src/preview/terminal/ui/mod.rs | 26 ++-- 6 files changed, 180 insertions(+), 94 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2f11057..61ea57b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ab_glyph" @@ -114,9 +114,9 @@ checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" [[package]] name = "castaway" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a17ed5635fc8536268e5d4de1e22e81ac34419e5f052d4d51f4e01dcc263fcc" +checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5" dependencies = [ "rustversion", ] @@ -149,7 +149,7 @@ dependencies = [ "strsim", "terminal_size", "unicase", - "unicode-width", + "unicode-width 0.1.12", ] [[package]] @@ -158,7 +158,7 @@ version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "syn", @@ -178,28 +178,38 @@ checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "compact_str" -version = "0.7.1" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f86b9c4c00838774a6d902ef931eff7470720c51d90c2e32cfe15dc304737b3f" +checksum = "3b79c4069c6cad78e2e0cdfcbd26275770669fb39fd308a752dc110e83b9af32" dependencies = [ "castaway", "cfg-if", "itoa", + "rustversion", "ryu", "static_assertions", ] +[[package]] +name = "core_maths" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b02505ccb8c50b0aa21ace0fc08c3e53adebd4e58caa18a36152803c7709a3" +dependencies = [ + "libm", +] + [[package]] name = "crossterm" -version = "0.27.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" +checksum = "829d955a0bb380ef178a640b91779e3987da38c9aea133b20614cfed8cdea9c6" dependencies = [ "bitflags", "crossterm_winapi", - "libc", "mio", "parking_lot", + "rustix", "signal-hook", "signal-hook-mio", "winapi", @@ -214,6 +224,41 @@ dependencies = [ "winapi", ] +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "either" version = "1.11.0" @@ -253,6 +298,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "fontconfig-parser" version = "0.5.6" @@ -264,16 +315,16 @@ dependencies = [ [[package]] name = "fontdb" -version = "0.16.2" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0299020c3ef3f60f526a4f64ab4a3d4ce116b1acbf24cdd22da0068e5d81dc3" +checksum = "457e789b3d1202543297a350643cf459f836cade38934e7a4cf6a39e7cde2905" dependencies = [ "fontconfig-parser", "log", "memmap2", "slotmap", "tinyvec", - "ttf-parser 0.20.0", + "ttf-parser 0.25.1", ] [[package]] @@ -282,7 +333,6 @@ version = "0.4.4-alpha.1" dependencies = [ "ab_glyph", "clap", - "crossterm", "env_logger", "fontdb", "grid", @@ -292,7 +342,7 @@ dependencies = [ "range-set-blaze", "ratatui", "thiserror", - "ttf-parser 0.21.0", + "ttf-parser 0.25.1", "tui-input", ] @@ -318,12 +368,6 @@ dependencies = [ "allocator-api2", ] -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "heck" version = "0.5.0" @@ -332,9 +376,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "httparse" -version = "1.8.0" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] name = "humantime" @@ -342,12 +386,31 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "indoc" version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" +[[package]] +name = "instability" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "894813a444908c0c8c0e221b041771d107c4a21de1d317dc49bcc66e3c9e5b3f" +dependencies = [ + "darling", + "indoc", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.0" @@ -363,6 +426,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -371,9 +443,15 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "libc" -version = "0.2.154" +version = "0.2.169" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" + +[[package]] +name = "libm" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" [[package]] name = "linux-raw-sys" @@ -423,14 +501,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.11" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" dependencies = [ "libc", "log", "wasi", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -497,18 +575,18 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] @@ -520,29 +598,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8421b5d459262eabbe49048d362897ff3e3830b44eac6cfe341d6acb2f0f13d2" dependencies = [ "gen_ops", - "itertools", + "itertools 0.12.1", "num-integer", "num-traits", ] [[package]] name = "ratatui" -version = "0.26.2" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a564a852040e82671dc50a37d88f3aa83bbc690dfc6844cfe7a2591620206a80" +checksum = "eabd94c2f37801c20583fc49dd5cd6b0ba68c716787c2dd6ed18571e1e63117b" dependencies = [ "bitflags", "cassowary", "compact_str", "crossterm", "indoc", - "itertools", + "instability", + "itertools 0.13.0", "lru", "paste", - "stability", "strum", "unicode-segmentation", - "unicode-width", + "unicode-truncate", + "unicode-width 0.2.0", ] [[package]] @@ -632,9 +711,9 @@ dependencies = [ [[package]] name = "signal-hook-mio" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" +checksum = "34db1a06d485c9142248b7a054f034b349b212551f3dfd19c94d45a754a217cd" dependencies = [ "libc", "mio", @@ -665,16 +744,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "stability" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ff9eaf853dec4c8802325d8b6d3dffa86cc707fd7a1a4cdbf416e13b061787a" -dependencies = [ - "quote", - "syn", -] - [[package]] name = "static_assertions" version = "1.1.0" @@ -689,20 +758,20 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "strum" -version = "0.26.2" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" dependencies = [ "strum_macros", ] [[package]] name = "strum_macros" -version = "0.26.2" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", "quote", "rustversion", @@ -711,9 +780,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.61" +version = "2.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c993ed8ccba56ae856363b1845da7266a7cb78e1d146c8a32d54b45a8b831fc9" +checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a" dependencies = [ "proc-macro2", "quote", @@ -773,18 +842,21 @@ checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" [[package]] name = "ttf-parser" -version = "0.21.0" +version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb71ffab0ca84cecd986dd52e873c8d0b013f3d5d9ce25a6f7d0513ed933d562" +checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31" +dependencies = [ + "core_maths", +] [[package]] name = "tui-input" -version = "0.8.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e785f863a3af4c800a2a669d0b64c879b538738e352607e2624d03f868dc01" +checksum = "e5d1733c47f1a217b7deff18730ff7ca4ecafc5771368f715ab072d679a36114" dependencies = [ - "crossterm", - "unicode-width", + "ratatui", + "unicode-width 0.2.0", ] [[package]] @@ -808,12 +880,29 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +[[package]] +name = "unicode-truncate" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3644627a5af5fa321c95b9b235a72fd24cd29c648c2c379431e6628655627bf" +dependencies = [ + "itertools 0.13.0", + "unicode-segmentation", + "unicode-width 0.1.12", +] + [[package]] name = "unicode-width" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" +[[package]] +name = "unicode-width" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" + [[package]] name = "utf8parse" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index ce26a86..2d980d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,10 +25,10 @@ grid = "0.13" clap = { version = "4.4", features = ["derive", "unicode", "wrap_help"] } # Font loader -fontdb = "0.16" +fontdb = "0.23" # Font parser -ttf-parser = "0.21" +ttf-parser = "0.25" # Filter fonts range-set-blaze = "0.1.16" @@ -38,17 +38,14 @@ range-set-blaze = "0.1.16" ab_glyph = "0.2" # Termianal UI -ratatui = "0.26" - -# Terminal events -crossterm = "0.27" +ratatui = "0.29" # Input widget for filter in TUI -tui-input = "0.8.0" +tui-input = "0.11" # Home-made single thread HTTP server for preview fonts in browser. # Alternative: output a html file into temp dir and open it -httparse = "1.8" +httparse = "1.9" # Logger log = { version = "0.4", features = ["release_max_level_off"] } diff --git a/src/loader/cmap.rs b/src/loader/cmap.rs index 3bd2a7c..ebad370 100644 --- a/src/loader/cmap.rs +++ b/src/loader/cmap.rs @@ -24,7 +24,7 @@ use super::{ }; pub struct CMapTable<'a> { - subtables: Vec>, + sub_tables: Vec>, } impl<'a> CMapTable<'a> { @@ -32,22 +32,22 @@ impl<'a> CMapTable<'a> { let cmap_data = rf.table(CMAP_TAG).ok_or(MISSING_CMAP_TABLE)?; let table = cmap::Table::parse(cmap_data).ok_or(BROKEN_CMAP_TABLE)?; - let mut subtables = vec![]; + let mut sub_tables = vec![]; for i in 0..table.subtables.len() { - let subtable = table.subtables.get(i).ok_or(BROKEN_CMAP_TABLE)?; - if subtable.is_unicode() { - subtables.push(subtable) + let sub_table = table.subtables.get(i).ok_or(BROKEN_CMAP_TABLE)?; + if sub_table.is_unicode() { + sub_tables.push(sub_table) } } - Ok(Self { subtables }) + Ok(Self { sub_tables }) } pub fn glyph_index(&self, c: char) -> Option { - self.subtables + self.sub_tables .iter() - .filter_map(|subtable| subtable.glyph_index(c as u32)) + .filter_map(|sub_table| sub_table.glyph_index(c as u32)) .next() } } diff --git a/src/one_char.rs b/src/one_char.rs index 7a16a8e..1dd9cdc 100644 --- a/src/one_char.rs +++ b/src/one_char.rs @@ -99,7 +99,7 @@ impl OneChar { let c1 = c1.expect("at least one char because of the take_while"); let c2 = c2.ok_or(ParseError::UTF8BytesStrCantAlignToBytes)?; if c1.is_ascii_hexdigit() && c2.is_ascii_hexdigit() { - Ok((c1.to_digit(16).expect("hexdigit") << 4 + Ok(((c1.to_digit(16).expect("hexdigit") << 4) | c2.to_digit(16).expect("hexdigit")) as u8) } else { Err(ParseError::InvalidDigitInRadix(16)) diff --git a/src/preview/terminal/ui/event.rs b/src/preview/terminal/ui/event.rs index c2e6669..c9c017f 100644 --- a/src/preview/terminal/ui/event.rs +++ b/src/preview/terminal/ui/event.rs @@ -18,7 +18,7 @@ use std::{io::Result as IoResult, ops::Deref, sync::mpsc, thread, time::Duration}; -use crossterm::event::{self, Event, KeyEvent, KeyEventKind}; +use ratatui::crossterm::event::{self, Event, KeyEvent, KeyEventKind}; #[derive(Copy, Clone)] pub enum TerminalEvent { diff --git a/src/preview/terminal/ui/mod.rs b/src/preview/terminal/ui/mod.rs index 71da8ec..5e01396 100644 --- a/src/preview/terminal/ui/mod.rs +++ b/src/preview/terminal/ui/mod.rs @@ -25,16 +25,16 @@ use std::{ time::Duration, }; -use crossterm::{ - event::{Event, KeyCode as CtKeyCode, KeyEvent, KeyModifiers as CtKM}, - execute, - terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode}, -}; use ratatui::{ + Frame, Terminal, backend::CrosstermBackend, + crossterm::{ + event::{Event, KeyCode as CtKeyCode, KeyEvent, KeyModifiers as CtKM}, + execute, + terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode}, + }, layout::{Alignment, Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style}, - terminal::{Frame, Terminal}, text::{Line, Span, Text}, widgets::{Block, Borders, List, ListItem, Paragraph, canvas::Canvas}, }; @@ -109,7 +109,7 @@ impl<'a> UI<'a> { let style = if let Some(WhichInput::Search) = self.editing { let x = searchbox.visual_cursor().max(scroll) - scroll; - f.set_cursor(area.x + 1 + x as u16, area.y + 1); + f.set_cursor_position((area.x + 1 + x as u16, area.y + 1)); Style::default().fg(Color::Yellow) } else { @@ -331,7 +331,7 @@ impl<'a> UI<'a> { let layout = Layout::default() .direction(Direction::Vertical) .constraints([Constraint::Fill(1), Constraint::Length(4)].as_ref()) - .split(f.size()); + .split(f.area()); let main = layout[0]; let status_bar = layout[1]; @@ -343,16 +343,16 @@ impl<'a> UI<'a> { .constraints([Constraint::Length(list_width), Constraint::Min(24)].as_ref()) .split(main); - let side_pannel = main[0]; + let side_panel = main[0]; let canvas = main[1]; - let side_pannel = Layout::default() + let side_panel = Layout::default() .direction(Direction::Vertical) .constraints([Constraint::Fill(1), Constraint::Length(3)]) - .split(side_pannel); + .split(side_panel); - let list = side_pannel[0]; - let searchbox = side_pannel[1]; + let list = side_panel[0]; + let searchbox = side_panel[1]; let width = u32::from(canvas.width.saturating_sub(2)); let height = u32::from(canvas.height.saturating_sub(2));