aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/format_table.h
blob: 4f4a7724b0ec47ee520d4f4d3d0517dc8657ca7c (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
/*
  Copyright (c) 2020 Damjan Marion

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef __format_table_h__
#define __format_table_h__

typedef enum
{
  TTAF_RESET = (1 << 0),
  TTAF_BOLD = (1 << 1),
  TTAF_DIM = (1 << 2),
  TTAF_UNDERLINE = (1 << 3),
  TTAF_FG_COLOR_SET = (1 << 4),
  TTAF_BG_COLOR_SET = (1 << 5),
  TTAF_FG_COLOR_BRIGHT = (1 << 6),
  TTAF_BG_COLOR_BRIGHT = (1 << 7),
} table_text_attr_flags_t;

typedef enum
{
  TTAC_BLACK = 0,
  TTAC_RED = 1,
  TTAC_GREEN = 2,
  TTAC_YELLOW = 3,
  TTAC_BLUE = 4,
  TTAC_MAGENTA = 5,
  TTAC_CYAN = 6,
  TTAC_WHITE = 7,
  TTAC_BRIGHT_BLACK = 8,
  TTAC_BRIGHT_RED = 9,
  TTAC_BRIGHT_GREEN = 10,
  TTAC_BRIGHT_YELLOW = 11,
  TTAC_BRIGHT_BLUE = 12,
  TTAC_BRIGHT_MAGENTA = 13,
  TTAC_BRIGHT_CYAN = 14,
  TTAC_BRIGHT_WHITE = 15,
} table_text_attr_color_t;

typedef enum
{
  TTAA_DEFAULT = 0,
  TTAA_LEFT = 1,
  TTAA_RIGHT = 2,
  TTAA_CENTER = 3,
} table_text_attr_align_t;

typedef struct
{
  union
  {
    struct
    {
      table_text_attr_flags_t flags : 16;
      table_text_attr_color_t fg_color : 4;
      table_text_attr_color_t bg_color : 4;
      table_text_attr_align_t align : 4;
    };
    u32 as_u32;
  };
} table_text_attr_t;

typedef struct
{
  table_text_attr_t attr;
  u8 *text;
} table_cell_t;

typedef struct
{
  u8 no_ansi : 1;
  u8 *title;
  table_cell_t **cells;
  int *row_sizes;
  int n_header_cols;
  int n_header_rows;
  int n_footer_cols;
  table_text_attr_t default_title;
  table_text_attr_t default_body;
  table_text_attr_t default_header_col;
  table_text_attr_t default_header_row;
} table_t;

__clib_export format_function_t format_table;

__clib_export void table_format_title (table_t *t, char *fmt, ...);
__clib_export void table_format_cell (table_t *t, int c, int r, char *fmt,
				      ...);
__clib_export void table_set_cell_align (table_t *t, int c, int r,
					 table_text_attr_align_t a);
__clib_export void table_set_cell_fg_color (table_t *t, int c, int r,
					    table_text_attr_color_t v);
__clib_export void table_set_cell_bg_color (table_t *t, int c, int r,
					    table_text_attr_color_t v);
__clib_export void table_free (table_t *t);
__clib_export void table_add_header_col (table_t *t, int n_strings, ...);
__clib_export void table_add_header_row (table_t *t, int n_strings, ...);

#endif