<commit_before>// Copyright (2015) Gustav

#include "ride/builtinthemes.h"

#include <string>

typedef google::protobuf::RepeatedPtrField<ride::Theme> ThemeList;

ride::Theme* GetOrCreateTheme(ThemeList* themes, const std::string& name) {
  for (ride::Theme& t : *themes) {
    if (t.name() == name) return &t;
  }

  ride::Theme* temp = themes->Add();
  temp->set_name(name);
  temp->set_can_remove(false);
  return temp;
}

ride::Color MakeColor(google::protobuf::int32 r, google::protobuf::int32 g,
                      google::protobuf::int32 b) {
  ride::Color c;

  c.set_r(r);
  c.set_g(g);
  c.set_b(b);

  return c;
}

ride::Color MakeColor(google::protobuf::int32 c) { return MakeColor(c, c, c); }

ride::Color* NewColor(google::protobuf::int32 r, google::protobuf::int32 g,
                      google::protobuf::int32 b) {
  return new ride::Color(MakeColor(r, g, b));
}

ride::Color* NewColor(google::protobuf::int32 c) { return NewColor(c, c, c); }

ride::Style* NewStyle(ride::Color* front, ride::Color* back = NULL,
                      bool bold = false) {
  ride::Style* style = new ride::Style();

  if (front) {
    style->set_use_foreground(true);
    style->set_allocated_foreground(front);
  }

  if (back) {
    style->set_use_background(true);
    style->set_allocated_background(back);
  }

  if (bold) {
    style->set_use_bold(true);
    style->set_bold(true);
  }

  return style;
}

template <typename T>
T* New(const T& t) {
  return new T(t);
}

ride::Indicator MakeIndicator(const ride::Color& c) {
  ride::Indicator ind;
  ind.set_allocated_foreground(New(c));
  return ind;
}

//////////////////////////////////////////////////////////////////////////

void SetupDefaultTemplate(ride::FontsAndColors* colors) {
  colors->set_use_selection_background(true);
  colors->set_use_selection_foreground(true);
  colors->set_allocated_selection_foreground(NewColor(255, 255, 255));
  colors->set_allocated_selection_background(NewColor(0, 0, 0));

  ride::Color bkg = MakeColor(224);

  colors->set_allocated_default_style(
      NewStyle(NewColor(0), new ride::Color(bkg)));
  colors->set_allocated_line_number_style(NewStyle(0, new ride::Color(bkg)));
  colors->set_allocated_fold_margin_hi(NewColor(192));
  colors->set_allocated_fold_margin_low(NewColor(224));

  colors->set_allocated_selected_line(NewColor(255, 255, 0));  // yellow

  ride::Color comment = MakeColor(128, 64, 0);
  colors->set_allocated_style_comment(NewStyle(new ride::Color(comment)));
  colors->set_allocated_style_commentline(NewStyle(new ride::Color(comment)));
  colors->set_allocated_style_commentdoc(NewStyle(new ride::Color(comment)));
  colors->set_allocated_style_commentlinedoc(
      NewStyle(new ride::Color(comment)));
  colors->set_allocated_style_keyword(
      NewStyle(NewColor(0, 0, 255), NULL, true));

  colors->set_allocated_folderend_background(new ride::Color(bkg));
  colors->set_allocated_folderopenmid_background(new ride::Color(bkg));
  colors->set_allocated_foldermidtail_background(new ride::Color(bkg));
  colors->set_allocated_foldertail_background(new ride::Color(bkg));
  colors->set_allocated_foldersub_background(new ride::Color(bkg));
  colors->set_allocated_folder_background(new ride::Color(bkg));
  colors->set_allocated_folderopen_background(new ride::Color(bkg));

  colors->set_allocated_props_key(NewStyle(NewColor(128, 128, 255)));
  colors->set_allocated_props_section(NewStyle(NULL, NULL, true));

  colors->set_allocated_indicator_error(
      New(MakeIndicator(MakeColor(255, 60, 60))));
  colors->set_allocated_indicator_warning(
      New(MakeIndicator(MakeColor(0, 255, 0))));
  colors->set_allocated_indicator_search_highlight(
      New(MakeIndicator(MakeColor(200))));
  colors->set_allocated_indicator_select_highlight(
      New(MakeIndicator(MakeColor(180))));
}

//////////////////////////////////////////////////////////////////////////

// solarized colors from http://ethanschoonover.com/solarized
const ride::Color solarized_base03 = MakeColor(0, 43, 54);
const ride::Color solarized_base02 = MakeColor(7, 54, 66);
const ride::Color solarized_base01 = MakeColor(88, 110, 117);
const ride::Color solarized_base00 = MakeColor(101, 123, 131);
const ride::Color solarized_base0 = MakeColor(131, 148, 150);
const ride::Color solarized_base1 = MakeColor(147, 161, 161);
const ride::Color solarized_base2 = MakeColor(238, 232, 213);
const ride::Color solarized_base3 = MakeColor(253, 246, 227);
const ride::Color solarized_yellow = MakeColor(181, 137, 0);
const ride::Color solarized_orange = MakeColor(203, 75, 22);
const ride::Color solarized_red = MakeColor(220, 50, 47);
const ride::Color solarized_magenta = MakeColor(211, 54, 130);
const ride::Color solarized_violet = MakeColor(108, 113, 196);
const ride::Color solarized_blue = MakeColor(38, 139, 210);
const ride::Color solarized_cyan = MakeColor(42, 161, 152);
const ride::Color solarized_green = MakeColor(133, 153, 0);

//////////////////////////////////////////////////////////////////////////

void AddBuiltInThemes(::ride::Settings* settings) {
  ThemeList* themes = settings->mutable_themes();

  ride::Theme* default_theme = GetOrCreateTheme(themes, "Ride (default)");
  SetupDefaultTemplate(default_theme->mutable_data());

  if (false == settings->has_fonts_and_colors()) {
    // if the current settings is missing the fonts and colors
    // apply the default theme
    settings->set_allocated_fonts_and_colors(<commit_msg>renamed stuff in theme code for #64<commit_after>// Copyright (2015) Gustav

#include "ride/builtinthemes.h"

#include <string>

typedef google::protobuf::RepeatedPtrField<ride::Theme> ThemeList;

ride::Theme* GetOrCreateTheme(ThemeList* themes, const std::string& name) {
  for (ride::Theme& t : *themes) {
    if (t.name() == name) return &t;
  }

  ride::Theme* temp = themes->Add();
  temp->set_name(name);
  temp->set_can_remove(false);
  return temp;
}

ride::Color Color(google::protobuf::int32 r, google::protobuf::int32 g,
                  google::protobuf::int32 b) {
  ride::Color c;

  c.set_r(r);
  c.set_g(g);
  c.set_b(b);

  return c;
}

ride::Color Color(google::protobuf::int32 c) { return Color(c, c, c); }

ride::Style Style(ride::Color* front, ride::Color* back = NULL,
                  bool bold = false) {
  ride::Style style;

  if (front) {
    style.set_use_foreground(true);
    style.set_allocated_foreground(front);
  }

  if (back) {
    style.set_use_background(true);
    style.set_allocated_background(back);
  }

  if (bold) {
    style.set_use_bold(true);
    style.set_bold(true);
  }

  return style;
}

template <typename T>
T* New(const T& t) {
  return new T(t);
}

ride::Indicator Indicator(const ride::Color& c) {
  ride::Indicator ind;
  ind.set_allocated_foreground(New(c));
  return ind;
}

//////////////////////////////////////////////////////////////////////////

void SetupDefaultTemplate(ride::FontsAndColors* colors) {
  colors->set_use_selection_background(true);
  colors->set_use_selection_foreground(true);
  colors->set_allocated_selection_foreground(New(Color(255, 255, 255)));
  colors->set_allocated_selection_background(New(Color(0, 0, 0)));

  ride::Color bkg = Color(224);

  colors->set_allocated_default_style(New(Style(New(Color(0)), New(bkg))));
  colors->set_allocated_line_number_style(New(Style(NULL, New(bkg))));
  colors->set_allocated_fold_margin_hi(New(Color(192)));
  colors->set_allocated_fold_margin_low(New(Color(224)));

  colors->set_allocated_selected_line(New(Color(255, 255, 0)));  // yellow

  ride::Color comment = Color(128, 64, 0);
  colors->set_allocated_style_comment(New(Style(New(comment))));
  colors->set_allocated_style_commentline(New(Style(New(comment))));
  colors->set_allocated_style_commentdoc(New(Style(New(comment))));
  colors->set_allocated_style_commentlinedoc(New(Style(New(comment))));
  colors->set_allocated_style_keyword(
      New(Style(New(Color(0, 0, 255)), NULL, true)));

  colors->set_allocated_folderend_background(New(bkg));
  colors->set_allocated_folderopenmid_background(New(bkg));
  colors->set_allocated_foldermidtail_background(New(bkg));
  colors->set_allocated_foldertail_background(New(bkg));
  colors->set_allocated_foldersub_background(New(bkg));
  colors->set_allocated_folder_background(New(bkg));
  colors->set_allocated_folderopen_background(New(bkg));

  colors->set_allocated_props_key(New(Style(New(Color(128, 128, 255)))));
  colors->set_allocated_props_section(New(Style(NULL, NULL, true)));

  colors->set_allocated_indicator_error(New(Indicator(Color(255, 60, 60))));
  colors->set_allocated_indicator_warning(New(Indicator(Color(0, 255, 0))));
  colors->set_allocated_indicator_search_highlight(New(Indicator(Color(200))));
  colors->set_allocated_indicator_select_highlight(New(Indicator(Color(180))));
}

//////////////////////////////////////////////////////////////////////////

// solarized colors from http://ethanschoonover.com/solarized
const ride::Color solarized_base03 = Color(0, 43, 54);
const ride::Color solarized_base02 = Color(7, 54, 66);
const ride::Color solarized_base01 = Color(88, 110, 117);
const ride::Color solarized_base00 = Color(101, 123, 131);
const ride::Color solarized_base0 = Color(131, 148, 150);
const ride::Color solarized_base1 = Color(147, 161, 161);
const ride::Color solarized_base2 = Color(238, 232, 213);
const ride::Color solarized_base3 = Color(253, 246, 227);
const ride::Color solarized_yellow = Color(181, 137, 0);
const ride::Color solarized_orange = Color(203, 75, 22);
const ride::Color solarized_red = Color(220, 50, 47);
const ride::Color solarized_magenta = Color(211, 54, 130);
const ride::Color solarized_violet = Color(108, 113, 196);
const ride::Color solarized_blue = Color(38, 139, 210);
const ride::Color solarized_cyan = Color(42, 161, 152);
const ride::Color solarized_green = Color(133, 153, 0);

//////////////////////////////////////////////////////////////////////////

void AddBuiltInThemes(::ride::Settings* settings) {
  ThemeList* themes = settings->mutable_themes();

  ride::Theme* default_theme = GetOrCreateTheme(themes, "Ride (default)");
  SetupDefaultTemplate(default_theme->mutable_data());

  if (false == settings->has_fonts_and_colors()) {
    // if the current settings is missing the fonts and colors
    // apply the default theme
    settings->set_allocated_fonts_and_colors(
{'fraction_non_alphanumeric': 0.18153727307840864, 'fraction_numerical': 0.04258400926998841, 'mean_word_length': 4.665754923413567, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 83, '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': '6921052', 'n_tokens_mistral': 3741, 'n_tokens_neox': 3350, 'n_words': 621}