From a92dec271a9d3ac8eda2462bef57a1f578c57b48 Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Thu, 28 Dec 2017 16:54:37 -0500 Subject: [PATCH] Add zathura theme support --- src/theme.cr | 1 + src/theme_helper/theme_helper.cr | 65 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/src/theme.cr b/src/theme.cr index 41f89b76..2ef8ee20 100644 --- a/src/theme.cr +++ b/src/theme.cr @@ -12,6 +12,7 @@ if ARGV.size > 0 theme : Hash(YAML::Type, YAML::Type) = YAML.parse(File.read file).as_h Theme.set_terminal(theme) + Theme.set_zathura(theme) Theme.set_xresources(theme) system("i3 restart >/dev/null 2>&1") puts "Successfully changed the theme to #{theme["scheme"].to_s}!" diff --git a/src/theme_helper/theme_helper.cr b/src/theme_helper/theme_helper.cr index 7ca0f3fa..00e52499 100644 --- a/src/theme_helper/theme_helper.cr +++ b/src/theme_helper/theme_helper.cr @@ -1,5 +1,29 @@ require "colorize" +# The theme helper handles changing the color scheme for various +# programs. It relies on Base16 color schemes and is an easy way +# to change color schemes for all the software you use all at once +# with a single command. +# +# Note that software such as vim use the colors directly from the +# terminal and therefore do not need an explicit change in a config +# file. Other software, however, have the different colors hard-coded +# into the config file. +# +# This software would not exist without the help from a variety of +# people that have contributed to the "Base16 movement". Theme creators +# made optimal color schemes and other contributors decided on which +# colors to use for different software. It is because of their open +# contributions that I am able to make this program the way it is. +# +# To learn more, here is the complete list of the Base16 repositories +# I used in the development of this software: +# +# https://github.com/chriskempson/base16 +# https://github.com/chriskempson/base16-vim +# https://github.com/chriskempson/base16-shell +# https://github.com/chriskempson/base16-xresources +# https://github.com/nicodebo/base16-zathura module Theme extend self @@ -45,6 +69,43 @@ module Theme #test_color :white, "color07 base05" end + # Sets all the colors in zathura. + # + # This method will replace everything after the `[colors]` + # line with the theme colors. You can then open a new + # zathura window to see the changes instantly. + def set_zathura(theme : Hash(YAML::Type, YAML::Type)) + file : String = ENV["HOME"] + "/.config/zathura/zathurarc" + _DNE(file) if !File.exists?(file) + config : String = "" + File.each_line(file) do |line| + config += line + "\n" + break if line.includes?("[colors]") + end + config += add_zcolor "default-bg", theme["base00"] + config += add_zcolor "default-fg", theme["base01"] + config += add_zcolor "statusbar-bg", theme["base02"] + config += add_zcolor "statusbar-fg", theme["base04"] + config += add_zcolor "inputbar-bg", theme["base00"] + config += add_zcolor "inputbar-fg", theme["base07"] + config += add_zcolor "notification-bg", theme["base00"] + config += add_zcolor "notification-fg", theme["base07"] + config += add_zcolor "notification-error-bg", theme["base00"] + config += add_zcolor "notification-error-fg", theme["base08"] + config += add_zcolor "notification-warning-bg", theme["base00"] + config += add_zcolor "notification-warning-fg", theme["base08"] + config += add_zcolor "highlight-color", theme["base0A"] + config += add_zcolor "highlight-active-color", theme["base0D"] + config += add_zcolor "completion-bg", theme["base01"] + config += add_zcolor "completion-fg", theme["base0D"] + config += add_zcolor "completion-highlight-bg", theme["base0D"] + config += add_zcolor "completion-highlight-fg", theme["base07"] + config += add_zcolor "recolor-lightcolor", theme["base00"] + config += add_zcolor "recolor-darkcolor", theme["base06"] + config += "\n# vim:ft=conf\n" + File.write(file, config) + end + # Sets all the colors in .Xresources, then reloads xrdb. # # This method will replace everything after the `[colors]` @@ -259,6 +320,10 @@ module Theme return "*#{type}: ##{color.to_s}\n" end + private def add_zcolor(type : String, color : YAML::Type) : String + return "set #{type.ljust(30)} \"##{color.to_s}\"\n" + end + # Prints an error that the file does not exists. def _DNE(file : String) _e("The file " + File.expand_path(file) + " does not exist!")