#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum WrapMode {
#[default]
Reflow,
Stable,
Sentence,
Semantic,
Preserve,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum MathWrap {
#[default]
Auto,
Preserve,
SingleLine,
Break,
}
impl MathWrap {
#[must_use]
pub fn resolve(self, wrap: WrapMode) -> Self {
match self {
Self::Auto => {
if wrap == WrapMode::Preserve {
Self::Preserve
} else {
Self::Break
}
}
other => other,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FormatStyle {
pub line_width: usize,
pub indent_width: usize,
pub wrap: WrapMode,
pub math_wrap: MathWrap,
}
impl Default for FormatStyle {
fn default() -> Self {
Self {
line_width: 80,
indent_width: 2,
wrap: WrapMode::default(),
math_wrap: MathWrap::default(),
}
}
}
pub(crate) const STABLE_WRAP_TARGET_OFFSET: usize = 15;
impl FormatStyle {
pub(crate) fn stable_wrap_target(self) -> usize {
self.line_width
.saturating_sub(STABLE_WRAP_TARGET_OFFSET)
.clamp(1, self.line_width.max(1))
}
}