aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-symfony-console/src/helper/table_style.rs
blob: 6b0a27a9aeb288e410d9c3d3b7cabfe7d9a920d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//! ref: composer/vendor/symfony/console/Helper/TableStyle.php

/// Defines the styles for a Table.
#[derive(Debug, Clone)]
pub struct TableStyle {
    padding_char: String,
    horizontal_outside_border_char: String,
    horizontal_inside_border_char: String,
    vertical_outside_border_char: String,
    vertical_inside_border_char: String,
    crossing_char: String,
    crossing_top_right_char: String,
    crossing_top_mid_char: String,
    crossing_top_left_char: String,
    crossing_mid_right_char: String,
    crossing_bottom_right_char: String,
    crossing_bottom_mid_char: String,
    crossing_bottom_left_char: String,
    crossing_mid_left_char: String,
    crossing_top_left_bottom_char: String,
    crossing_top_mid_bottom_char: String,
    crossing_top_right_bottom_char: String,
    cell_header_format: String,
    cell_row_format: String,
    cell_row_content_format: String,
    border_format: String,
    pad_type: i64,
}

impl Default for TableStyle {
    fn default() -> Self {
        Self {
            padding_char: " ".to_string(),
            horizontal_outside_border_char: "-".to_string(),
            horizontal_inside_border_char: "-".to_string(),
            vertical_outside_border_char: "|".to_string(),
            vertical_inside_border_char: "|".to_string(),
            crossing_char: "+".to_string(),
            crossing_top_right_char: "+".to_string(),
            crossing_top_mid_char: "+".to_string(),
            crossing_top_left_char: "+".to_string(),
            crossing_mid_right_char: "+".to_string(),
            crossing_bottom_right_char: "+".to_string(),
            crossing_bottom_mid_char: "+".to_string(),
            crossing_bottom_left_char: "+".to_string(),
            crossing_mid_left_char: "+".to_string(),
            crossing_top_left_bottom_char: "+".to_string(),
            crossing_top_mid_bottom_char: "+".to_string(),
            crossing_top_right_bottom_char: "+".to_string(),
            cell_header_format: "<info>%s</info>".to_string(),
            cell_row_format: "%s".to_string(),
            cell_row_content_format: " %s ".to_string(),
            border_format: "%s".to_string(),
            pad_type: shirabe_php_shim::STR_PAD_RIGHT,
        }
    }
}

impl TableStyle {
    /// Gets padding character, used for cell padding.
    pub fn get_padding_char(&self) -> String {
        self.padding_char.clone()
    }

    /// Sets horizontal border characters.
    pub fn set_horizontal_border_chars(
        &mut self,
        outside: String,
        inside: Option<String>,
    ) -> &mut Self {
        self.horizontal_outside_border_char = outside.clone();
        self.horizontal_inside_border_char = inside.unwrap_or(outside);

        self
    }

    /// Sets vertical border characters.
    pub fn set_vertical_border_chars(
        &mut self,
        outside: String,
        inside: Option<String>,
    ) -> &mut Self {
        self.vertical_outside_border_char = outside.clone();
        self.vertical_inside_border_char = inside.unwrap_or(outside);

        self
    }

    /// Gets border characters.
    pub fn get_border_chars(&self) -> Vec<String> {
        vec![
            self.horizontal_outside_border_char.clone(),
            self.vertical_outside_border_char.clone(),
            self.horizontal_inside_border_char.clone(),
            self.vertical_inside_border_char.clone(),
        ]
    }

    /// Sets crossing characters.
    #[allow(clippy::too_many_arguments)]
    pub fn set_crossing_chars(
        &mut self,
        cross: String,
        top_left: String,
        top_mid: String,
        top_right: String,
        mid_right: String,
        bottom_right: String,
        bottom_mid: String,
        bottom_left: String,
        mid_left: String,
        top_left_bottom: Option<String>,
        top_mid_bottom: Option<String>,
        top_right_bottom: Option<String>,
    ) -> &mut Self {
        self.crossing_char = cross.clone();
        self.crossing_top_left_char = top_left;
        self.crossing_top_mid_char = top_mid;
        self.crossing_top_right_char = top_right;
        self.crossing_mid_right_char = mid_right.clone();
        self.crossing_bottom_right_char = bottom_right;
        self.crossing_bottom_mid_char = bottom_mid;
        self.crossing_bottom_left_char = bottom_left;
        self.crossing_mid_left_char = mid_left.clone();
        self.crossing_top_left_bottom_char = top_left_bottom.unwrap_or(mid_left);
        self.crossing_top_mid_bottom_char = top_mid_bottom.unwrap_or(cross);
        self.crossing_top_right_bottom_char = top_right_bottom.unwrap_or(mid_right);

        self
    }

    /// Sets default crossing character used for each cross.
    pub fn set_default_crossing_char(&mut self, char: String) -> &mut Self {
        self.set_crossing_chars(
            char.clone(),
            char.clone(),
            char.clone(),
            char.clone(),
            char.clone(),
            char.clone(),
            char.clone(),
            char.clone(),
            char,
            None,
            None,
            None,
        )
    }

    /// Gets crossing character.
    pub fn get_crossing_char(&self) -> String {
        self.crossing_char.clone()
    }

    /// Gets crossing characters.
    pub fn get_crossing_chars(&self) -> Vec<String> {
        vec![
            self.crossing_char.clone(),
            self.crossing_top_left_char.clone(),
            self.crossing_top_mid_char.clone(),
            self.crossing_top_right_char.clone(),
            self.crossing_mid_right_char.clone(),
            self.crossing_bottom_right_char.clone(),
            self.crossing_bottom_mid_char.clone(),
            self.crossing_bottom_left_char.clone(),
            self.crossing_mid_left_char.clone(),
            self.crossing_top_left_bottom_char.clone(),
            self.crossing_top_mid_bottom_char.clone(),
            self.crossing_top_right_bottom_char.clone(),
        ]
    }

    /// Sets header cell format.
    pub fn set_cell_header_format(&mut self, cell_header_format: String) -> &mut Self {
        self.cell_header_format = cell_header_format;

        self
    }

    /// Gets header cell format.
    pub fn get_cell_header_format(&self) -> String {
        self.cell_header_format.clone()
    }

    /// Gets row cell format.
    pub fn get_cell_row_format(&self) -> String {
        self.cell_row_format.clone()
    }

    /// Sets row cell content format.
    pub fn set_cell_row_content_format(&mut self, cell_row_content_format: String) -> &mut Self {
        self.cell_row_content_format = cell_row_content_format;

        self
    }

    /// Gets row cell content format.
    pub fn get_cell_row_content_format(&self) -> String {
        self.cell_row_content_format.clone()
    }

    /// Gets table border format.
    pub fn get_border_format(&self) -> String {
        self.border_format.clone()
    }

    /// Gets cell padding type.
    pub fn get_pad_type(&self) -> i64 {
        self.pad_type
    }
}