#[derive(Debug, Clone)]
pub struct FormattingOptions {
pub double_quot: bool,
pub new_lines: bool,
pub max_len: usize,
pub tab_size: u8,
}
impl FormattingOptions {
pub fn pretty() -> Self {
Self::default()
}
pub fn compact() -> Self {
Self {
double_quot: false,
new_lines: false,
max_len: 0,
tab_size: 0,
}
}
pub fn quotes(&self) -> char {
match self.double_quot {
true => '"',
false => '\'',
}
}
pub fn fmt_depth<W>(&self, f: &mut W, depth: usize) -> std::fmt::Result
where
W: std::fmt::Write,
{
if self.tab_size == 0 || depth < self.tab_size as usize {
return Ok(());
}
let tabs = depth / self.tab_size as usize;
for _ in 0..tabs {
write!(f, "\t")?;
}
Ok(())
}
}
impl Default for FormattingOptions {
fn default() -> Self {
Self {
double_quot: false,
new_lines: true,
max_len: 60,
tab_size: 4,
}
}
}