Skip to content

Instantly share code, notes, and snippets.

@hholst80
Created October 21, 2025 21:37
Show Gist options
  • Save hholst80/da7e88e26dd4a7f7ec8c4cfea62c4985 to your computer and use it in GitHub Desktop.
Save hholst80/da7e88e26dd4a7f7ec8c4cfea62c4985 to your computer and use it in GitHub Desktop.
diff --git a/color.c b/color.c
index 42c684c..a88b829 100644
--- a/color.c
+++ b/color.c
@@ -12,31 +12,140 @@
static BOOL color_enabled = FALSE;
+#define NORD_COLOR_COUNT 16
+
+enum {
+ NORD0 = 0,
+ NORD1,
+ NORD2,
+ NORD3,
+ NORD4,
+ NORD5,
+ NORD6,
+ NORD7,
+ NORD8,
+ NORD9,
+ NORD10,
+ NORD11,
+ NORD12,
+ NORD13,
+ NORD14,
+ NORD15
+};
+
+typedef struct {
+ short red;
+ short green;
+ short blue;
+} NordColor;
+
+static const NordColor nord_palette[NORD_COLOR_COUNT] = {
+ { 180, 204, 251 }, /* nord0 #2E3440 */
+ { 231, 259, 322 }, /* nord1 #3B4252 */
+ { 263, 298, 369 }, /* nord2 #434C5E */
+ { 298, 337, 416 }, /* nord3 #4C566A */
+ { 847, 871, 914 }, /* nord4 #D8DEE9 */
+ { 898, 914, 941 }, /* nord5 #E5E9F0 */
+ { 925, 937, 957 }, /* nord6 #ECEFF4 */
+ { 561, 737, 733 }, /* nord7 #8FBCBB */
+ { 533, 753, 816 }, /* nord8 #88C0D0 */
+ { 506, 631, 757 }, /* nord9 #81A1C1 */
+ { 369, 506, 675 }, /* nord10 #5E81AC */
+ { 749, 380, 416 }, /* nord11 #BF616A */
+ { 816, 529, 439 }, /* nord12 #D08770 */
+ { 922, 796, 545 }, /* nord13 #EBCB8B */
+ { 639, 745, 549 }, /* nord14 #A3BE8C */
+ { 706, 557, 678 } /* nord15 #B48EAD */
+};
+
+static const short nord_fallback[NORD_COLOR_COUNT] = {
+ COLOR_BLACK, /* nord0 */
+ COLOR_BLUE, /* nord1 */
+ COLOR_BLUE, /* nord2 */
+ COLOR_BLUE, /* nord3 */
+ COLOR_WHITE, /* nord4 */
+ COLOR_WHITE, /* nord5 */
+ COLOR_WHITE, /* nord6 */
+ COLOR_CYAN, /* nord7 */
+ COLOR_CYAN, /* nord8 */
+ COLOR_BLUE, /* nord9 */
+ COLOR_BLUE, /* nord10 */
+ COLOR_RED, /* nord11 */
+ COLOR_YELLOW, /* nord12 */
+ COLOR_YELLOW, /* nord13 */
+ COLOR_GREEN, /* nord14 */
+ COLOR_MAGENTA /* nord15 */
+};
+
+static BOOL SetupNordPalette(short color_ids[])
+{
+ BOOL use_truecolor;
+ int i;
+
+ use_truecolor = FALSE;
+
+ if (COLORS >= NORD_COLOR_COUNT) {
+ use_truecolor = TRUE;
+
+ for (i = 0; i < NORD_COLOR_COUNT; i++) {
+ short color_index;
+
+ color_index = (short) i;
+ if (color_index >= COLORS) {
+ use_truecolor = FALSE;
+ break;
+ }
+ if (init_color(color_index,
+ nord_palette[i].red,
+ nord_palette[i].green,
+ nord_palette[i].blue) == ERR) {
+ use_truecolor = FALSE;
+ break;
+ }
+ color_ids[i] = color_index;
+ }
+ }
+
+ if (!use_truecolor) {
+ for (i = 0; i < NORD_COLOR_COUNT; i++) {
+ color_ids[i] = nord_fallback[i];
+ }
+ }
+
+ return use_truecolor;
+}
+
void StartColors()
{
start_color();
- if ((COLORS < 8) || (COLOR_PAIRS < 17)) {
+ if ((COLORS < 8) || (COLOR_PAIRS <= HIGLOBAL_COLOR)) {
ESCAPE; /* no color support */
}
- init_pair(DIR_COLOR, COLOR_WHITE, COLOR_BLUE);
- init_pair(HIDIR_COLOR, COLOR_BLACK, COLOR_WHITE);
- init_pair(WINDIR_COLOR, COLOR_CYAN, COLOR_BLUE);
- init_pair(FILE_COLOR, COLOR_WHITE, COLOR_BLUE);
- init_pair(HIFILE_COLOR, COLOR_BLACK, COLOR_WHITE);
- init_pair(WINFILE_COLOR, COLOR_CYAN, COLOR_BLUE);
- init_pair(STATS_COLOR, COLOR_BLUE, COLOR_CYAN);
- init_pair(WINSTATS_COLOR,COLOR_BLUE, COLOR_CYAN);
- init_pair(BORDERS_COLOR, COLOR_BLUE, COLOR_CYAN);
- init_pair(HIMENUS_COLOR, COLOR_WHITE, COLOR_BLUE);
- init_pair(MENU_COLOR, COLOR_CYAN, COLOR_BLUE);
- init_pair(WINERR_COLOR, COLOR_BLUE, COLOR_WHITE);
- init_pair(HST_COLOR, COLOR_YELLOW, COLOR_CYAN);
- init_pair(HIHST_COLOR, COLOR_WHITE, COLOR_WHITE);
- init_pair(WINHST_COLOR, COLOR_YELLOW, COLOR_CYAN);
- init_pair(HIGLOBAL_COLOR,COLOR_BLUE, COLOR_WHITE);
- init_pair(GLOBAL_COLOR, COLOR_YELLOW, COLOR_CYAN);
+ {
+ short nord_ids[NORD_COLOR_COUNT];
+
+ (void) SetupNordPalette(nord_ids);
+
+ init_pair(DIR_COLOR, nord_ids[NORD6], nord_ids[NORD0]);
+ init_pair(HIDIR_COLOR, nord_ids[NORD0], nord_ids[NORD8]);
+ init_pair(WINDIR_COLOR, nord_ids[NORD4], nord_ids[NORD0]);
+ init_pair(FILE_COLOR, nord_ids[NORD6], nord_ids[NORD0]);
+ init_pair(HIFILE_COLOR, nord_ids[NORD0], nord_ids[NORD8]);
+ init_pair(WINFILE_COLOR, nord_ids[NORD4], nord_ids[NORD0]);
+ init_pair(STATS_COLOR, nord_ids[NORD8], nord_ids[NORD1]);
+ init_pair(WINSTATS_COLOR,nord_ids[NORD8], nord_ids[NORD1]);
+ init_pair(BORDERS_COLOR, nord_ids[NORD3], nord_ids[NORD0]);
+ init_pair(HIMENUS_COLOR, nord_ids[NORD0], nord_ids[NORD9]);
+ init_pair(MENU_COLOR, nord_ids[NORD6], nord_ids[NORD2]);
+ init_pair(WINERR_COLOR, nord_ids[NORD11], nord_ids[NORD1]);
+ init_pair(HST_COLOR, nord_ids[NORD6], nord_ids[NORD0]);
+ init_pair(HIHST_COLOR, nord_ids[NORD0], nord_ids[NORD8]);
+ init_pair(WINHST_COLOR, nord_ids[NORD4], nord_ids[NORD0]);
+ init_pair(HIGLOBAL_COLOR,nord_ids[NORD0], nord_ids[NORD7]);
+ init_pair(GLOBAL_COLOR, nord_ids[NORD7], nord_ids[NORD2]);
+ }
color_enabled = TRUE;
FNC_XIT: ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment