logparse_pretty_print/helpers/
k_and_r_bracket.rs1use super::*;
2use crate::{PrettyBuilder, Text};
3
4#[derive(Copy, Clone, Debug)]
16pub struct KAndRBracket {
17 pub head_space: bool,
19 pub bracket_l: &'static str,
21 pub bracket_r: &'static str,
23}
24
25impl KAndRBracket {
26 pub fn curly_braces() -> Self {
28 Self { head_space: true, bracket_l: "{", bracket_r: "}" }
29 }
30 pub fn build<'b, 'a, I, T: Text<'a>>(
32 &self,
33 items: &[I],
34 allocator: &'b PrettyProvider,
35 inline_join: PrettyTree<'a, T>,
36 block_join: PrettyTree<'a, T>,
37 ) -> PrettyTree<'a, T>
38 where
39 I: PrettyPrint<'a, T>,
40 {
41 let mut output = PrettySequence::new(5);
42 if self.head_space {
43 output.push(" ");
44 }
45 output.push(self.bracket_l);
46 let mut inline = PrettySequence::new(3);
48 inline.push(" ");
49 inline.push(allocator.join_slice(items, inline_join));
50 inline.push(" ");
51 let mut block = PrettySequence::new(3);
53 block.push(PrettyTree::Hardline);
54 block.push(allocator.join_slice(items, block_join).indent(4));
55 block.push(PrettyTree::Hardline);
56 output.push(block.flat_alt(inline));
58 output.push(self.bracket_r);
59 output.into()
60 }
61}