fmt: fix write_char not respecting indent string
take default indent string from env!
This commit is contained in:
12
src/fmt.rs
12
src/fmt.rs
@@ -2,11 +2,19 @@
|
|||||||
|
|
||||||
use std::fmt::{Display, Write};
|
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 {}
|
impl<W: Write + ?Sized> FmtAdapter for W {}
|
||||||
pub trait FmtAdapter: Write {
|
pub trait FmtAdapter: Write {
|
||||||
/// Indents by one level.
|
/// Indents by one level.
|
||||||
fn indent(&mut self) -> Indent<'_, Self> {
|
fn indent(&mut self) -> Indent<'_, Self> {
|
||||||
Indent::new(self, " ")
|
Indent::new(self, INDENTATION)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pastes `indent` after each newline.
|
/// 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 {
|
fn write_char(&mut self, c: char) -> std::fmt::Result {
|
||||||
if self.needs_indent {
|
if self.needs_indent {
|
||||||
self.f.write_str(" ")?;
|
self.f.write_str(self.indent)?;
|
||||||
}
|
}
|
||||||
self.needs_indent = c == '\n';
|
self.needs_indent = c == '\n';
|
||||||
self.f.write_char(c)
|
self.f.write_char(c)
|
||||||
|
|||||||
Reference in New Issue
Block a user