From d63910b7f1f70662f62ae42a266e1f18c62ddc57 Mon Sep 17 00:00:00 2001 From: itsjunetime Date: Sat, 20 Dec 2025 07:24:51 -0600 Subject: [PATCH] Update to edition 2024 --- Cargo.toml | 2 +- examples/color-output.rs | 2 +- examples/static-no-overflow.rs | 2 +- src/core/commands.rs | 2 +- src/core/ev_handler.rs | 10 ++-- src/core/init.rs | 15 +++-- src/core/mod.rs | 5 +- src/core/utils/display/mod.rs | 2 +- src/core/utils/display/tests.rs | 88 +++++++++++++++++++----------- src/dynamic_pager.rs | 2 +- src/input/definitions/keydefs.rs | 2 +- src/input/definitions/mousedefs.rs | 2 +- src/input/hashed_event_register.rs | 2 +- src/input/tests.rs | 2 +- src/pager.rs | 2 +- src/screen/mod.rs | 2 +- src/screen/tests.rs | 2 +- src/search.rs | 18 +++--- src/state.rs | 11 ++-- src/static_pager.rs | 2 +- src/tests.rs | 6 +- 21 files changed, 104 insertions(+), 77 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eb3e2a5e..16caf2fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "minus" version = "5.6.1" authors = ["Arijit Dey "] -edition = "2018" +edition = "2024" license = "MIT OR Apache-2.0" documentation = "https://docs.rs/minus" repository = "https://github.com/AMythicDev/minus" diff --git a/examples/color-output.rs b/examples/color-output.rs index 5a618d1e..ac5cb273 100644 --- a/examples/color-output.rs +++ b/examples/color-output.rs @@ -1,5 +1,5 @@ use crossterm::style::{Color, ResetColor, SetForegroundColor}; -use minus::{error::MinusError, page_all, Pager}; +use minus::{Pager, error::MinusError, page_all}; use std::fmt::Write; fn main() -> Result<(), MinusError> { diff --git a/examples/static-no-overflow.rs b/examples/static-no-overflow.rs index 879c8325..6ae3c90d 100644 --- a/examples/static-no-overflow.rs +++ b/examples/static-no-overflow.rs @@ -1,5 +1,5 @@ use minus::error::MinusError; -use minus::{page_all, Pager}; +use minus::{Pager, page_all}; use std::fmt::Write; fn main() -> Result<(), MinusError> { diff --git a/src/core/commands.rs b/src/core/commands.rs index 22b609a5..3d3ca118 100644 --- a/src/core/commands.rs +++ b/src/core/commands.rs @@ -6,8 +6,8 @@ use std::fmt::Debug; use crate::{ - input::{InputClassifier, InputEvent}, ExitStrategy, LineNumbers, + input::{InputClassifier, InputEvent}, }; #[cfg(feature = "search")] diff --git a/src/core/ev_handler.rs b/src/core/ev_handler.rs index 5ca4dd36..92391d47 100644 --- a/src/core/ev_handler.rs +++ b/src/core/ev_handler.rs @@ -2,17 +2,17 @@ use std::convert::TryInto; use std::io::Write; -use std::sync::{atomic::AtomicBool, Arc}; +use std::sync::{Arc, atomic::AtomicBool}; #[cfg(feature = "search")] use parking_lot::{Condvar, Mutex}; -use super::utils::display::{self, AppendStyle}; use super::CommandQueue; +use super::utils::display::{self, AppendStyle}; use super::{commands::Command, utils::term}; #[cfg(feature = "search")] use crate::search; -use crate::{error::MinusError, input::InputEvent, PagerState}; +use crate::{PagerState, error::MinusError, input::InputEvent}; /// Respond based on the type of command /// @@ -336,12 +336,12 @@ pub fn handle_event( mod tests { use super::super::commands::Command; use super::handle_event; - use crate::{minus_core::CommandQueue, ExitStrategy, PagerState, RunMode}; + use crate::{ExitStrategy, PagerState, RunMode, minus_core::CommandQueue}; #[cfg(feature = "search")] use parking_lot::{Condvar, Mutex}; #[cfg(feature = "search")] use std::sync::LazyLock; - use std::sync::{atomic::AtomicBool, Arc}; + use std::sync::{Arc, atomic::AtomicBool}; // Tests constants #[cfg(feature = "search")] diff --git a/src/core/init.rs b/src/core/init.rs index afb82cc5..b54d8d7e 100644 --- a/src/core/init.rs +++ b/src/core/init.rs @@ -11,25 +11,25 @@ #[cfg(feature = "static_output")] use crate::minus_core::utils::display; use crate::{ + Pager, PagerState, error::MinusError, input::InputEvent, minus_core::{ + RunMode, commands::Command, ev_handler::handle_event, utils::{display::draw_full, term}, - RunMode, }, - Pager, PagerState, }; use crossbeam_channel::{Receiver, Sender, TrySendError}; use crossterm::event; use std::{ - io::{stdout, Stdout}, + io::{Stdout, stdout}, panic, sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }, }; @@ -40,7 +40,7 @@ use {super::utils::display::write_raw_lines, crossterm::tty::IsTty}; use parking_lot::Condvar; use parking_lot::Mutex; -use super::{utils::display::draw_for_change, CommandQueue, RUNMODE}; +use super::{CommandQueue, RUNMODE, utils::display::draw_for_change}; /// The main entry point of minus /// @@ -88,7 +88,10 @@ pub fn init_core(pager: &Pager, rm: RunMode) -> std::result::Result<(), MinusErr { let mut runmode = super::RUNMODE.lock(); - assert!(runmode.is_uninitialized(), "Failed to set the RUNMODE. This is caused probably because another instance of minus is already running"); + assert!( + runmode.is_uninitialized(), + "Failed to set the RUNMODE. This is caused probably because another instance of minus is already running" + ); *runmode = rm; drop(runmode); } diff --git a/src/core/mod.rs b/src/core/mod.rs index e34c8a62..e77e2998 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -45,7 +45,10 @@ impl CommandQueue { /// This function will panic if it is called in an environment where [RUNMODE] is /// uninitialized. pub fn push_back(&mut self, value: Command) { - assert!(!RUNMODE.lock().is_uninitialized(), "CommandQueue::push_back() caled when RUNMODE is not set. This is most likely a bug. Please report the issue on minus's issue tracker on Github."); + assert!( + !RUNMODE.lock().is_uninitialized(), + "CommandQueue::push_back() caled when RUNMODE is not set. This is most likely a bug. Please report the issue on minus's issue tracker on Github." + ); self.0.push_back(value); } /// Store `value` without checking [RUNMODE]. diff --git a/src/core/utils/display/mod.rs b/src/core/utils/display/mod.rs index d979a945..89e71d5c 100644 --- a/src/core/utils/display/mod.rs +++ b/src/core/utils/display/mod.rs @@ -10,7 +10,7 @@ use std::{cmp::Ordering, convert::TryInto, io::Write}; use super::term; use crate::screen::Row; -use crate::{error::MinusError, minus_core, LineNumbers, PagerState}; +use crate::{LineNumbers, PagerState, error::MinusError, minus_core}; /// How should the incoming text be drawn on the screen #[derive(Debug, PartialEq, Eq)] diff --git a/src/core/utils/display/tests.rs b/src/core/utils/display/tests.rs index f59ac0b2..5224790e 100644 --- a/src/core/utils/display/tests.rs +++ b/src/core/utils/display/tests.rs @@ -233,9 +233,11 @@ fn draw_short_no_line_numbers() { assert!(draw_full(&mut out, &mut pager).is_ok()); - assert!(String::from_utf8(out) - .expect("Should have written valid UTF-8") - .contains("\rA line\n\rAnother line")); + assert!( + String::from_utf8(out) + .expect("Should have written valid UTF-8") + .contains("\rA line\n\rAnother line") + ); assert_eq!(pager.upper_mark, 0); let mut out = Vec::with_capacity(lines.len()); @@ -245,9 +247,11 @@ fn draw_short_no_line_numbers() { // The number of lines is less than 'rows' so 'upper_mark' will be 0 even // if we set it to 1. This is done because everything can be displayed without problems. - assert!(String::from_utf8(out) - .expect("Should have written valid UTF-8") - .contains("\rA line\n\rAnother line")); + assert!( + String::from_utf8(out) + .expect("Should have written valid UTF-8") + .contains("\rA line\n\rAnother line") + ); assert_eq!(pager.upper_mark, 0); } @@ -264,9 +268,11 @@ fn draw_long_no_line_numbers() { assert!(draw_full(&mut out, &mut pager).is_ok()); - assert!(String::from_utf8(out) - .expect("Should have written valid UTF-8") - .contains("\rA line\n\rAnother line")); + assert!( + String::from_utf8(out) + .expect("Should have written valid UTF-8") + .contains("\rA line\n\rAnother line") + ); assert_eq!(pager.upper_mark, 0); // This ensures that asking for a position other than 0 works. @@ -275,9 +281,11 @@ fn draw_long_no_line_numbers() { assert!(draw_full(&mut out, &mut pager).is_ok()); - assert!(String::from_utf8(out) - .expect("Should have written valid UTF-8") - .contains("\rAnother line\n\rThird line")); + assert!( + String::from_utf8(out) + .expect("Should have written valid UTF-8") + .contains("\rAnother line\n\rThird line") + ); assert_eq!(pager.upper_mark, 1); // This test ensures that as much text as possible will be displayed, even @@ -287,9 +295,11 @@ fn draw_long_no_line_numbers() { assert!(draw_full(&mut out, &mut pager).is_ok()); - assert!(String::from_utf8(out) - .expect("Should have written valid UTF-8") - .contains("\rThird line\n\rFourth line")); + assert!( + String::from_utf8(out) + .expect("Should have written valid UTF-8") + .contains("\rThird line\n\rFourth line") + ); assert_eq!(pager.upper_mark, 2); } @@ -303,9 +313,11 @@ fn draw_short_with_line_numbers() { pager.format_lines(); assert!(draw_full(&mut out, &mut pager).is_ok()); - assert!(String::from_utf8(out) - .expect("Should have written valid UTF-8") - .contains("\r 1. A line\n\r 2. Another line")); + assert!( + String::from_utf8(out) + .expect("Should have written valid UTF-8") + .contains("\r 1. A line\n\r 2. Another line") + ); assert_eq!(pager.upper_mark, 0); let mut out = Vec::with_capacity(lines.len()); @@ -315,9 +327,11 @@ fn draw_short_with_line_numbers() { // The number of lines is less than 'rows' so 'upper_mark' will be 0 even // if we set it to 1. This is done because everything can be displayed without problems. - assert!(String::from_utf8(out) - .expect("Should have written valid UTF-8") - .contains("\r 1. A line\n\r 2. Another line")); + assert!( + String::from_utf8(out) + .expect("Should have written valid UTF-8") + .contains("\r 1. A line\n\r 2. Another line") + ); assert_eq!(pager.upper_mark, 0); } @@ -335,9 +349,11 @@ fn draw_long_with_line_numbers() { assert!(draw_full(&mut out, &mut pager).is_ok()); - assert!(String::from_utf8(out) - .expect("Should have written valid UTF-8") - .contains("\r 1. A line\n\r 2. Another line")); + assert!( + String::from_utf8(out) + .expect("Should have written valid UTF-8") + .contains("\r 1. A line\n\r 2. Another line") + ); assert_eq!(pager.upper_mark, 0); // This ensures that asking for a position other than 0 works. @@ -346,9 +362,11 @@ fn draw_long_with_line_numbers() { assert!(draw_full(&mut out, &mut pager).is_ok()); - assert!(String::from_utf8(out) - .expect("Should have written valid UTF-8") - .contains("\r 2. Another line\n\r 3. Third line")); + assert!( + String::from_utf8(out) + .expect("Should have written valid UTF-8") + .contains("\r 2. Another line\n\r 3. Third line") + ); assert_eq!(pager.upper_mark, 1); // This test ensures that as much text as possible will be displayed, even @@ -358,9 +376,11 @@ fn draw_long_with_line_numbers() { assert!(draw_full(&mut out, &mut pager).is_ok()); - assert!(String::from_utf8(out) - .expect("Should have written valid UTF-8") - .contains("\r 3. Third line\n\r 4. Fourth line")); + assert!( + String::from_utf8(out) + .expect("Should have written valid UTF-8") + .contains("\r 3. Third line\n\r 4. Fourth line") + ); assert_eq!(pager.upper_mark, 2); } @@ -439,9 +459,11 @@ fn test_draw_no_overflow() { pager.screen.orig_text = TEXT.to_string(); pager.format_lines(); draw_full(&mut out, &mut pager).unwrap(); - assert!(String::from_utf8(out) - .expect("Should have written valid UTF-8") - .contains(TEXT)); + assert!( + String::from_utf8(out) + .expect("Should have written valid UTF-8") + .contains(TEXT) + ); } #[cfg(test)] diff --git a/src/dynamic_pager.rs b/src/dynamic_pager.rs index 8acb2632..1b4d3f71 100644 --- a/src/dynamic_pager.rs +++ b/src/dynamic_pager.rs @@ -1,6 +1,6 @@ +use crate::Pager; use crate::error::MinusError; use crate::minus_core::init; -use crate::Pager; /// Starts a asynchronously running pager /// diff --git a/src/input/definitions/keydefs.rs b/src/input/definitions/keydefs.rs index 97fdf90e..35935431 100644 --- a/src/input/definitions/keydefs.rs +++ b/src/input/definitions/keydefs.rs @@ -1,6 +1,6 @@ #![allow(dead_code)] -use super::{Token, MODIFIERS}; +use super::{MODIFIERS, Token}; use std::{collections::HashMap, sync::LazyLock}; use crossterm::event::{KeyCode, KeyEvent, KeyEventState, KeyModifiers}; diff --git a/src/input/definitions/mousedefs.rs b/src/input/definitions/mousedefs.rs index fa5499e6..242aaa67 100644 --- a/src/input/definitions/mousedefs.rs +++ b/src/input/definitions/mousedefs.rs @@ -1,6 +1,6 @@ use std::{collections::HashMap, sync::LazyLock}; -use super::{Token, MODIFIERS}; +use super::{MODIFIERS, Token}; use crossterm::event::{KeyModifiers, MouseButton, MouseEvent, MouseEventKind}; static MOUSE_ACTIONS: LazyLock> = LazyLock::new(|| { diff --git a/src/input/hashed_event_register.rs b/src/input/hashed_event_register.rs index e7b4b0d6..90ebc520 100644 --- a/src/input/hashed_event_register.rs +++ b/src/input/hashed_event_register.rs @@ -8,7 +8,7 @@ use super::{InputClassifier, InputEvent}; use crate::PagerState; use crossterm::event::{Event, MouseEvent}; use std::{ - collections::hash_map::RandomState, collections::HashMap, hash::BuildHasher, hash::Hash, + collections::HashMap, collections::hash_map::RandomState, hash::BuildHasher, hash::Hash, sync::Arc, }; diff --git a/src/input/tests.rs b/src/input/tests.rs index 9a7a8d42..6d9bbd8b 100644 --- a/src/input/tests.rs +++ b/src/input/tests.rs @@ -1,6 +1,6 @@ #[cfg(feature = "search")] use crate::SearchMode; -use crate::{input::InputEvent, LineNumbers, PagerState}; +use crate::{LineNumbers, PagerState, input::InputEvent}; use crossterm::event::{ Event, KeyCode, KeyEvent, KeyEventState, KeyModifiers, MouseEvent, MouseEventKind, }; diff --git a/src/pager.rs b/src/pager.rs index 04cdae4d..6de05aaf 100644 --- a/src/pager.rs +++ b/src/pager.rs @@ -1,6 +1,6 @@ //! Proivdes the [Pager] type -use crate::{error::MinusError, input, minus_core::commands::Command, ExitStrategy, LineNumbers}; +use crate::{ExitStrategy, LineNumbers, error::MinusError, input, minus_core::commands::Command}; use crossbeam_channel::{Receiver, Sender}; use std::fmt; diff --git a/src/screen/mod.rs b/src/screen/mod.rs index d275cc3b..9c8d7793 100644 --- a/src/screen/mod.rs +++ b/src/screen/mod.rs @@ -2,8 +2,8 @@ //! //! This module is still a work is progress and is subject to change. use crate::{ - minus_core::{self, utils::LinesRowMap}, LineNumbers, + minus_core::{self, utils::LinesRowMap}, }; #[cfg(feature = "search")] use regex::Regex; diff --git a/src/screen/tests.rs b/src/screen/tests.rs index 69d911d1..8b3388df 100644 --- a/src/screen/tests.rs +++ b/src/screen/tests.rs @@ -1,5 +1,5 @@ mod unterminated { - use crate::screen::{format_text_block, FormatOpts, Rows}; + use crate::screen::{FormatOpts, Rows, format_text_block}; const fn get_append_opts_template(text: &'_ str) -> FormatOpts<'_, Rows> { FormatOpts { diff --git a/src/search.rs b/src/search.rs index 37c3264b..a9190c81 100644 --- a/src/search.rs +++ b/src/search.rs @@ -53,8 +53,8 @@ #![allow(unused_imports)] use crate::minus_core::utils::{display, term}; use crate::screen::Screen; -use crate::{error::MinusError, input::HashedEventRegister, screen}; use crate::{LineNumbers, PagerState}; +use crate::{error::MinusError, input::HashedEventRegister, screen}; use crossterm::{ cursor::{self, MoveTo}, event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}, @@ -773,8 +773,8 @@ pub(crate) fn next_nth_match( mod tests { mod input_handling { use crate::{ - search::{handle_key_press, InputStatus, SearchOpts}, SearchMode, + search::{InputStatus, SearchOpts, handle_key_press}, }; use crossterm::{ cursor::MoveTo, @@ -1076,8 +1076,8 @@ mod tests { mod highlighting { use std::collections::BTreeSet; - use crate::search::{highlight_line_matches, next_nth_match, INVERT, NORMAL}; use crate::PagerState; + use crate::search::{INVERT, NORMAL, highlight_line_matches, next_nth_match}; use crossterm::style::Attribute; use regex::Regex; @@ -1214,12 +1214,12 @@ eros.", assert_eq!( res.0, format!( - "{i}{e}test{n}{nn} this {e}is a {i}te{NONE}st{n} again {e}yeah{nn} {i}test{n}", - e = ESC, - i = *INVERT, - n = *NORMAL, - nn = NONE - ) + "{i}{e}test{n}{nn} this {e}is a {i}te{NONE}st{n} again {e}yeah{nn} {i}test{n}", + e = ESC, + i = *INVERT, + n = *NORMAL, + nn = NONE + ) ); } diff --git a/src/state.rs b/src/state.rs index cc69cdc3..3be49fa3 100644 --- a/src/state.rs +++ b/src/state.rs @@ -4,15 +4,14 @@ use crate::search::{SearchMode, SearchOpts}; use crate::{ + ExitStrategy, LineNumbers, error::{MinusError, TermError}, input::{self, HashedEventRegister}, minus_core::{ - self, - utils::{display::AppendStyle, LinesRowMap}, - CommandQueue, + self, CommandQueue, + utils::{LinesRowMap, display::AppendStyle}, }, screen::{self, Screen}, - ExitStrategy, LineNumbers, }; use crossterm::{terminal, tty::IsTty}; #[cfg(feature = "search")] @@ -23,9 +22,9 @@ use std::collections::BTreeSet; use std::{ collections::hash_map::RandomState, convert::TryInto, - io::stdout, io::Stdout, - sync::{atomic::AtomicBool, Arc}, + io::stdout, + sync::{Arc, atomic::AtomicBool}, }; use crate::minus_core::{commands::Command, ev_handler::handle_event}; diff --git a/src/static_pager.rs b/src/static_pager.rs index 052c1bd9..308ae702 100644 --- a/src/static_pager.rs +++ b/src/static_pager.rs @@ -2,7 +2,7 @@ //! //! This module provides provides the [`page_all`] function to display static output via minus use crate::minus_core::init; -use crate::{error::MinusError, Pager}; +use crate::{Pager, error::MinusError}; /// Display static information to the screen /// diff --git a/src/tests.rs b/src/tests.rs index c19e6d9b..c2becad6 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,6 +1,6 @@ // Test the implementation of std::fmt::Write on Pager mod fmt_write { - use crate::{minus_core::commands::Command, Pager}; + use crate::{Pager, minus_core::commands::Command}; use std::fmt::Write; #[test] @@ -229,7 +229,7 @@ mod pager_append_str { fn exit_callback() { use crate::PagerState; use std::sync::atomic::Ordering; - use std::sync::{atomic::AtomicBool, Arc}; + use std::sync::{Arc, atomic::AtomicBool}; let mut ps = PagerState::new().unwrap(); let exited = Arc::new(AtomicBool::new(false)); @@ -244,7 +244,7 @@ fn exit_callback() { mod emit_events { // Check functions emit correct events on function calls - use crate::{minus_core::commands::Command, ExitStrategy, LineNumbers, Pager}; + use crate::{ExitStrategy, LineNumbers, Pager, minus_core::commands::Command}; const TEST_STR: &str = "This is sample text"; #[test]