forked from extern/nix-config
Add theme preview support
This commit is contained in:
parent
9383aaf795
commit
bb7db5210d
15
src/theme.cr
15
src/theme.cr
@ -11,11 +11,16 @@ 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}!"
|
||||
if ARGV.size > 1
|
||||
Theme.preview(theme)
|
||||
else
|
||||
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}!"
|
||||
end
|
||||
|
||||
else
|
||||
Theme.test
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
require "colorize"
|
||||
require "./../trucolor"
|
||||
|
||||
# The theme helper handles changing the color scheme for various
|
||||
# programs. It relies on Base16 color schemes and is an easy way
|
||||
@ -69,6 +70,29 @@ module Theme
|
||||
#test_color :white, "color07 base05"
|
||||
end
|
||||
|
||||
# Previews a given theme.
|
||||
#
|
||||
# Unlike #test, #preview takes a given theme and prints
|
||||
# those colors to the terminal.
|
||||
def preview(theme : Hash(YAML::Type, YAML::Type))
|
||||
preview_color theme["base00"], "base00"
|
||||
preview_color theme["base01"], "base01"
|
||||
preview_color theme["base02"], "base02"
|
||||
preview_color theme["base03"], "base03"
|
||||
preview_color theme["base04"], "base04"
|
||||
preview_color theme["base05"], "base05"
|
||||
preview_color theme["base06"], "base06"
|
||||
preview_color theme["base07"], "base07"
|
||||
preview_color theme["base08"], "base08"
|
||||
preview_color theme["base09"], "base09"
|
||||
preview_color theme["base0A"], "base0A"
|
||||
preview_color theme["base0B"], "base0B"
|
||||
preview_color theme["base0C"], "base0C"
|
||||
preview_color theme["base0D"], "base0D"
|
||||
preview_color theme["base0E"], "base0E"
|
||||
preview_color theme["base0F"], "base0F"
|
||||
end
|
||||
|
||||
# Sets all the colors in zathura.
|
||||
#
|
||||
# This method will replace everything after the `[colors]`
|
||||
@ -304,6 +328,13 @@ module Theme
|
||||
print "\n"
|
||||
end
|
||||
|
||||
private def preview_color(color : YAML::Type, text : String)
|
||||
r : Int32 = color.to_s[0,2].to_i(16)
|
||||
g : Int32 = color.to_s[2,2].to_i(16)
|
||||
b : Int32 = color.to_s[4,2].to_i(16)
|
||||
print Trucolor.format({r, g, b}, "#{text} \x1b[48;2;#{r};#{g};#{b}m____________________________\x1b[0m\n")
|
||||
end
|
||||
|
||||
private def add_term(num : Int32, color : YAML::Type) : String
|
||||
return "color#{num.to_s.ljust(2, ' ')} = ##{color.to_s}\n"
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user