diff --git a/flake.nix b/flake.nix index f0df37e..32bd3e6 100644 --- a/flake.nix +++ b/flake.nix @@ -92,17 +92,16 @@ }); }; - devShells.default = - (craneLib.overrideToolchain stableToolchainWithRustAnalyzer).devShell - ({ - buildInputs = []; - nativeBuildInputs = []; - packages = with pkgs; [ - cargo-nextest - cargo-criterion - ]; - } - // commonArgs); + devShells.default = (craneLib.overrideToolchain stableToolchainWithRustAnalyzer).devShell (commonArgs + // { + buildInputs = []; + nativeBuildInputs = []; + packages = with pkgs; [ + cargo-nextest + cargo-criterion + cargo-outdated + ]; + }); } ); } diff --git a/src/parser.rs b/src/parser.rs index 33825e0..0557435 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -81,7 +81,7 @@ impl From for tui::style::Style { pub(crate) fn text(mut s: &[u8]) -> IResult<&[u8], Text<'static>> { let mut lines = Vec::new(); - let mut last = Default::default(); + let mut last = Style::new(); while let Ok((_s, (line, style))) = line(last)(s) { lines.push(line); last = style; @@ -96,7 +96,7 @@ pub(crate) fn text(mut s: &[u8]) -> IResult<&[u8], Text<'static>> { #[cfg(feature = "zero-copy")] pub(crate) fn text_fast(mut s: &[u8]) -> IResult<&[u8], Text<'_>> { let mut lines = Vec::new(); - let mut last = Default::default(); + let mut last = Style::new(); while let Ok((_s, (line, style))) = line_fast(last)(s) { lines.push(line); last = style; @@ -119,7 +119,7 @@ fn line(style: Style) -> impl Fn(&[u8]) -> IResult<&[u8], (Line<'static>, Style) // Since reset now tracks seperately we can skip the reset check last = last.patch(span.style); - if spans.is_empty() || !span.content.is_empty() { + if !span.content.is_empty() { spans.push(span); } text = s; @@ -144,7 +144,7 @@ fn line_fast(style: Style) -> impl Fn(&[u8]) -> IResult<&[u8], (Line<'_>, Style) last = last.patch(span.style); // If the spans is empty then it might be possible that the style changes // but there is no text change - if spans.is_empty() || !span.content.is_empty() { + if !span.content.is_empty() { spans.push(span); } text = s; diff --git a/tests/tests.rs b/tests/tests.rs index 8588b12..a26c1f8 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -91,18 +91,19 @@ fn test_screen_modes() { #[test] fn test_cursor_shape_and_color() { // malformed -> malformed -> empty - let bytes: Vec = b"\x1b[4 q\x1b]12;#fab1ed\x07".to_vec(); + let bytes = b"\x1b[4 q\x1b]12;#fab1ed\x07"; let output = Text::raw(""); test_both(bytes, output); } #[test] fn test_malformed_simple() { - let bytes: Vec = b"\x1b[".to_vec(); + let bytes = b"\x1b["; let output = Text::raw(""); test_both(bytes, output); } + #[test] fn test_malformed_complex() { let bytes: Vec = b"\x1b\x1b[0\x1b[m\x1b".to_vec(); @@ -116,7 +117,7 @@ fn empty_span() { let bytes: Vec = b"\x1b[33m\x1b[31m\x1b[32mHello\x1b[0mWorld".to_vec(); let output = Text::from(Line::from(vec![ // Not sure whether to keep this empty span or remove it somehow - Span::styled("", Style::default().fg(Color::Yellow)), + // Span::styled("", Style::default().fg(Color::Yellow)), // Span::styled("", Style::default().fg(Color::Red)), Span::styled("Hello", Style::default().fg(Color::Green)), Span::styled("World", Style::reset()), @@ -155,7 +156,7 @@ pub fn test_both(bytes: impl AsRef<[u8]>, other: Text) { let bytes = bytes.as_ref(); let zero_copy = bytes.to_text().unwrap(); let owned = bytes.into_text().unwrap(); - assert_eq!(zero_copy, owned); - assert_eq!(owned, other); + assert_eq!(zero_copy, owned, "zero-copy and owned version of the methods have diverged this is for sure a bug in the library"); + assert_eq!(owned, other, "owned and other have diverged this migh be due to a bug in the library or maybe an update to the ratatui crate"); assert_eq!(zero_copy, other); }