Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "minus"
version = "5.6.1"
authors = ["Arijit Dey <arijid79@gmail.com>"]
edition = "2018"
edition = "2024"
license = "MIT OR Apache-2.0"
documentation = "https://docs.rs/minus"
repository = "https://github.com/AMythicDev/minus"
Expand Down
2 changes: 1 addition & 1 deletion examples/color-output.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion examples/static-no-overflow.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion src/core/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use std::fmt::Debug;

use crate::{
input::{InputClassifier, InputEvent},
ExitStrategy, LineNumbers,
input::{InputClassifier, InputEvent},
};

#[cfg(feature = "search")]
Expand Down
10 changes: 5 additions & 5 deletions src/core/ev_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -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")]
Expand Down
15 changes: 9 additions & 6 deletions src/core/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
};

Expand All @@ -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
///
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/display/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
88 changes: 55 additions & 33 deletions src/core/utils/display/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
}

Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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);
}

Expand All @@ -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());
Expand All @@ -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);
}

Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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);
}

Expand Down Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic_pager.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Pager;
use crate::error::MinusError;
use crate::minus_core::init;
use crate::Pager;

/// Starts a asynchronously running pager
///
Expand Down
2 changes: 1 addition & 1 deletion src/input/definitions/keydefs.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion src/input/definitions/mousedefs.rs
Original file line number Diff line number Diff line change
@@ -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<HashMap<&str, MouseEventKind>> = LazyLock::new(|| {
Expand Down
2 changes: 1 addition & 1 deletion src/input/hashed_event_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
2 changes: 1 addition & 1 deletion src/input/tests.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion src/pager.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/screen/tests.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Loading
Loading