|
| 1 | +pub mod styles; |
| 2 | + |
| 3 | +use super::Renderer as RendererTrait; |
| 4 | +use crate::display_list::line::DisplayLine; |
| 5 | +use crate::display_list::line::DisplayRawLine; |
| 6 | +use crate::DisplayList; |
| 7 | +use std::io::Write; |
| 8 | +use std::marker::PhantomData; |
| 9 | +use styles::Style as StyleTrait; |
| 10 | + |
| 11 | +pub struct Renderer<S: StyleTrait> { |
| 12 | + style: PhantomData<S>, |
| 13 | +} |
| 14 | + |
| 15 | +impl<S: StyleTrait> Renderer<S> { |
| 16 | + pub fn new() -> Self { |
| 17 | + Renderer { style: PhantomData } |
| 18 | + } |
| 19 | + |
| 20 | + pub fn fmt(&self, w: &mut impl Write, dl: &DisplayList) -> std::io::Result<()> { |
| 21 | + for line in &dl.body { |
| 22 | + self.fmt_line(w, line)?; |
| 23 | + } |
| 24 | + Ok(()) |
| 25 | + } |
| 26 | + |
| 27 | + fn fmt_line(&self, w: &mut impl Write, line: &DisplayLine) -> std::io::Result<()> { |
| 28 | + match line { |
| 29 | + DisplayLine::Raw(l) => self.fmt_raw_line(w, l), |
| 30 | + _ => Ok(()), |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + fn fmt_raw_line( |
| 35 | + &self, |
| 36 | + w: &mut impl std::io::Write, |
| 37 | + line: &DisplayRawLine, |
| 38 | + ) -> std::io::Result<()> { |
| 39 | + match line { |
| 40 | + DisplayRawLine::Origin { path, .. } => { |
| 41 | + let _lineno_max = 1; |
| 42 | + S::fmt(w, path) |
| 43 | + //write!(w, "{:>1$}", "", lineno_max)?; |
| 44 | + //write!(w, "--> {}", path)?; |
| 45 | + //if let Some(line) = pos.0 { |
| 46 | + //write!(w, ":{}", line)?; |
| 47 | + //} |
| 48 | + //w.write_char('\n') |
| 49 | + } |
| 50 | + _ => Ok(()), |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +impl<S: StyleTrait> RendererTrait for Renderer<S> { |
| 56 | + fn fmt(&self, w: &mut impl Write, dl: &DisplayList) -> std::io::Result<()> { |
| 57 | + Renderer::fmt(self, w, dl) |
| 58 | + } |
| 59 | +} |
0 commit comments