1 ////////////////////////////////////////////////////////////////////////////////
3 // Copyright 2006 - 2017, Paul Beckingham, Federico Hernandez.
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included
13 // in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // http://www.opensource.org/licenses/mit-license.php
25 ////////////////////////////////////////////////////////////////////////////////
27 #ifndef INCLUDED_TABLE
28 #define INCLUDED_TABLE
37 // View specifications.
38 void add (const std::string& col, bool alignLeft = true, bool wrap = true);
39 void width (int width) { _width = width; }
40 void leftMargin (int margin) { _left_margin = margin; }
41 void colorHeader (const Color& c) { _header = c; }
42 void colorOdd (const Color& c) { _odd = c; }
43 void colorEven (const Color& c) { _even = c; }
44 void intraPadding (int padding) { _intra_padding = padding; }
45 void intraColorOdd (const Color& c) { _intra_odd = c; }
46 void intraColorEven (const Color& c) { _intra_even = c; }
47 void extraPadding (int padding) { _extra_padding = padding; }
48 void extraColorOdd (const Color& c) { _extra_odd = c; }
49 void extraColorEven (const Color& c) { _extra_even = c; }
50 void truncateLines (int n) { _truncate_lines = n; }
51 void truncateRows (int n) { _truncate_rows = n; }
52 void forceColor () { _forceColor = true; }
53 void obfuscate () { _obfuscate = true; }
54 void underlineHeaders () { _underline_headers = true; }
55 int lines () { return _lines; }
56 int rows () { return (int) _data.size (); }
62 void set (int, int, const std::string&, const Color color = Color::nocolor);
63 void set (int, int, int, const Color color = Color::nocolor);
64 void set (int, int, const Color);
67 std::string render ();
70 void measureCell (const std::string&, unsigned int&, unsigned int&) const;
71 void renderCell (std::vector <std::string>&, const std::string&, int, bool, bool, const Color&) const;
74 std::vector <std::vector <std::string>> _data;
75 std::vector <std::vector <Color>> _color;
76 std::vector <std::string> _columns;
77 std::vector <bool> _align;
78 std::vector <bool> _wrap;
79 std::vector <bool> _oddness;
85 int _intra_padding {1};
87 Color _intra_even {0};
88 int _extra_padding {0};
90 Color _extra_even {0};
91 int _truncate_lines {0};
92 int _truncate_rows {0};
93 bool _forceColor {false};
94 bool _obfuscate {false};
95 bool _underline_headers {false};