fmt: fix write_char not respecting indent string

take default indent string from env!
This commit is contained in:
2025-12-01 23:09:58 -05:00
parent 2e5cd3029f
commit 7ea483fe26

View File

@@ -2,11 +2,19 @@
use std::fmt::{Display, Write};
/// The default indentation string. Defaults to four spaces.
const INDENTATION: &str = {
match option_env!("DOUGHLANG_INDENT") {
Some(indent) => indent,
None => " ",
}
};
impl<W: Write + ?Sized> FmtAdapter for W {}
pub trait FmtAdapter: Write {
/// Indents by one level.
fn indent(&mut self) -> Indent<'_, Self> {
Indent::new(self, " ")
Indent::new(self, INDENTATION)
}
/// Pastes `indent` after each newline.
@@ -99,7 +107,7 @@ impl<F: Write + ?Sized> Write for Indent<'_, F> {
}
fn write_char(&mut self, c: char) -> std::fmt::Result {
if self.needs_indent {
self.f.write_str(" ")?;
self.f.write_str(self.indent)?;
}
self.needs_indent = c == '\n';
self.f.write_char(c)