blob: c8d51c845b001282a83ae466ae7b83a9629a65d3 [file] [log] [blame]
Christian Göttsche9060a412020-12-25 16:42:35 +01001#ifndef HEADER_HeaderLayout
2#define HEADER_HeaderLayout
3/*
4htop - HeaderLayout.h
5(C) 2021 htop dev team
Daniel Lange94ad1112021-09-22 11:33:00 +02006Released under the GNU GPLv2+, see the COPYING file
Christian Göttsche9060a412020-12-25 16:42:35 +01007in the source distribution for its full text.
8*/
9
10#include <assert.h>
11#include <stddef.h>
12#include <stdint.h>
13
14#include "Macros.h"
Christian Göttschedb076b92021-08-24 17:40:22 +020015#include "XUtils.h"
Christian Göttsche9060a412020-12-25 16:42:35 +010016
17
18typedef enum HeaderLayout_ {
hwangcc2372c56692022-04-04 23:29:48 +080019 HF_INVALID = -1,
Peter Dey13ca4e22024-04-16 20:59:25 +020020 HF_ONE_100,
Christian Göttsche9060a412020-12-25 16:42:35 +010021 HF_TWO_50_50,
22 HF_TWO_33_67,
23 HF_TWO_67_33,
24 HF_THREE_33_34_33,
25 HF_THREE_25_25_50,
26 HF_THREE_25_50_25,
27 HF_THREE_50_25_25,
Christian Hesse8980d7a2023-12-22 07:51:28 +010028 HF_THREE_40_30_30,
29 HF_THREE_30_40_30,
30 HF_THREE_30_30_40,
Christian Göttsche9060a412020-12-25 16:42:35 +010031 HF_THREE_40_20_40,
32 HF_FOUR_25_25_25_25,
33 LAST_HEADER_LAYOUT
34} HeaderLayout;
35
36static const struct {
37 uint8_t columns;
38 const uint8_t widths[4];
Christian Göttschedb076b92021-08-24 17:40:22 +020039 const char* name;
Christian Göttsche9060a412020-12-25 16:42:35 +010040 const char* description;
41} HeaderLayout_layouts[LAST_HEADER_LAYOUT] = {
Peter Dey13ca4e22024-04-16 20:59:25 +020042 [HF_ONE_100] = { 1, { 100, 0, 0, 0 }, "one_100", "1 column - full width", },
Christian Göttschedb076b92021-08-24 17:40:22 +020043 [HF_TWO_50_50] = { 2, { 50, 50, 0, 0 }, "two_50_50", "2 columns - 50/50 (default)", },
44 [HF_TWO_33_67] = { 2, { 33, 67, 0, 0 }, "two_33_67", "2 columns - 33/67", },
45 [HF_TWO_67_33] = { 2, { 67, 33, 0, 0 }, "two_67_33", "2 columns - 67/33", },
46 [HF_THREE_33_34_33] = { 3, { 33, 34, 33, 0 }, "three_33_34_33", "3 columns - 33/34/33", },
47 [HF_THREE_25_25_50] = { 3, { 25, 25, 50, 0 }, "three_25_25_50", "3 columns - 25/25/50", },
48 [HF_THREE_25_50_25] = { 3, { 25, 50, 25, 0 }, "three_25_50_25", "3 columns - 25/50/25", },
49 [HF_THREE_50_25_25] = { 3, { 50, 25, 25, 0 }, "three_50_25_25", "3 columns - 50/25/25", },
Christian Hesse8980d7a2023-12-22 07:51:28 +010050 [HF_THREE_40_30_30] = { 3, { 40, 30, 30, 0 }, "three_40_30_30", "3 columns - 40/30/30", },
51 [HF_THREE_30_40_30] = { 3, { 30, 40, 30, 0 }, "three_30_40_30", "3 columns - 30/40/30", },
52 [HF_THREE_30_30_40] = { 3, { 30, 30, 40, 0 }, "three_30_30_40", "3 columns - 30/30/40", },
Christian Göttschedb076b92021-08-24 17:40:22 +020053 [HF_THREE_40_20_40] = { 3, { 40, 20, 40, 0 }, "three_40_20_40", "3 columns - 40/20/40", },
54 [HF_FOUR_25_25_25_25] = { 4, { 25, 25, 25, 25 }, "four_25_25_25_25", "4 columns - 25/25/25/25", },
Christian Göttsche9060a412020-12-25 16:42:35 +010055};
56
57static inline size_t HeaderLayout_getColumns(HeaderLayout hLayout) {
58 /* assert the layout is initialized */
59 assert(0 <= hLayout);
60 assert(hLayout < LAST_HEADER_LAYOUT);
Christian Göttschedb076b92021-08-24 17:40:22 +020061 assert(HeaderLayout_layouts[hLayout].name[0]);
Christian Göttsche9060a412020-12-25 16:42:35 +010062 assert(HeaderLayout_layouts[hLayout].description[0]);
63 return HeaderLayout_layouts[hLayout].columns;
64}
65
Christian Göttschedb076b92021-08-24 17:40:22 +020066static inline const char* HeaderLayout_getName(HeaderLayout hLayout) {
67 /* assert the layout is initialized */
68 assert(0 <= hLayout);
69 assert(hLayout < LAST_HEADER_LAYOUT);
70 assert(HeaderLayout_layouts[hLayout].name[0]);
71 assert(HeaderLayout_layouts[hLayout].description[0]);
72 return HeaderLayout_layouts[hLayout].name;
73}
74
75static inline HeaderLayout HeaderLayout_fromName(const char* name) {
76 for (size_t i = 0; i < LAST_HEADER_LAYOUT; i++) {
77 if (String_eq(HeaderLayout_layouts[i].name, name))
78 return (HeaderLayout) i;
79 }
80
81 return LAST_HEADER_LAYOUT;
82}
83
Christian Göttsche9060a412020-12-25 16:42:35 +010084#endif /* HEADER_HeaderLayout */