format_tools/format/output_format/
keys.rs

1//! Implement keys list output format.
2//!
3//! # Example
4//!
5//! ```text
6//! ```
7//!
8
9use crate::*;
10use print::
11{
12  InputExtract,
13  Context,
14};
15use core::
16{
17  fmt,
18};
19use std::sync::OnceLock;
20
21/// A struct representing the list of keys output format.
22#[ derive( Debug ) ]
23pub struct Keys
24{
25  // /// Prefix added to each row.
26  // pub table_prefix : String,
27  // /// Postfix added to each row.
28  // pub table_postfix : String,
29  // /// Separator used between rows.
30  // pub table_separator : String,
31  // /// Prefix added to each row.
32  // pub row_prefix : String,
33  // /// Postfix added to each row.
34  // pub row_postfix : String,
35  // /// Separator used between rows.
36  // pub row_separator : String,
37  // /// Prefix added to each cell.
38  // pub cell_prefix : String,
39  // /// Postfix added to each cell.
40  // pub cell_postfix : String,
41  // /// Separator used between table columns.
42  // pub cell_separator : String,
43}
44
45impl Keys
46{
47  /// Returns a reference to a static instance of `Keys`.
48  pub fn instance() -> &'static dyn TableOutputFormat
49  {
50    static INSTANCE : OnceLock< Keys > = OnceLock::new();
51    INSTANCE.get_or_init( || Keys::default() )
52  }
53}
54
55impl Default for Keys
56{
57  fn default() -> Self
58  {
59
60    // let cell_prefix = "".to_string();
61    // let cell_postfix = "".to_string();
62    // let cell_separator = " │ ".to_string();
63    // let row_prefix = "│ ".to_string();
64    // let row_postfix = " │".to_string();
65    // let row_separator = "\n".to_string();
66    // let table_prefix = "".to_string();
67    // let table_postfix = "".to_string();
68    // let table_separator = "\n".to_string();
69
70    Self
71    {
72      // table_prefix,
73      // table_postfix,
74      // table_separator,
75      // row_prefix,
76      // row_postfix,
77      // row_separator,
78      // cell_prefix,
79      // cell_postfix,
80      // cell_separator,
81    }
82  }
83}
84
85impl TableOutputFormat for Keys
86{
87
88  fn extract_write< 'buf, 'data >(
89    &self,
90    x : &InputExtract< 'data >,
91    c : &mut Context< 'buf >,
92  ) -> fmt::Result
93  {
94
95    // dbg!( &x );
96
97    for col in &x.col_descriptors
98    {
99      write!( c.buf, " - {}\n", col.label )?;
100    }
101
102    write!( c.buf, "  {} fields\n", x.col_descriptors.len() )?;
103
104    Ok(())
105  }
106
107}