Skip to main content

renderdag/
output.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8use std::marker::PhantomData;
9
10use super::ascii::AsciiRenderer;
11use super::ascii_large::AsciiLargeRenderer;
12use super::box_drawing::BoxDrawingRenderer;
13use super::render::GraphRow;
14use super::render::Renderer;
15
16pub(crate) struct OutputRendererOptions {
17    pub(crate) min_row_height: usize,
18}
19
20pub struct OutputRendererBuilder<N, R>
21where
22    R: Renderer<N, Output = GraphRow<N>> + Sized,
23{
24    inner: R,
25    options: OutputRendererOptions,
26    _phantom: PhantomData<N>,
27}
28
29impl<N, R> OutputRendererBuilder<N, R>
30where
31    R: Renderer<N, Output = GraphRow<N>> + Sized,
32{
33    pub fn new(inner: R) -> Self {
34        OutputRendererBuilder {
35            inner,
36            options: OutputRendererOptions { min_row_height: 2 },
37            _phantom: PhantomData,
38        }
39    }
40
41    pub fn with_min_row_height(mut self, min_row_height: usize) -> Self {
42        self.options.min_row_height = min_row_height;
43        self
44    }
45
46    pub fn build_ascii(self) -> AsciiRenderer<N, R> {
47        AsciiRenderer::new(self.inner, self.options)
48    }
49
50    pub fn build_ascii_large(self) -> AsciiLargeRenderer<N, R> {
51        AsciiLargeRenderer::new(self.inner, self.options)
52    }
53
54    pub fn build_box_drawing(self) -> BoxDrawingRenderer<N, R> {
55        BoxDrawingRenderer::new(self.inner, self.options)
56    }
57}