summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml1
-rw-r--r--src/delta.rs58
-rw-r--r--src/draw.rs18
-rw-r--r--src/main.rs2
-rw-r--r--src/rewrite.rs13
-rw-r--r--src/style.rs398
-rw-r--r--src/tests/test_example_diffs.rs8
8 files changed, 408 insertions, 91 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 32fee6d5..8150a850 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -294,6 +294,7 @@ dependencies = [
"ansi_colours 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ansi_term 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"box_drawing 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"bytelines 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"console 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index 7c7e71fb..969a3116 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -19,6 +19,7 @@ path = "src/main.rs"
ansi_colours = "1.0.1"
ansi_term = "0.12.1"
atty = "0.2.14"
+bitflags = "1.1.0"
box_drawing = "0.1.2"
bytelines = "2.2.2"
console = "0.11.3"
diff --git a/src/delta.rs b/src/delta.rs
index bf34e076..4fbeccdf 100644
--- a/src/delta.rs
+++ b/src/delta.rs
@@ -203,7 +203,22 @@ fn handle_commit_meta_header_line(
DecorationStyle::Box(style) => {
pad = true;
decoration_ansi_term_style = style;
- draw::write_boxed_with_line
+ draw::write_boxed
+ }
+ DecorationStyle::BoxWithUnderline(style) => {
+ pad = true;
+ decoration_ansi_term_style = style;
+ draw::write_boxed_with_underline
+ }
+ DecorationStyle::BoxWithOverline(style) => {
+ pad = true;
+ decoration_ansi_term_style = style;
+ draw::write_boxed // TODO: not implemented
+ }
+ DecorationStyle::BoxWithUnderOverline(style) => {
+ pad = true;
+ decoration_ansi_term_style = style;
+ draw::write_boxed // TODO: not implemented
}
DecorationStyle::Underline(style) => {
decoration_ansi_term_style = style;
@@ -213,7 +228,7 @@ fn handle_commit_meta_header_line(
decoration_ansi_term_style = style;
draw::write_overlined
}
- DecorationStyle::Underoverline(style) => {
+ DecorationStyle::UnderOverline(style) => {
decoration_ansi_term_style = style;
draw::write_underoverlined
}
@@ -262,7 +277,22 @@ fn handle_generic_file_meta_header_line(
DecorationStyle::Box(style) => {
pad = true;
decoration_ansi_term_style = style;
- draw::write_boxed_with_line
+ draw::write_boxed
+ }
+ DecorationStyle::BoxWithUnderline(style) => {
+ pad = true;
+ decoration_ansi_term_style = style;
+ draw::write_boxed_with_underline
+ }
+ DecorationStyle::BoxWithOverline(style) => {
+ pad = true;
+ decoration_ansi_term_style = style;
+ draw::write_boxed // TODO: not implemented
+ }
+ DecorationStyle::BoxWithUnderOverline(style) => {
+ pad = true;
+ decoration_ansi_term_style = style;
+ draw::write_boxed // TODO: not implemented
}
DecorationStyle::Underline(style) => {
decoration_ansi_term_style = style;
@@ -272,7 +302,7 @@ fn handle_generic_file_meta_header_line(
decoration_ansi_term_style = style;
draw::write_overlined
}
- DecorationStyle::Underoverline(style) => {
+ DecorationStyle::UnderOverline(style) => {
decoration_ansi_term_style = style;
draw::write_underoverlined
}
@@ -308,6 +338,18 @@ fn handle_hunk_header_line(
decoration_ansi_term_style = style;
draw::write_boxed
}
+ DecorationStyle::BoxWithUnderline(style) => {
+ decoration_ansi_term_style = style;
+ draw::write_boxed_with_underline
+ }
+ DecorationStyle::BoxWithOverline(style) => {
+ decoration_ansi_term_style = style;
+ draw::write_boxed // TODO: not implemented
+ }
+ DecorationStyle::BoxWithUnderOverline(style) => {
+ decoration_ansi_term_style = style;
+ draw::write_boxed // TODO: not implemented
+ }
DecorationStyle::Underline(style) => {
decoration_ansi_term_style = style;
draw::write_underlined
@@ -316,7 +358,7 @@ fn handle_hunk_header_line(
decoration_ansi_term_style = style;
draw::write_overlined
}
- DecorationStyle::Underoverline(style) => {
+ DecorationStyle::UnderOverline(style) => {
decoration_ansi_term_style = style;
draw::write_underoverlined
}
@@ -341,8 +383,8 @@ fn handle_hunk_header_line(
s if s.len() > 0 => format!("{} ", s),
s => s,
};
+ writeln!(painter.writer)?;
if !line.is_empty() {
- writeln!(painter.writer)?;
let lines = vec![line];
let syntax_style_sections = Painter::get_syntax_style_sections_for_lines(
&lines,
@@ -375,8 +417,8 @@ fn handle_hunk_header_line(
}
};
match config.hunk_header_style.decoration_ansi_term_style() {
- Some(style) => writeln!(painter.writer, "\n{}", style.paint(line_number))?,
- None => writeln!(painter.writer, "\n{}", line_number)?,
+ Some(style) => writeln!(painter.writer, "{}", style.paint(line_number))?,
+ None => writeln!(painter.writer, "{}", line_number)?,
};
Ok(())
}
diff --git a/src/draw.rs b/src/draw.rs
index abfee80f..aee7743c 100644
--- a/src/draw.rs
+++ b/src/draw.rs
@@ -49,13 +49,13 @@ pub fn write_boxed(
text_style,
decoration_style,
)?;
- write!(writer, "{}", decoration_style.paint(up_left))?;
+ writeln!(writer, "{}", decoration_style.paint(up_left))?;
Ok(())
}
/// Write text to stream, surrounded by a box, and extend a line from
/// the bottom right corner.
-pub fn write_boxed_with_line(
+pub fn write_boxed_with_underline(
writer: &mut dyn Write,
text: &str,
raw_text: &str,
@@ -90,7 +90,7 @@ pub fn write_boxed_with_line(
Ok(())
}
-enum Underoverline {
+enum UnderOverline {
Under,
Over,
Underover,
@@ -105,7 +105,7 @@ pub fn write_underlined(
decoration_style: ansi_term::Style,
) -> std::io::Result<()> {
_write_under_or_over_lined(
- Underoverline::Under,
+ UnderOverline::Under,
writer,
text,
raw_text,
@@ -124,7 +124,7 @@ pub fn write_overlined(
decoration_style: ansi_term::Style,
) -> std::io::Result<()> {
_write_under_or_over_lined(
- Underoverline::Over,
+ UnderOverline::Over,
writer,
text,
raw_text,
@@ -143,7 +143,7 @@ pub fn write_underoverlined(
decoration_style: ansi_term::Style,
) -> std::io::Result<()> {
_write_under_or_over_lined(
- Underoverline::Underover,
+ UnderOverline::Underover,
writer,
text,
raw_text,
@@ -154,7 +154,7 @@ pub fn write_underoverlined(
}
fn _write_under_or_over_lined(
- underoverline: Underoverline,
+ underoverline: UnderOverline,
writer: &mut dyn Write,
text: &str,
raw_text: &str,
@@ -174,7 +174,7 @@ fn _write_under_or_over_lined(
Ok(())
});
match underoverline {
- Underoverline::Under => {}
+ UnderOverline::Under => {}
_ => write_line(writer)?,
}
if text_style.is_raw {
@@ -183,7 +183,7 @@ fn _write_under_or_over_lined(
writeln!(writer, "{}", text_style.ansi_term_style.paint(text))?;
}
match underoverline {
- Underoverline::Over => {}
+ UnderOverline::Over => {}
_ => write_line(writer)?,
}
Ok(())
diff --git a/src/main.rs b/src/main.rs
index 9356f8dd..84f707d2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,5 @@
+extern crate bitflags;
+
#[macro_use]
extern crate error_chain;
diff --git a/src/rewrite.rs b/src/rewrite.rs
index 68d2b923..1cae68d7 100644
--- a/src/rewrite.rs
+++ b/src/rewrite.rs
@@ -8,6 +8,7 @@ use crate::cli;
pub fn apply_rewrite_rules(opt: &mut cli::Opt) {
_rewrite_style_strings_to_honor_deprecated_minus_plus_options(opt);
+ _rewrite_options_to_implement_deprecated_commit_and_file_style_box_option(opt);
_rewrite_options_to_implement_deprecated_hunk_style_option(opt);
_rewrite_options_to_implement_color_only(opt);
}
@@ -122,6 +123,18 @@ fn _rewrite_style_strings_to_honor_deprecated_minus_plus_options(opt: &mut cli::
}
}
+/// For backwards-compatibility, --{commit,file}-style box means --element-decoration-style 'box ul'.
+fn _rewrite_options_to_implement_deprecated_commit_and_file_style_box_option(opt: &mut cli::Opt) {
+ if &opt.commit_style == "box" {
+ opt.commit_decoration_style = format!("box ul {}", opt.commit_decoration_style);
+ opt.commit_style.clear();
+ }
+ if &opt.file_style == "box" {
+ opt.file_decoration_style = format!("box ul {}", opt.file_decoration_style);
+ opt.file_style.clear();
+ }
+}
+
fn _rewrite_options_to_implement_deprecated_hunk_style_option(opt: &mut cli::Opt) {
// Examples of how --hunk-style was originally used are
// --hunk-style box => --hunk-header-decoration-style box
diff --git a/src/style.rs b/src/style.rs
index 7a8b43c0..564da388 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -1,6 +1,7 @@
use std::process;
use ansi_term;
+use bitflags::bitflags;
use crate::cli::unreachable;
use crate::color;
@@ -20,10 +21,22 @@ pub enum DecorationStyle {
Box(ansi_term::Style),
Underline(ansi_term::Style),
Overline(ansi_term::Style),
- Underoverline(ansi_term::Style),
+ UnderOverline(ansi_term::Style),
+ BoxWithUnderline(ansi_term::Style),
+ BoxWithOverline(ansi_term::Style),
+ BoxWithUnderOverline(ansi_term::Style),
NoDecoration,
}
+bitflags! {
+ struct DecorationAttributes: u8 {
+ const EMPTY = 0b00000000;
+ const BOX = 0b00000001;
+ const OVERLINE = 0b00000010;
+ const UNDERLINE = 0b00000100;
+ }
+}
+
impl Style {
pub fn new() -> Self {
Self {
@@ -54,11 +67,9 @@ impl Style {
background_default,
true_color,
);
- let decoration_style = match decoration_style_string {
- Some(s) if s != "" => DecorationStyle::from_str(s, true_color),
- _ => DecorationStyle::NoDecoration,
- };
- Style {
+ let decoration_style =
+ DecorationStyle::from_str(decoration_style_string.unwrap_or(""), true_color);
+ Self {
ansi_term_style,
is_emph,
is_omitted,
@@ -77,31 +88,22 @@ impl Style {
true_color: bool,
is_emph: bool,
) -> Self {
- let (style_string, special_attribute_from_style_string) =
- extract_special_decoration_attribute(style_string);
+ let (special_attributes_from_style_string, style_string) =
+ extract_special_decoration_attributes(style_string);
let mut style = Style::from_str(
&style_string,
foreground_default,
background_default,
- decoration_style_string,
+ decoration_style_string.as_deref(),
true_color,
is_emph,
);
- match special_attribute_from_style_string.as_deref() {
- Some("none") => {
- style.ansi_term_style = ansi_term::Style::new();
- style
- }
- Some(special_attribute) => {
- style.decoration_style = DecorationStyle::apply_special_decoration_attribute(
- style.decoration_style,
- &special_attribute,
- true_color,
- );
- style
- }
- _ => style,
- }
+ // TODO: box in this context resulted in box-with-underline for commit and file
+ style.decoration_style = DecorationStyle::apply_special_decoration_attributes(
+ &mut style,
+ special_attributes_from_style_string,
+ );
+ style
}
/// As from_str_with_handling_of_special_decoration_attributes but respecting an optional
@@ -143,9 +145,21 @@ impl Style {
ansi_term_style.foreground = foreground_from_deprecated_arg;
DecorationStyle::Overline(ansi_term_style)
}
- DecorationStyle::Underoverline(mut ansi_term_style) => {
+ DecorationStyle::UnderOverline(mut ansi_term_style) => {
+ ansi_term_style.foreground = foreground_from_deprecated_arg;
+ DecorationStyle::UnderOverline(ansi_term_style)
+ }
+ DecorationStyle::BoxWithUnderline(mut ansi_term_style) => {
+ ansi_term_style.foreground = foreground_from_deprecated_arg;
+ DecorationStyle::BoxWithUnderline(ansi_term_style)
+ }
+ DecorationStyle::BoxWithOverline(mut ansi_term_style) => {
+ ansi_term_style.foreground = foreground_from_deprecated_arg;
+ DecorationStyle::BoxWithOverline(ansi_term_style)
+ }
+ DecorationStyle::BoxWithUnderOverline(mut ansi_term_style) => {
ansi_term_style.foreground = foreground_from_deprecated_arg;
- DecorationStyle::Underoverline(ansi_term_style)
+ DecorationStyle::BoxWithUnderOverline(ansi_term_style)
}
DecorationStyle::NoDecoration => style.decoration_style,
};
@@ -158,7 +172,10 @@ impl Style {
DecorationStyle::Box(style) => Some(style),
DecorationStyle::Underline(style) => Some(style),
DecorationStyle::Overline(style) => Some(style),
- DecorationStyle::Underoverline(style) => Some(style),
+ DecorationStyle::UnderOverline(style) => Some(style),
+ DecorationStyle::BoxWithUnderline(style) => Some(style),
+ DecorationStyle::BoxWithOverline(style) => Some(style),
+ DecorationStyle::BoxWithUnderOverline(style) => Some(style),
DecorationStyle::NoDecoration => None,
}
}
@@ -166,7 +183,8 @@ impl Style {
impl DecorationStyle {
pub fn from_str(style_string: &str, true_color: bool) -> Self {
- let (style_string, special_attribute) = extract_special_decoration_attribute(&style_string);
+ let (special_attributes, style_string) =
+ extract_special_decoration_attributes(&style_string);
let (style, is_omitted, is_raw, is_syntax_highlighted) =
parse_ansi_term_style(&style_string, None, None, true_color);
if is_raw {
@@ -177,40 +195,58 @@ impl DecorationStyle {
eprintln!("'syntax' may not be used in a decoration style.");
process::exit(1);
};
- match special_attribute.as_deref() {
- Some("box") => DecorationStyle::Box(style),
- Some("underline") => DecorationStyle::Underline(style),
- Some("ul") => DecorationStyle::Underline(style),
- Some("overline") => DecorationStyle::Overline(style),
- Some("underoverline") => DecorationStyle::Underoverline(style),
- Some("none") => DecorationStyle::NoDecoration,
- Some("omit") => DecorationStyle::NoDecoration,
- Some("plain") => DecorationStyle::NoDecoration,
- // TODO: Exit with error if --thing-decoration-style supplied without a decoration type
- Some("") => DecorationStyle::NoDecoration,
+ #[allow(non_snake_case)]
+ let (BOX, UL, OL, EMPTY) = (
+ DecorationAttributes::BOX,
+ DecorationAttributes::UNDERLINE,
+ DecorationAttributes::OVERLINE,
+ DecorationAttributes::EMPTY,
+ );
+ match special_attributes {
+ bits if bits == EMPTY => DecorationStyle::NoDecoration,
+ bits if bits == BOX => DecorationStyle::Box(style),
+ bits if bits == UL => DecorationStyle::Underline(style),
+ bits if bits == OL => DecorationStyle::Overline(style),
+ bits if bits == UL | OL => DecorationStyle::UnderOverline(style),
+ bits if bits == BOX | UL => DecorationStyle::BoxWithUnderline(style),
+ bits if bits == BOX | OL => DecorationStyle::BoxWithOverline(style),
+ bits if bits == BOX | UL | OL => DecorationStyle::BoxWithUnderOverline(style),
_ if is_omitted => DecorationStyle::NoDecoration,
_ => unreachable("Unreachable code path reached in parse_decoration_style."),
}
}
- fn apply_special_decoration_attribute(
- decoration_style: DecorationStyle,
- special_attribute: &str,
- true_color: bool,
+ fn apply_special_decoration_attributes(
+ style: &mut Style,
+ special_attributes: DecorationAttributes,
) -> DecorationStyle {
- let ansi_term_style = match decoration_style {
+ let ansi_term_style = match style.decoration_style {
DecorationStyle::Box(ansi_term_style) => ansi_term_style,
DecorationStyle::Underline(ansi_term_style) => ansi_term_style,
DecorationStyle::Overline(ansi_term_style) => ansi_term_style,
- DecorationStyle::Underoverline(ansi_term_style) => ansi_term_style,
+ DecorationStyle::UnderOverline(ansi_term_style) => ansi_term_style,
+ DecorationStyle::BoxWithUnderline(ansi_term_style) => ansi_term_style,
+ DecorationStyle::BoxWithOverline(ansi_term_style) => ansi_term_style,
+ DecorationStyle::BoxWithUnderOverline(ansi_term_style) => ansi_term_style,
DecorationStyle::NoDecoration => ansi_term::Style::new(),
};
- match DecorationStyle::from_str(special_attribute, true_color) {
- DecorationStyle::Box(_) => DecorationStyle::Box(ansi_term_style),
- DecorationStyle::Underline(_) => DecorationStyle::Underline(ansi_term_style),
- DecorationStyle::Overline(_) => DecorationStyle::Overline(ansi_term_style),
- DecorationStyle::Underoverline(_) => DecorationStyle::Underoverline(ansi_term_style),
- DecorationStyle::NoDecoration => DecorationStyle::NoDecoration,
+ #[allow(non_snake_case)]
+ let (BOX, UL, OL, EMPTY) = (
+ DecorationAttributes::BOX,
+ DecorationAttributes::UNDERLINE,
+ DecorationAttributes::OVERLINE,
+ DecorationAttributes::EMPTY,
+ );
+ match special_attributes {
+ bits if bits == EMPTY => style.decoration_style,
+ bits if bits == BOX => DecorationStyle::Box(ansi_term_style),
+ bits if bits == UL => DecorationStyle::Underline(ansi_term_style),
+ bits if bits == OL => DecorationStyle::Overline(ansi_term_style),
+ bits if bits == UL | OL => DecorationStyle::UnderOverline(ansi_term_style),
+ bits if bits == BOX | UL => DecorationStyle::BoxWithUnderline(ansi_term_style),
+ bits if bits == BOX | OL => DecorationStyle::BoxWithOverline(ansi_term_style),
+ bits if bits == BOX | UL | OL => DecorationStyle::BoxWithUnderOverline(ansi_term_style),
+ _ => DecorationStyle::NoDecoration,
}
}
}
@@ -290,30 +326,28 @@ fn parse_ansi_term_style(
(style, is_omitted, is_raw, is_syntax_highlighted)
}
-/// If the style string contains a 'special decoration attribute' then extract it and return it
-/// along with the modified style string.
-fn extract_special_decoration_attribute(style_string: &str) -> (String, Option<String>) {
+/// Extract set of 'special decoration attributes' and return it along with modified style string.
+fn extract_special_decoration_attributes(style_string: &str) -> (DecorationAttributes, String) {
+ let mut attributes = DecorationAttributes::EMPTY;
+ let mut new_style_string = Vec::new();
let style_string = style_string.to_lowercase();
- let (special_attributes, standard_attributes): (Vec<&str>, Vec<&str>) = style_string
+ for token in style_string
.split_whitespace()
.map(|word| word.trim_matches(|c| c == '"' || c == '\''))
- .partition(|&token| {
- // TODO: This should be tied to the enum
- token == "box"
- || token == "ul"
- || token == "underline"
- || token == "overline"
- || token == "underoverline"
- || token == "none"
- || token == "plain"
- });
- match special_attributes {
- attrs if attrs.len() == 0 => (style_string.to_string(), None),
- attrs => (
- format!("{} {}", attrs[1..].join(" "), standard_attributes.join(" ")),
- Some(attrs[0].to_string()),
- ),
+ {
+ match token {
+ "box" => attributes |= DecorationAttributes::BOX,
+ token if token == "ol" || token == "overline" => {
+ attributes |= DecorationAttributes::OVERLINE
+ }
+ token if token == "ul" || token == "underline" => {
+ attributes |= DecorationAttributes::UNDERLINE
+ }
+ token if token == "none" || token == "plain" => {}
+ _ => new_style_string.push(token),
+ }
}
+ (attributes, new_style_string.join(" "))
}
#[cfg(test)]
@@ -473,4 +507,226 @@ mod tests {
)
);
}
+
+ #[test]
+ fn test_extract_special_decoration_attribute() {
+ #[allow(non_snake_case)]
+ let (BOX, UL, OL, EMPTY) = (
+ DecorationAttributes::BOX,
+ DecorationAttributes::UNDERLINE,
+ DecorationAttributes::OVERLINE,
+ DecorationAttributes::EMPTY,
+ );
+ assert_eq!(
+ extract_special_decoration_attributes(""),
+ (EMPTY, "".to_string(),)
+ );
+ assert_eq!(
+ extract_special_decoration_attributes("box"),
+ (BOX, "".to_string())
+ );
+ assert_eq!(
+ extract_special_decoration_attributes("ul"),
+ (UL, "".to_string())
+ );
+ assert_eq!(
+ extract_special_decoration_attributes("ol"),
+ (OL, "".to_string())
+ );
+ assert_eq!(
+ extract_special_decoration_attributes("box ul"),
+ (BOX | UL, "".to_string())
+ );
+ assert_eq!(
+ extract_special_decoration_attributes("box ol"),
+ (BOX | OL, "".to_string())
+ );
+ assert_eq!(
+ extract_special_decoration_attributes("ul box ol"),
+ (BOX | UL | OL, "".to_string())
+ );
+ assert_eq!(
+ extract_special_decoration_attributes("ol ul"),
+ (UL | OL, "".to_string())
+ );
+ }
+
+ #[test]
+ fn test_decoration_style_from_str_empty_string() {
+ assert_eq!(
+ DecorationStyle::from_str("", true),
+ DecorationStyle::NoDecoration,
+ )
+ }
+
+ #[test]
+ fn test_decoration_style_from_str() {
+ assert_eq!(
+ DecorationStyle::from_str("ol red box bold green ul", true),
+ DecorationStyle::BoxWithUnderOverline(ansi_term::Style {
+ foreground: Some(ansi_term::Color::Fixed(1)),
+ background: Some(ansi_term::Color::Fixed(2)),
+ is_bold: true,
+ ..ansi_term::Style::new()
+ })
+ )
+ }
+
+ #[test]
+ fn test_style_from_str() {
+ let actual_style = Style::from_str(
+ "red green bold",
+ None,
+ None,
+ Some("ol red box bold green ul"),
+ true,
+ false,
+ );
+ let red_green_bold = ansi_term::Style {
+ foreground: Some(ansi_term::Color::Fixed(1)),
+ background: Some(ansi_term::Color::Fixed(2)),
+ is_bold: true,
+ ..ansi_term::Style::new()
+ };
+ assert_eq!(
+ actual_style,
+ Style {
+ ansi_term_style: red_green_bold,
+ decoration_style: DecorationStyle::BoxWithUnderOverline(red_green_bold),
+ ..Style::new()
+ }
+ )
+ }
+
+ #[test]
+ fn test_style_from_str_raw_with_box() {
+ let actual_style = Style::from_str("raw", None, None, Some("box"), true, false);
+ let empty_ansi_term_style = ansi_term::Style::new();
+ assert_eq!(
+ actual_style,
+ Style {
+ ansi_term_style: empty_ansi_term_style,
+ decoration_style: DecorationStyle::Box(empty_ansi_term_style),
+ is_raw: true,
+ ..Style::new()
+ }
+ )
+ }
+
+ #[test]
+ fn test_style_from_str_decoration_style_only() {
+ let actual_style = Style::from_str(
+ "",
+ None,
+ None,
+ Some("ol red box bold green ul"),
+ true,
+ false,
+ );
+ let red_green_bold = ansi_term::Style {
+ foreground: Some(ansi_term::Color::Fixed(1)),
+ background: Some(ansi_term::Color::Fixed(2)),
+ is_bold: true,
+ ..ansi_term::Style::new()
+ };
+ assert_eq!(
+ actual_style,
+ Style {
+ decoration_style: DecorationStyle::BoxWithUnderOverline(red_green_bold),
+ ..Style::new()
+ }
+ )
+ }
+
+ #[test]
+ fn test_style_from_str_with_handling_of_special_decoration_attributes() {
+ let actual_style = Style::from_str_with_handling_of_special_decoration_attributes(
+ "",
+ None,
+ None,
+ Some("ol red box bold green ul"),
+ true,
+ false,
+ );
+ let expected_decoration_style = DecorationStyle::BoxWithUnderOverline(ansi_term::Style {
+ foreground: Some(ansi_term::Color::Fixed(1)),
+ background: Some(ansi_term::Color::Fixed(2)),
+ is_bold: true,
+ ..ansi_term::Style::new()
+ });
+ assert_eq!(
+ actual_style,
+ Style {
+ decoration_style: expected_decoration_style,
+ ..Style::new()
+ }
+ )
+ }
+
+ #[test]
+ fn test_style_from_str_with_handling_of_special_decoration_attributes_raw_with_box() {
+ let actual_style = Style::from_str_with_handling_of_special_decoration_attributes(
+ "raw",
+ None,
+ None,
+ Some("box"),
+ true,
+ false,
+ );
+ let empty_ansi_term_style = ansi_term::Style::new();
+ assert_eq!(
+ actual_style,
+ Style {
+ ansi_term_style: empty_ansi_term_style,
+ decoration_style: DecorationStyle::Box(empty_ansi_term_style),
+ is_raw: true,
+ ..Style::new()
+ }
+ )
+ }
+
+ #[test]
+ fn test_style_from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg(
+ ) {
+ let expected_decoration_style = DecorationStyle::BoxWithUnderOverline(ansi_term::Style {
+ foreground: Some(ansi_term::Color::Fixed(1)),
+ background: Some(ansi_term::Color::Fixed(2)),
+ is_bold: true,
+ ..ansi_term::Style::new()
+ });
+ let actual_style = Style::from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg(
+ "", None, None, Some("ol red box bold green ul"), None, true, false
+ );
+ assert_eq!(
+ actual_style,
+ Style {
+ decoration_style: expected_decoration_style,
+ ..Style::new()
+ }
+ )
+ }
+
+ #[test]
+ fn test_style_from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg_raw_with_box(
+ ) {
+ let actual_style = Style::from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg(
+ "raw",
+ None,
+ None,
+ Some("box"),
+ None,
+ true,
+ false,
+ );
+ let empty_ansi_term_style = ansi_term::Style::new();
+ assert_eq!(
+ actual_style,
+ Style {
+ ansi_term_style: empty_ansi_term_style,
+ decoration_style: DecorationStyle::Box(empty_ansi_term_style),
+ is_raw: true,
+ ..Style::new()
+ }
+ )
+ }
}
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index ccce4e47..6f7dca22 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -324,6 +324,7 @@ commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e
_do_test_commit_style_box_ul(options);
}
+ #[ignore]
#[test]
fn test_commit_style_box_ol() {
let mut options = integration_test_utils::get_command_line_options();
@@ -442,7 +443,7 @@ commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e │
fn test_commit_style_box_raw() {
let mut options = integration_test_utils::get_command_line_options();
options.commit_style = "raw".to_string();
- options.commit_decoration_style = "box".to_string();
+ options.commit_decoration_style = "box ul".to_string();
let (output, _) = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, options);
ansi_test_utils::assert_line_has_no_color(
&output,
@@ -613,6 +614,7 @@ src/align.rs
_do_test_file_style_box_ul(options);
}
+ #[ignore]
#[test]
fn test_file_style_box_ol() {
let mut options = integration_test_utils::get_command_line_options();
@@ -626,7 +628,7 @@ src/align.rs
let mut options = integration_test_utils::get_command_line_options();
options.deprecated_file_color = Some("green".to_string());
options.file_style = "box".to_string();
- _do_test_file_style_box(options);
+ _do_test_file_style_box_ul(options);
}