From 7c93d279e60253fc380d73f2f84fe5e2a4a274e6 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Wed, 21 Apr 2021 07:50:23 -0400 Subject: Rename syntect module --- src/color.rs | 6 +++--- src/config.rs | 4 ++-- src/main.rs | 3 ++- src/syntect_color.rs | 15 --------------- src/syntect_utils.rs | 15 +++++++++++++++ 5 files changed, 22 insertions(+), 21 deletions(-) delete mode 100644 src/syntect_color.rs create mode 100644 src/syntect_utils.rs (limited to 'src') diff --git a/src/color.rs b/src/color.rs index 8b7428be..e7c3f62f 100644 --- a/src/color.rs +++ b/src/color.rs @@ -7,7 +7,7 @@ use lazy_static::lazy_static; use syntect::highlighting::Color as SyntectColor; use crate::bat_utils::terminal::to_ansi_color; -use crate::syntect_color; +use crate::syntect_utils; pub fn parse_color(s: &str, true_color: bool) -> Option { if s == "normal" { @@ -22,8 +22,8 @@ pub fn parse_color(s: &str, true_color: bool) -> Option { } else { s.parse::() .ok() - .and_then(syntect_color::syntect_color_from_ansi_number) - .or_else(|| syntect_color::syntect_color_from_ansi_name(s)) + .and_then(syntect_utils::syntect_color_from_ansi_number) + .or_else(|| syntect_utils::syntect_color_from_ansi_name(s)) .unwrap_or_else(die) }; to_ansi_color(syntect_color, true_color) diff --git a/src/config.rs b/src/config.rs index 4a93cfe2..15b3b75d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -21,7 +21,7 @@ use crate::features::side_by_side; use crate::git_config::{GitConfig, GitConfigEntry}; use crate::paint::BgFillMethod; use crate::style::{self, Style}; -use crate::syntect_color; +use crate::syntect_utils; use crate::wrapping::WrapConfig; pub const INLINE_SYMBOL_WIDTH_1: usize = 1; @@ -292,7 +292,7 @@ impl From for Config { hyperlinks_file_link_format: opt.hyperlinks_file_link_format, inspect_raw_lines: opt.computed.inspect_raw_lines, inline_hint_color: Some(SyntectStyle { - foreground: syntect_color::syntect_color_from_ansi_name("blue").unwrap(), + foreground: syntect_utils::syntect_color_from_ansi_name("blue").unwrap(), ..SyntectStyle::default() }), keep_plus_minus_markers: opt.keep_plus_minus_markers, diff --git a/src/main.rs b/src/main.rs index 8b382a34..21b6e749 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,8 @@ mod style; mod wrapping; mod subcommands; -mod syntect_color; +mod syntect_utils; + mod tests; use std::io::{self, ErrorKind}; diff --git a/src/syntect_color.rs b/src/syntect_color.rs deleted file mode 100644 index 3569b318..00000000 --- a/src/syntect_color.rs +++ /dev/null @@ -1,15 +0,0 @@ -use std::str::FromStr; - -use syntect::highlighting::Color; - -use crate::color; - -pub fn syntect_color_from_ansi_name(name: &str) -> Option { - color::ansi_16_color_name_to_number(name).and_then(syntect_color_from_ansi_number) -} - -/// Convert 8-bit ANSI code to #RGBA string with ANSI code in red channel and 0 in alpha channel. -// See https://github.com/sharkdp/bat/pull/543 -pub fn syntect_color_from_ansi_number(n: u8) -> Option { - Color::from_str(&format!("#{:02x}000000", n)).ok() -} diff --git a/src/syntect_utils.rs b/src/syntect_utils.rs new file mode 100644 index 00000000..3569b318 --- /dev/null +++ b/src/syntect_utils.rs @@ -0,0 +1,15 @@ +use std::str::FromStr; + +use syntect::highlighting::Color; + +use crate::color; + +pub fn syntect_color_from_ansi_name(name: &str) -> Option { + color::ansi_16_color_name_to_number(name).and_then(syntect_color_from_ansi_number) +} + +/// Convert 8-bit ANSI code to #RGBA string with ANSI code in red channel and 0 in alpha channel. +// See https://github.com/sharkdp/bat/pull/543 +pub fn syntect_color_from_ansi_number(n: u8) -> Option { + Color::from_str(&format!("#{:02x}000000", n)).ok() +} -- cgit v1.2.3