use super::sentence::SentenceOptions;
use super::style::FormatStyle;
#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
pub(crate) struct FormatContext<'a> {
style: FormatStyle,
sentence: SentenceOptions<'a>,
}
#[allow(dead_code)]
impl FormatContext<'static> {
pub(crate) fn new(style: FormatStyle) -> Self {
Self {
style,
sentence: SentenceOptions::default(),
}
}
}
#[allow(dead_code)]
impl<'a> FormatContext<'a> {
pub(crate) fn with_sentence(style: FormatStyle, sentence: SentenceOptions<'a>) -> Self {
Self { style, sentence }
}
pub(crate) fn style(self) -> FormatStyle {
self.style
}
pub(crate) fn sentence(self) -> SentenceOptions<'a> {
self.sentence
}
pub(crate) fn indent_text(self, indent: usize) -> String {
" ".repeat(self.style.indent_width * indent)
}
pub(crate) fn fits_inline(self, indent: usize, text: &str) -> bool {
!text.contains('\n') && text.chars().count() <= self.max_inline_width(indent)
}
fn max_inline_width(self, indent: usize) -> usize {
self.style
.line_width
.saturating_sub(self.style.indent_width * indent)
}
}