#[derive(PartialEq, Debug, Clone, Copy)]
pub enum NumberingMode {
None,
NonEmpty,
All,
}
pub struct Options {
pub number: NumberingMode,
pub show_ends: bool,
pub squeeze_blank: bool,
pub show_tabs: bool,
pub show_nonprinting: bool,
}
impl Options {
pub fn new() -> Self {
Self {
number: NumberingMode::None,
show_ends: false,
squeeze_blank: false,
show_tabs: false,
show_nonprinting: false,
}
}
pub fn number(mut self, number: NumberingMode) -> Self {
self.number = number;
self
}
pub fn show_ends(mut self, show_ends: bool) -> Self {
self.show_ends = show_ends;
self
}
pub fn squeeze_blank(mut self, squeeze_blank: bool) -> Self {
self.squeeze_blank = squeeze_blank;
self
}
pub fn show_tabs(mut self, show_tabs: bool) -> Self {
self.show_tabs = show_tabs;
self
}
pub fn show_nonprinting(mut self, show_nonprinting: bool) -> Self {
self.show_nonprinting = show_nonprinting;
self
}
}
impl Options {
pub(crate) fn tab(&self) -> &'static str {
if self.show_tabs {
"^I"
} else {
"\t"
}
}
pub(crate) fn end_of_line(&self) -> &'static str {
if self.show_ends {
"$\n"
} else {
"\n"
}
}
pub(crate) fn can_write_fast(&self) -> bool {
!(self.show_tabs
|| self.show_nonprinting
|| self.show_ends
|| self.squeeze_blank
|| self.number != NumberingMode::None)
}
}