aboutsummaryrefslogtreecommitdiff
path: root/analyzer/render.h
diff options
context:
space:
mode:
Diffstat (limited to 'analyzer/render.h')
-rw-r--r--analyzer/render.h53
1 files changed, 23 insertions, 30 deletions
diff --git a/analyzer/render.h b/analyzer/render.h
index 1015eb9..3604bde 100644
--- a/analyzer/render.h
+++ b/analyzer/render.h
@@ -2,6 +2,7 @@
// functions for "rendering" data onto the terminal
#include "parser/fight_results/fight_results.h"
+#include "utils/memory.h"
// ANSI escape sequence colors
#define COLOR_GOLD 33
@@ -23,40 +24,32 @@
#define TABLE_LINE_END_WIDTH (sizeof(TABLE_LINE_END) - 1)
#define TABLE_LINE_SEPARATOR_WIDTH (sizeof(TABLE_LINE_SEPARATOR) - 1)
-#define TABLE_COLUMN_COUNT 6
-
-#define TABLE_NAME_LVL_WIDTH 17
-#define TABLE_EXP_WIDTH 7
-#define TABLE_GOLD_WIDTH 7
-#define TABLE_PSYCHO_WIDTH 6
-#define TABLE_SATURATION_WIDTH 13
-#define TABLE_SPLINTERS_WIDTH 9
+// column info
+typedef struct {
+ char *name;
+ size_t width;
+ int color;
+} ColumnInfo;
+static const ColumnInfo columns[] = {
+ {"Nick (LVL)", 17, COLOR_WHITE},
+ {"EXP", 7, COLOR_WHITE},
+ {"Gold", 7, COLOR_YELLOW},
+ {"Psycho", 6, COLOR_AQUA},
+ {"Saturation", 13, COLOR_GREEN},
+ {"Splinters", 9, COLOR_BLUE},
+};
// clang-format off
-#define TABLE_COLUMN_NAMES {"Nick (LVL)", "EXP", "Gold", "Psycho", "Saturation", "Splinters"}
-#define TABLE_COLUMN_COLORS {COLOR_WHITE, COLOR_WHITE, COLOR_YELLOW, COLOR_AQUA, COLOR_GREEN, COLOR_BLUE}
-#define TABLE_COLUMN_WIDTHS { \
- TABLE_NAME_LVL_WIDTH, \
- TABLE_EXP_WIDTH, \
- TABLE_GOLD_WIDTH, \
- TABLE_PSYCHO_WIDTH, \
- TABLE_SATURATION_WIDTH, \
- TABLE_SPLINTERS_WIDTH, \
-}
-
-#define TABLE_LINE_WIDTH ( \
- TABLE_LINE_START_WIDTH + \
- TABLE_NAME_LVL_WIDTH + \
- TABLE_EXP_WIDTH + \
- TABLE_GOLD_WIDTH + \
- TABLE_PSYCHO_WIDTH + \
- TABLE_SATURATION_WIDTH + \
- TABLE_SPLINTERS_WIDTH + \
- (TABLE_COLUMN_COUNT - 1) * TABLE_LINE_SEPARATOR_WIDTH + \
- TABLE_LINE_END_WIDTH \
-)
+#define SUM_COL_WIDTHS ({ \
+ size_t sum = 0; \
+ for (size_t i = 0; i < ARR_LEN(columns); i++) \
+ sum += columns[i].width; \
+ sum; \
+})
// clang-format on
+#define TABLE_LINE_WIDTH (TABLE_LINE_START_WIDTH + SUM_COL_WIDTHS + (ARR_LEN(columns) - 1) * TABLE_LINE_SEPARATOR_WIDTH + TABLE_LINE_END_WIDTH)
+
#define TABLE_ITEMS_WIDTH (TABLE_LINE_WIDTH - TABLE_LINE_START_WIDTH - TABLE_LINE_END_WIDTH)
// render fight results onto the terminal