1use crate::{
2 grid::config::{CompactConfig, CompactMultilineConfig},
3 settings::TableOption,
4};
5
6#[cfg(feature = "std")]
7use crate::grid::config::{ColoredConfig, HorizontalLine as GridLine};
8
9use super::Line;
10
11/// A horizontal split line which can be used to set a border.
12#[cfg_attr(not(feature = "std"), allow(dead_code))]
13#[derive(Debug, Clone)]
14pub struct HorizontalLine {
15 pub(super) index: usize,
16 pub(super) line: Line,
17}
18
19impl HorizontalLine {
20 /// Creates a new horizontal split line.
21 pub const fn new(index: usize, line: Line) -> Self {
22 Self { index, line }
23 }
24
25 /// Sets a horizontal character.
26 pub const fn main(mut self, c: Option<char>) -> Self {
27 self.line.main = c;
28 self
29 }
30
31 /// Sets a vertical intersection character.
32 pub const fn intersection(mut self, c: Option<char>) -> Self {
33 self.line.intersection = c;
34 self
35 }
36
37 /// Sets a left character.
38 pub const fn left(mut self, c: Option<char>) -> Self {
39 self.line.connector1 = c;
40 self
41 }
42
43 /// Sets a right character.
44 pub const fn right(mut self, c: Option<char>) -> Self {
45 self.line.connector2 = c;
46 self
47 }
48}
49
50#[cfg(feature = "std")]
51impl<R, D> TableOption<R, D, ColoredConfig> for HorizontalLine {
52 fn change(self, _: &mut R, cfg: &mut ColoredConfig, _: &mut D) {
53 cfg.insert_horizontal_line(self.index, val:GridLine::from(self.line))
54 }
55}
56
57impl<R, D> TableOption<R, D, CompactConfig> for HorizontalLine {
58 fn change(self, _: &mut R, cfg: &mut CompactConfig, _: &mut D) {
59 if self.index == 1 {
60 *cfg = cfg.set_first_horizontal_line(papergrid::config::Line::from(self.line));
61 }
62 }
63}
64
65impl<R, D> TableOption<R, D, CompactMultilineConfig> for HorizontalLine {
66 fn change(self, records: &mut R, cfg: &mut CompactMultilineConfig, dimension: &mut D) {
67 self.change(records, cfg:cfg.as_mut(), dimension)
68 }
69}
70