Fix spacing issue with git feature disabled

This commit is contained in:
einfachIrgendwer0815 2024-03-18 18:26:53 +01:00
parent 38cbbfac55
commit 8c072fd7d7
No known key found for this signature in database
GPG Key ID: 58D55E5F117DA873
5 changed files with 120 additions and 66 deletions

View File

@ -156,3 +156,33 @@ impl Decoration for GridBorderDecoration {
self.cached.width
}
}
pub(crate) struct PlaceholderDecoration {
cached: DecorationText,
}
impl PlaceholderDecoration {
pub(crate) fn new(length: usize) -> Self {
Self {
cached: DecorationText {
text: " ".repeat(length),
width: length,
},
}
}
}
impl Decoration for PlaceholderDecoration {
fn generate(
&self,
_line_number: usize,
_continuation: bool,
_printer: &InteractivePrinter,
) -> DecorationText {
self.cached.clone()
}
fn width(&self) -> usize {
self.cached.width
}
}

View File

@ -24,6 +24,7 @@ use crate::config::Config;
use crate::decorations;
#[cfg(feature = "git")]
use crate::decorations::LineChangesDecoration;
use crate::decorations::PlaceholderDecoration;
use crate::decorations::{Decoration, GridBorderDecoration, LineNumberDecoration};
#[cfg(feature = "git")]
use crate::diff::LineChanges;
@ -260,6 +261,28 @@ impl<'a> InteractivePrinter<'a> {
}
}
let insert_placeholder = {
let git_feature_enabled = cfg!(feature = "git");
let changes_component;
#[cfg(feature = "git")]
{
changes_component = config.style_components.changes();
}
#[cfg(not(feature = "git"))]
{
changes_component = false;
}
let soft_limit_active = config.soft_line_limit.is_some();
let numbers_and_grid =
config.style_components.grid() && config.style_components.numbers();
(!git_feature_enabled || !changes_component) && numbers_and_grid && soft_limit_active
};
if insert_placeholder {
decorations.push(Box::new(PlaceholderDecoration::new(1)))
}
let mut panel_width: usize =
decorations.len() + decorations.iter().fold(0, |a, x| a + x.width());

View File

@ -1343,11 +1343,11 @@ fn bom_stripped_when_no_color_and_not_loop_through() {
.success()
.stdout(
"\
File: test_BOM.txt
1 hello world
File: test_BOM.txt
1 hello world
",
);
}
@ -1595,15 +1595,16 @@ fn header_narrow_terminal() {
.success()
.stdout(
"\
File: this-file-path-is
-really-long-and-would-
have-broken-the-layout-
of-the-header.txt
1 The header is not broke
n
File: this-file-path-
is-really-long-and-wo
uld-have-broken-the-l
ayout-of-the-header.t
xt
1 The header is not bro
ken
",
)
.stderr("");

View File

@ -1,27 +1,27 @@
───────────────────────────────────────────────────────────────────────────────
│ File: sample.rs
───────────────────────────────────────────────────────────────────────────────
1 │ /// A rectangle. First line is changed to prevent a regression of #1869
2 │ struct Rectangle {
3 │ width: u32,
4 │ height: u32,
5 │ }
6 │
7 │ fn main() {
8 │ let rect1 = Rectangle { width: 30, height: 50 };
9 │
10 │ println!(
11 │ "The perimeter of the rectangle is {} pixels.",
12 │ perimeter(&rect1)
13 │ );
14 │ println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
15 │ }
16 │
17 │ fn area(rectangle: &Rectangle) -> u32 {
18 │ rectangle.width * rectangle.height
19 │ }
20 │
21 │ fn perimeter(rectangle: &Rectangle) -> u32 {
22 │ (rectangle.width + rectangle.height) * 2
23 │ }
───────────────────────────────────────────────────────────────────────────────
───────────────────────────────────────────────────────────────────────────────
│ File: sample.rs
───────────────────────────────────────────────────────────────────────────────
1 │ /// A rectangle. First line is changed to prevent a regression of #1869
2 │ struct Rectangle {
3 │ width: u32,
4 │ height: u32,
5 │ }
6
7 │ fn main() {
8 │ let rect1 = Rectangle { width: 30, height: 50 };
9
10 │ println!(
11 │ "The perimeter of the rectangle is {} pixels.",
12 │ perimeter(&rect1)
13 │ );
14 │ println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
15 │ }
16
17 │ fn area(rectangle: &Rectangle) -> u32 {
18 │ rectangle.width * rectangle.height
19 │ }
20
21 │ fn perimeter(rectangle: &Rectangle) -> u32 {
22 │ (rectangle.width + rectangle.height) * 2
23 │ }
───────────────────────────────────────────────────────────────────────────────

View File

@ -1,25 +1,25 @@
───────────────────────────────────────────────────────────────────────────────
1 │ /// A rectangle. First line is changed to prevent a regression of #1869
2 │ struct Rectangle {
3 │ width: u32,
4 │ height: u32,
5 │ }
6 │
7 │ fn main() {
8 │ let rect1 = Rectangle { width: 30, height: 50 };
9 │
10 │ println!(
11 │ "The perimeter of the rectangle is {} pixels.",
12 │ perimeter(&rect1)
13 │ );
14 │ println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
15 │ }
16 │
17 │ fn area(rectangle: &Rectangle) -> u32 {
18 │ rectangle.width * rectangle.height
19 │ }
20 │
21 │ fn perimeter(rectangle: &Rectangle) -> u32 {
22 │ (rectangle.width + rectangle.height) * 2
23 │ }
───────────────────────────────────────────────────────────────────────────────
───────────────────────────────────────────────────────────────────────────────
1 │ /// A rectangle. First line is changed to prevent a regression of #1869
2 │ struct Rectangle {
3 │ width: u32,
4 │ height: u32,
5 │ }
6
7 │ fn main() {
8 │ let rect1 = Rectangle { width: 30, height: 50 };
9
10 │ println!(
11 │ "The perimeter of the rectangle is {} pixels.",
12 │ perimeter(&rect1)
13 │ );
14 │ println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
15 │ }
16
17 │ fn area(rectangle: &Rectangle) -> u32 {
18 │ rectangle.width * rectangle.height
19 │ }
20
21 │ fn perimeter(rectangle: &Rectangle) -> u32 {
22 │ (rectangle.width + rectangle.height) * 2
23 │ }
───────────────────────────────────────────────────────────────────────────────