use std::cmp::max;
use lazy_static::lazy_static;
use regex::Regex;
use crate::config;
use crate::delta::State;
use crate::features::hyperlinks;
use crate::features::side_by_side::ansifill::{self, ODD_PAD_CHAR};
use crate::features::side_by_side::{Left, PanelSide, Right};
use crate::features::OptionValueFunction;
use crate::format::{self, Align, Placeholder};
use crate::minusplus::*;
use crate::style::Style;
pub fn make_feature() -> Vec<(String, OptionValueFunction)> {
builtin_feature!([
(
"line-numbers",
bool,
None,
_opt => true
),
(
"line-numbers-left-style",
String,
None,
_opt => "blue"
),
(
"line-numbers-right-style",
String,
None,
_opt => "blue"
),
(
"line-numbers-minus-style",
String,
None,
opt => if opt.computed.is_light_mode {
"red".to_string()
} else {
"88".to_string()
}
),
(
"line-numbers-zero-style",
String,
None,
opt => if opt.computed.is_light_mode {"#dddddd"} else {"#444444"}
),
(
"line-numbers-plus-style",
String,
None,
opt => if opt.computed.is_light_mode {
"green".to_string()
} else {
"28".to_string()
}
)
])
}
pub fn linenumbers_and_styles<'a>(
line_numbers_data: &'a mut LineNumbersData,
state: &State,
config: &'a config::Config,
increment: bool,
) -> Option<(MinusPlus<Option<usize>>, MinusPlus<Style>)> {
let nr_left = line_numbers_data.line_number[Left];
let nr_right = line_numbers_data.line_number[Right];
let (minus_style, zero_style, plus_style) = (
config.line_numbers_style_minusplus[Minus],
config.line_numbers_zero_style,
config.line_numbers_style_minusplus[Plus],
);
let ((minus_number, plus_number), (minus_style, plus_style)) = match state {
State::HunkMinus(_) => {
line_numbers_data.line_number[Left] += increment as usize;
((Some(nr_left), None), (minus_style, plus_style))
}
State::HunkMinusWrapped => ((None, None), (minus_style, plus_style)),
State::HunkZero => {
line_numbers_data.line_number[Left] += increment as usize;
line_numbers_data.line_number[Right] += increment as usize;
((Some(nr_left), Some(nr_right)), (zero_style, zero_style))
}
State::HunkZeroWrapped => ((None, None), (zero_style, zero_style)),
State::HunkPlus(_) => {
line_numbers_data.line_number[Right] += increment as usize;
((None, Some(nr_right)), (minus_style, plus_style))
}
State::HunkPlusWrapped => ((None, None), (minus_style, plus_style)),
_ => return None,
};
Some((
MinusPlus::new(minus_number,