mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-25 22:38:39 +00:00
Fix spacing issue with git feature disabled
This commit is contained in:
parent
c50ab4de72
commit
4e5eacce0d
@ -156,3 +156,33 @@ impl Decoration for GridBorderDecoration {
|
|||||||
self.cached.width
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -24,6 +24,7 @@ use crate::config::Config;
|
|||||||
use crate::decorations;
|
use crate::decorations;
|
||||||
#[cfg(feature = "git")]
|
#[cfg(feature = "git")]
|
||||||
use crate::decorations::LineChangesDecoration;
|
use crate::decorations::LineChangesDecoration;
|
||||||
|
use crate::decorations::PlaceholderDecoration;
|
||||||
use crate::decorations::{Decoration, GridBorderDecoration, LineNumberDecoration};
|
use crate::decorations::{Decoration, GridBorderDecoration, LineNumberDecoration};
|
||||||
#[cfg(feature = "git")]
|
#[cfg(feature = "git")]
|
||||||
use crate::diff::LineChanges;
|
use crate::diff::LineChanges;
|
||||||
@ -261,6 +262,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 =
|
let mut panel_width: usize =
|
||||||
decorations.len() + decorations.iter().fold(0, |a, x| a + x.width());
|
decorations.len() + decorations.iter().fold(0, |a, x| a + x.width());
|
||||||
|
|
||||||
|
@ -1375,11 +1375,11 @@ fn bom_stripped_when_no_color_and_not_loop_through() {
|
|||||||
.success()
|
.success()
|
||||||
.stdout(
|
.stdout(
|
||||||
"\
|
"\
|
||||||
─────┬──────────────────────────────────────────────────────────────────────────
|
───────┬────────────────────────────────────────────────────────────────────────
|
||||||
│ File: test_BOM.txt
|
│ File: test_BOM.txt
|
||||||
─────┼──────────────────────────────────────────────────────────────────────────
|
───────┼────────────────────────────────────────────────────────────────────────
|
||||||
1 │ hello world
|
1 │ hello world
|
||||||
─────┴──────────────────────────────────────────────────────────────────────────
|
───────┴────────────────────────────────────────────────────────────────────────
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1627,15 +1627,16 @@ fn header_narrow_terminal() {
|
|||||||
.success()
|
.success()
|
||||||
.stdout(
|
.stdout(
|
||||||
"\
|
"\
|
||||||
─────┬────────────────────────
|
───────┬──────────────────────
|
||||||
│ File: this-file-path-is
|
│ File: this-file-path-
|
||||||
│ -really-long-and-would-
|
│ is-really-long-and-wo
|
||||||
│ have-broken-the-layout-
|
│ uld-have-broken-the-l
|
||||||
│ of-the-header.txt
|
│ ayout-of-the-header.t
|
||||||
─────┼────────────────────────
|
│ xt
|
||||||
1 │ The header is not broke
|
───────┼──────────────────────
|
||||||
│ n
|
1 │ The header is not bro
|
||||||
─────┴────────────────────────
|
│ ken
|
||||||
|
───────┴──────────────────────
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.stderr("");
|
.stderr("");
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
─────┬──────────────────────────────────────────────────────────────────────────
|
───────┬────────────────────────────────────────────────────────────────────────
|
||||||
│ File: sample.rs
|
│ File: sample.rs
|
||||||
─────┼──────────────────────────────────────────────────────────────────────────
|
───────┼────────────────────────────────────────────────────────────────────────
|
||||||
1 │ /// A rectangle. First line is changed to prevent a regression of #1869
|
1 │ /// A rectangle. First line is changed to prevent a regression of #1869
|
||||||
2 │ struct Rectangle {
|
2 │ struct Rectangle {
|
||||||
3 │ width: u32,
|
3 │ width: u32,
|
||||||
@ -24,4 +24,4 @@
|
|||||||
21 │ fn perimeter(rectangle: &Rectangle) -> u32 {
|
21 │ fn perimeter(rectangle: &Rectangle) -> u32 {
|
||||||
22 │ (rectangle.width + rectangle.height) * 2
|
22 │ (rectangle.width + rectangle.height) * 2
|
||||||
23 │ }
|
23 │ }
|
||||||
─────┴──────────────────────────────────────────────────────────────────────────
|
───────┴────────────────────────────────────────────────────────────────────────
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
─────┬──────────────────────────────────────────────────────────────────────────
|
───────┬────────────────────────────────────────────────────────────────────────
|
||||||
1 │ /// A rectangle. First line is changed to prevent a regression of #1869
|
1 │ /// A rectangle. First line is changed to prevent a regression of #1869
|
||||||
2 │ struct Rectangle {
|
2 │ struct Rectangle {
|
||||||
3 │ width: u32,
|
3 │ width: u32,
|
||||||
@ -22,4 +22,4 @@
|
|||||||
21 │ fn perimeter(rectangle: &Rectangle) -> u32 {
|
21 │ fn perimeter(rectangle: &Rectangle) -> u32 {
|
||||||
22 │ (rectangle.width + rectangle.height) * 2
|
22 │ (rectangle.width + rectangle.height) * 2
|
||||||
23 │ }
|
23 │ }
|
||||||
─────┴──────────────────────────────────────────────────────────────────────────
|
───────┴────────────────────────────────────────────────────────────────────────
|
||||||
|
Loading…
x
Reference in New Issue
Block a user