<commit_before>#include <stdio.h>
#include <ncurses.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>

#include "utils.h"
#include "smc.h"

#define MENU_WIDTH 30
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

WINDOW *menu_canvas;
WINDOW *info_canvas;
WINDOW *menu_window;

static int max_columns, max_rows;

static int selected_item = 1;
static int highlighted_item = 1;

WINDOW *create_window(int height, int width, int y, int x);
static const char *menu_items[] = {
  "Fan speed",
  "Cpu temp",
  "Battery info",
  "Exit"
};

static void draw_menu(WINDOW *window);
static void draw_borders(void);
static void process_menu_enter(void);

int main (int argv, char *argc[]) {
  open_smc();

  initscr();
  cbreak();
  noecho();

  curs_set(0);
  start_color();

  init_pair(1, COLOR_WHITE, COLOR_CYAN);    // highlighted
  init_pair(2, COLOR_MAGENTA, COLOR_BLACK); // selected
  init_pair(3, COLOR_MAGENTA, COLOR_CYAN);  // selected && highlighted

  getmaxyx(stdscr, max_rows, max_columns);

  menu_canvas = create_window(max_rows, MENU_WIDTH, 0, 0);
  info_canvas = create_window(max_rows, max_columns - MENU_WIDTH, 0, MENU_WIDTH);
  menu_window = create_window(ARRAY_LENGTH(menu_items), MENU_WIDTH - 2, 3, 1);

  keypad(menu_window, TRUE);

  draw_borders();
  draw_menu(menu_window);

  mvwaddstr(menu_canvas, 1, 8, "Select action");

  show_fan_info();

  wrefresh(menu_canvas);
  wrefresh(info_canvas);

  wrefresh(menu_window);

  while(1) {
    int key = wgetch(menu_window);

    switch(key) {
      case KEY_UP:
        if (highlighted_item > 1)
          highlighted_item--;
        break;

      case KEY_DOWN:
        if (highlighted_item < ARRAY_LENGTH(menu_items))
          highlighted_item++;
        break;

      case 10:
        selected_item = highlighted_item;
        process_menu_enter();
        break;
    }

    draw_menu(menu_window);
    wrefresh(menu_window);
  }

  endwin();
  return EXIT_SUCCESS;
}

WINDOW *create_window(int height, int width, int y, int x) {
  WINDOW *window = newwin(height, width, y, x);
  return window;
}

static void draw_menu(WINDOW *window) {
  for(size_t i = 0; i < ARRAY_LENGTH(menu_items); i++) {
    if (highlighted_item == i + 1) {
      wattron(window, COLOR_PAIR(1));
    }

    if (selected_item == i + 1) {
      wattron(window, A_BOLD | COLOR_PAIR(2));
    }

    if (selected_item == i + 1 && highlighted_item == i + 1) {
      wattron(window, COLOR_PAIR(3));
    }

    mvwaddch(window, i, 0, ' ');
    mvwaddstr(window, i, 1, menu_items[i]);

    int title_length = strlen(menu_items[i]);
    int width, height;
    getmaxyx(window, height, width);
    int span = width - title_length + 2;
<commit_msg>Add enum for menu color pairs<commit_after>#include <stdio.h>
#include <ncurses.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>

#include "utils.h"
#include "smc.h"

#define MENU_WIDTH 30
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

WINDOW *menu_canvas;
WINDOW *info_canvas;
WINDOW *menu_window;

static int max_columns, max_rows;

static int selected_item = 1;
static int highlighted_item = 1;

WINDOW *create_window(int height, int width, int y, int x);

enum EMenuColors {
  HIGHLIGHTED_MENU_C = 1,
  SELECTED_MENU_C = 2,
  SELECTED_AND_HIGHLIGHTED_MENU_C = 3
};

static const char *menu_items[] = {
  "Fan speed",
  "Cpu temp",
  "Battery info",
  "Exit"
};

static void draw_menu(WINDOW *window);
static void draw_borders(void);
static void process_menu_enter(void);

int main (int argv, char *argc[]) {
  open_smc();

  initscr();
  cbreak();
  noecho();

  curs_set(0);
  start_color();

  init_pair(HIGHLIGHTED_MENU_C, COLOR_WHITE, COLOR_CYAN);
  init_pair(SELECTED_MENU_C, COLOR_MAGENTA, COLOR_BLACK);
  init_pair(SELECTED_AND_HIGHLIGHTED_MENU_C, COLOR_MAGENTA, COLOR_CYAN);

  getmaxyx(stdscr, max_rows, max_columns);

  menu_canvas = create_window(max_rows, MENU_WIDTH, 0, 0);
  info_canvas = create_window(max_rows, max_columns - MENU_WIDTH, 0, MENU_WIDTH);
  menu_window = create_window(ARRAY_LENGTH(menu_items), MENU_WIDTH - 2, 3, 1);

  keypad(menu_window, TRUE);

  draw_borders();
  draw_menu(menu_window);

  mvwaddstr(menu_canvas, 1, 8, "Select action");

  show_fan_info();

  wrefresh(menu_canvas);
  wrefresh(info_canvas);

  wrefresh(menu_window);

  while(1) {
    int key = wgetch(menu_window);

    switch(key) {
      case KEY_UP:
        if (highlighted_item > 1)
          highlighted_item--;
        break;

      case KEY_DOWN:
        if (highlighted_item < ARRAY_LENGTH(menu_items))
          highlighted_item++;
        break;

      case 10:
        selected_item = highlighted_item;
        process_menu_enter();
        break;
    }

    draw_menu(menu_window);
    wrefresh(menu_window);
  }

  endwin();
  return EXIT_SUCCESS;
}

WINDOW *create_window(int height, int width, int y, int x) {
  WINDOW *window = newwin(height, width, y, x);
  return window;
}

static void draw_menu(WINDOW *window) {
  for(size_t i = 0; i < ARRAY_LENGTH(menu_items); i++) {
    if (highlighted_item == i + 1) {
      wattron(window, COLOR_PAIR(HIGHLIGHTED_MENU_C));
    }

    if (selected_item == i + 1) {
      wattron(window, A_BOLD | COLOR_PAIR(SELECTED_MENU_C));
    }

    if (selected_item == i + 1 && highlighted_item == i + 1) {
      wattron(window, COLOR_PAIR(SELECTED_AND_HIGHLIGHTED_MENU_C));
    }

    mvwaddch(window, i, 0, ' ');
    mvwaddstr(window, i, 1, menu_items[i]);

    int title_length = strlen(menu_items[i]);
    int width, height;
    getmaxyx(window, height, width);
    int span = width - title_length + 2;

{'fraction_non_alphanumeric': 0.12812777284826973, 'fraction_numerical': 0.01082519964507542, 'mean_word_length': 3.804774083546462, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5838304', 'n_tokens_mistral': 2238, 'n_tokens_neox': 2116, 'n_words': 467}