Skip to content

Commit 55bebbb

Browse files
Fix spacing issue with git feature disabled
1 parent cd4b880 commit 55bebbb

File tree

5 files changed

+120
-66
lines changed

5 files changed

+120
-66
lines changed

src/decorations.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,33 @@ impl Decoration for GridBorderDecoration {
156156
self.cached.width
157157
}
158158
}
159+
160+
pub(crate) struct PlaceholderDecoration {
161+
cached: DecorationText,
162+
}
163+
164+
impl PlaceholderDecoration {
165+
pub(crate) fn new(length: usize) -> Self {
166+
Self {
167+
cached: DecorationText {
168+
text: " ".repeat(length),
169+
width: length,
170+
},
171+
}
172+
}
173+
}
174+
175+
impl Decoration for PlaceholderDecoration {
176+
fn generate(
177+
&self,
178+
_line_number: usize,
179+
_continuation: bool,
180+
_printer: &InteractivePrinter,
181+
) -> DecorationText {
182+
self.cached.clone()
183+
}
184+
185+
fn width(&self) -> usize {
186+
self.cached.width
187+
}
188+
}

src/printer.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::config::Config;
2424
use crate::decorations;
2525
#[cfg(feature = "git")]
2626
use crate::decorations::LineChangesDecoration;
27+
use crate::decorations::PlaceholderDecoration;
2728
use crate::decorations::{Decoration, GridBorderDecoration, LineNumberDecoration};
2829
#[cfg(feature = "git")]
2930
use crate::diff::LineChanges;
@@ -257,6 +258,28 @@ impl<'a> InteractivePrinter<'a> {
257258
}
258259
}
259260

261+
let insert_placeholder = {
262+
let git_feature_enabled = cfg!(feature = "git");
263+
let changes_component;
264+
#[cfg(feature = "git")]
265+
{
266+
changes_component = config.style_components.changes();
267+
}
268+
#[cfg(not(feature = "git"))]
269+
{
270+
changes_component = false;
271+
}
272+
273+
let soft_limit_active = config.soft_line_limit.is_some();
274+
let numbers_and_grid =
275+
config.style_components.grid() && config.style_components.numbers();
276+
277+
(!git_feature_enabled || !changes_component) && numbers_and_grid && soft_limit_active
278+
};
279+
if insert_placeholder {
280+
decorations.push(Box::new(PlaceholderDecoration::new(1)))
281+
}
282+
260283
let mut panel_width: usize =
261284
decorations.len() + decorations.iter().fold(0, |a, x| a + x.width());
262285

tests/integration_tests.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,11 +1308,11 @@ fn bom_stripped_when_no_color_and_not_loop_through() {
13081308
.success()
13091309
.stdout(
13101310
"\
1311-
─────┬──────────────────────────────────────────────────────────────────────────
1312-
│ File: test_BOM.txt
1313-
─────┼──────────────────────────────────────────────────────────────────────────
1314-
1 │ hello world
1315-
─────┴──────────────────────────────────────────────────────────────────────────
1311+
───────┬────────────────────────────────────────────────────────────────────────
1312+
│ File: test_BOM.txt
1313+
───────┼────────────────────────────────────────────────────────────────────────
1314+
1 │ hello world
1315+
───────┴────────────────────────────────────────────────────────────────────────
13161316
",
13171317
);
13181318
}
@@ -1560,15 +1560,16 @@ fn header_narrow_terminal() {
15601560
.success()
15611561
.stdout(
15621562
"\
1563-
─────┬────────────────────────
1564-
│ File: this-file-path-is
1565-
│ -really-long-and-would-
1566-
│ have-broken-the-layout-
1567-
│ of-the-header.txt
1568-
─────┼────────────────────────
1569-
1 │ The header is not broke
1570-
│ n
1571-
─────┴────────────────────────
1563+
───────┬──────────────────────
1564+
│ File: this-file-path-
1565+
│ is-really-long-and-wo
1566+
│ uld-have-broken-the-l
1567+
│ ayout-of-the-header.t
1568+
│ xt
1569+
───────┼──────────────────────
1570+
1 │ The header is not bro
1571+
│ ken
1572+
───────┴──────────────────────
15721573
",
15731574
)
15741575
.stderr("");
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
─────┬──────────────────────────────────────────────────────────────────────────
2-
│ File: sample.rs
3-
─────┼──────────────────────────────────────────────────────────────────────────
4-
1 │ /// A rectangle. First line is changed to prevent a regression of #1869
5-
2 │ struct Rectangle {
6-
3 │ width: u32,
7-
4 │ height: u32,
8-
5 │ }
9-
6 │
10-
7 │ fn main() {
11-
8 │ let rect1 = Rectangle { width: 30, height: 50 };
12-
9 │
13-
10 │ println!(
14-
11 │ "The perimeter of the rectangle is {} pixels.",
15-
12 │ perimeter(&rect1)
16-
13 │ );
17-
14 │ println!(r#"This line contains invalid utf8: "�����"#;
18-
15 │ }
19-
16 │
20-
17 │ fn area(rectangle: &Rectangle) -> u32 {
21-
18 │ rectangle.width * rectangle.height
22-
19 │ }
23-
20 │
24-
21 │ fn perimeter(rectangle: &Rectangle) -> u32 {
25-
22 │ (rectangle.width + rectangle.height) * 2
26-
23 │ }
27-
─────┴──────────────────────────────────────────────────────────────────────────
1+
───────┬────────────────────────────────────────────────────────────────────────
2+
│ File: sample.rs
3+
───────┼────────────────────────────────────────────────────────────────────────
4+
1 │ /// A rectangle. First line is changed to prevent a regression of #1869
5+
2 │ struct Rectangle {
6+
3 │ width: u32,
7+
4 │ height: u32,
8+
5 │ }
9+
6
10+
7 │ fn main() {
11+
8 │ let rect1 = Rectangle { width: 30, height: 50 };
12+
9
13+
10 │ println!(
14+
11 │ "The perimeter of the rectangle is {} pixels.",
15+
12 │ perimeter(&rect1)
16+
13 │ );
17+
14 │ println!(r#"This line contains invalid utf8: "�����"#;
18+
15 │ }
19+
16
20+
17 │ fn area(rectangle: &Rectangle) -> u32 {
21+
18 │ rectangle.width * rectangle.height
22+
19 │ }
23+
20
24+
21 │ fn perimeter(rectangle: &Rectangle) -> u32 {
25+
22 │ (rectangle.width + rectangle.height) * 2
26+
23 │ }
27+
───────┴────────────────────────────────────────────────────────────────────────
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
─────┬──────────────────────────────────────────────────────────────────────────
2-
1 │ /// A rectangle. First line is changed to prevent a regression of #1869
3-
2 │ struct Rectangle {
4-
3 │ width: u32,
5-
4 │ height: u32,
6-
5 │ }
7-
6 │
8-
7 │ fn main() {
9-
8 │ let rect1 = Rectangle { width: 30, height: 50 };
10-
9 │
11-
10 │ println!(
12-
11 │ "The perimeter of the rectangle is {} pixels.",
13-
12 │ perimeter(&rect1)
14-
13 │ );
15-
14 │ println!(r#"This line contains invalid utf8: "�����"#;
16-
15 │ }
17-
16 │
18-
17 │ fn area(rectangle: &Rectangle) -> u32 {
19-
18 │ rectangle.width * rectangle.height
20-
19 │ }
21-
20 │
22-
21 │ fn perimeter(rectangle: &Rectangle) -> u32 {
23-
22 │ (rectangle.width + rectangle.height) * 2
24-
23 │ }
25-
─────┴──────────────────────────────────────────────────────────────────────────
1+
───────┬────────────────────────────────────────────────────────────────────────
2+
1 │ /// A rectangle. First line is changed to prevent a regression of #1869
3+
2 │ struct Rectangle {
4+
3 │ width: u32,
5+
4 │ height: u32,
6+
5 │ }
7+
6
8+
7 │ fn main() {
9+
8 │ let rect1 = Rectangle { width: 30, height: 50 };
10+
9
11+
10 │ println!(
12+
11 │ "The perimeter of the rectangle is {} pixels.",
13+
12 │ perimeter(&rect1)
14+
13 │ );
15+
14 │ println!(r#"This line contains invalid utf8: "�����"#;
16+
15 │ }
17+
16
18+
17 │ fn area(rectangle: &Rectangle) -> u32 {
19+
18 │ rectangle.width * rectangle.height
20+
19 │ }
21+
20
22+
21 │ fn perimeter(rectangle: &Rectangle) -> u32 {
23+
22 │ (rectangle.width + rectangle.height) * 2
24+
23 │ }
25+
───────┴────────────────────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)