From aea8522c83cf09a84b95f66e283f8223d20bea8a Mon Sep 17 00:00:00 2001 From: Zackary Troop Date: Sat, 24 Feb 2024 23:47:18 -0500 Subject: [PATCH] Replace tui with ratatui lib --- Cargo.lock | 230 ++++++++++++++++++++++++++++++++++++++++++++------ Cargo.toml | 4 +- src/viewer.rs | 24 +++--- 3 files changed, 217 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3932cd7..00700ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,24 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d713b3834d76b85304d4d525563c1276e2e30dc97cc67bfb4585a4a29fc2c89f" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "autocfg" version = "1.1.0" @@ -32,22 +50,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "crossterm" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" -dependencies = [ - "bitflags 1.3.2", - "crossterm_winapi", - "libc", - "mio", - "parking_lot", - "signal-hook", - "signal-hook-mio", - "winapi", -] - [[package]] name = "crossterm" version = "0.27.0" @@ -75,10 +77,47 @@ dependencies = [ [[package]] name = "dead-ringer" -version = "1.0.1" +version = "1.0.2" +dependencies = [ + "crossterm", + "ratatui", +] + +[[package]] +name = "either" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash", + "allocator-api2", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "indoc" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8" + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ - "crossterm 0.27.0", - "tui", + "either", ] [[package]] @@ -103,6 +142,15 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "lru" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3262e75e648fce39813cb56ac41f3c3e3f65217ebf3844d818d1f9398cfb0dc" +dependencies = [ + "hashbrown", +] + [[package]] name = "mio" version = "0.8.10" @@ -115,6 +163,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + [[package]] name = "parking_lot" version = "0.12.1" @@ -138,6 +192,49 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ratatui" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5659e52e4ba6e07b2dad9f1158f578ef84a73762625ddb51536019f34d180eb" +dependencies = [ + "bitflags 2.4.2", + "cassowary", + "crossterm", + "indoc", + "itertools", + "lru", + "paste", + "stability", + "strum", + "unicode-segmentation", + "unicode-width", +] + [[package]] name = "redox_syscall" version = "0.4.1" @@ -147,6 +244,12 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + [[package]] name = "scopeguard" version = "1.2.0" @@ -190,18 +293,65 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" [[package]] -name = "tui" -version = "0.19.0" +name = "stability" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccdd26cbd674007e649a272da4475fb666d3aa0ad0531da7136db6fab0e5bad1" +checksum = "ebd1b177894da2a2d9120208c3386066af06a488255caabc5de8ddca22dbc3ce" dependencies = [ - "bitflags 1.3.2", - "cassowary", - "crossterm 0.25.0", - "unicode-segmentation", - "unicode-width", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.50", ] +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + [[package]] name = "unicode-segmentation" version = "1.10.1" @@ -214,6 +364,12 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -307,3 +463,23 @@ name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.50", +] diff --git a/Cargo.toml b/Cargo.toml index 43c88be..095cf48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dead-ringer" -version = "1.0.1" +version = "1.0.2" edition = "2021" description = "Dring, A Binary Diff Utility" authors = ["Zackary Troop"] @@ -10,5 +10,5 @@ name = "dring" path = "src/main.rs" [dependencies] -tui = { version = "0.19.0", features = ["crossterm"] } +ratatui = { version = "0.25.0", features = ["crossterm"] } crossterm = "0.27" \ No newline at end of file diff --git a/src/viewer.rs b/src/viewer.rs index 15073b0..9315171 100644 --- a/src/viewer.rs +++ b/src/viewer.rs @@ -3,15 +3,15 @@ use crossterm::{ execute, terminal::{disable_raw_mode, enable_raw_mode, Clear, ClearType}, }; -use std::io; -use tui::{ +use ratatui::{ backend::CrosstermBackend, - layout::{Constraint, Direction, Layout}, + layout::{Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style}, - text::{Span, Spans, Text}, + text::{Line, Span, Text}, widgets::{Block, Borders, Paragraph}, - Terminal, + Frame, Terminal, }; +use std::io; pub struct FileDiffViewer { diffs: Vec<(usize, u8)>, @@ -66,7 +66,7 @@ impl FileDiffViewer { Ok(()) } - fn draw(&self, f: &mut tui::Frame) { + fn draw(&self, f: &mut Frame) { let size = f.size(); let bytes_per_line = (size.width / 6) as usize; let lines = (size.height - 3) as usize; @@ -110,7 +110,7 @@ impl FileDiffViewer { Span::styled(format!("{:02x} ", byte), style) }) .collect(); - Spans::from(spans) + Line::from(spans) }) .collect::>(); @@ -141,7 +141,7 @@ impl FileDiffViewer { Span::styled(ascii_char.to_string(), style) }) .collect(); - Spans::from(spans) + Line::from(spans) }) .collect::>(); @@ -163,7 +163,7 @@ impl FileDiffViewer { } } - fn move_cursor_down(&mut self, terminal_size: &tui::layout::Rect) { + fn move_cursor_down(&mut self, terminal_size: &Rect) { let bytes_per_line = (terminal_size.width / 6) as usize; let lines = (terminal_size.height - 5) as usize; let max_cursor_pos = self.diffs.len().saturating_sub(1); @@ -182,7 +182,7 @@ impl FileDiffViewer { } } - fn move_cursor_up(&mut self, _terminal_size: &tui::layout::Rect) { + fn move_cursor_up(&mut self, _terminal_size: &Rect) { let bytes_per_line = (_terminal_size.width / 6) as usize; if self.cursor_pos >= bytes_per_line { @@ -195,7 +195,7 @@ impl FileDiffViewer { } } - fn move_cursor_right(&mut self, terminal_size: &tui::layout::Rect) { + fn move_cursor_right(&mut self, terminal_size: &Rect) { let bytes_per_line = (terminal_size.width / 6) as usize; let lines = (terminal_size.height - 5) as usize; let max_cursor_pos = self.diffs.len().saturating_sub(1); @@ -212,7 +212,7 @@ impl FileDiffViewer { } } - fn move_cursor_left(&mut self, terminal_size: &tui::layout::Rect) { + fn move_cursor_left(&mut self, terminal_size: &Rect) { let bytes_per_line = (terminal_size.width / 6) as usize; // Move cursor left if not at the start