colorist

Few scripts for color scheme managment
git clone git://git.konyahin.xyz/colorist
Log | Files | Refs

commit 902c5eb5fa6d9b221012927e19e678b70ee6c66a
Author: Anton Konyahin <me@konyahin.xyz>
Date:   Tue, 17 May 2022 20:38:15 +0300

Initial commit

Diffstat:
Acolorist.tcl | 197+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ainstall.sh | 27+++++++++++++++++++++++++++
Aschemes/kasugano | 19+++++++++++++++++++
Aschemes/s3r0-modified | 19+++++++++++++++++++
Aschemes/visiblue | 19+++++++++++++++++++
5 files changed, 281 insertions(+), 0 deletions(-)

diff --git a/colorist.tcl b/colorist.tcl @@ -0,0 +1,197 @@ +#!/usr/bin/env tclsh + +proc array'reverse {oldName newName} { + upvar 1 $oldName old $newName new + foreach {key value} [array get old] {set new($value) $key} +} + +# Xresources +array set from_xresources { + *.foreground: foreground + *.background: background + *.cursorColor: cursor + *.color0: black + *.color8: black_bright + *.color1: red + *.color9: red_bright + *.color2: green + *.color10: green_bright + *.color3: yellow + *.color11: yellow_bright + *.color4: blue + *.color12: blue_bright + *.color5: magenta + *.color13: magenta_bright + *.color6: cyan + *.color14: cyan_bright + *.color7: white + *.color15: white_bright +} +array'reverse from_xresources to_xresources + +proc parse_xresources {filename} { + global from_xresources + set file [open $filename r] + set file_data [read $file] + close $file + set lines [split $file_data "\n"] + + array set colors {} + foreach line $lines { + set line [string trim $line] + if { $line eq {} || [string first "!" $line] >= 0 } { + continue + } + set name [lindex $line 0] + set value [lindex $line 1] + if {[info exist from_xresources($name)]} { + set key $from_xresources($name) + set colors($key) $value + } + } + return [array get colors] +} + +proc produce_xresources {_colors} { + global to_xresources + upvar $_colors colors + foreach color [array names colors] { + if {[info exist to_xresources($color)]} { + set key $to_xresources($color) + set value $colors($color) + puts "! $color" + puts "$key\t$value" + } + } +} + +# Simple Terminal (suckless) +set st_colors [list white red green yellow blue magenta cyan black \ + white_bright red_bright green_bright yellow_bright blue_bright \ + magenta_bright cyan_bright black_bright] +set st_more_colors [list cursor background foreground background] + +proc process_st_colors {keys _colors} { + upvar $_colors colors + foreach key $keys { + if {[info exist colors($key)]} { + set value $colors($key) + puts "\t\"$value\", // $key" + } else { + puts stderr "Missed color $key" + exit 1 + } + } +} + +proc produce_st {_colors} { + global st_colors st_more_colors + upvar $_colors colors + puts "static const char *colorname\[\] = \{" + process_st_colors $st_colors colors + puts "\t\[255\] = 0," + process_st_colors $st_more_colors colors + puts "\};" +} + +# DWM +array set dwm_colors { + active_font background + inactive_font foreground \ + active_bg foreground + inactive_bg background +} +proc produce_dwm {_colors} { + global dwm_colors + upvar $_colors colors + foreach key [array names dwm_colors] { + set color $dwm_colors($key) + set value $colors($color) + puts "static const char $key\[\] = \"$value\";" + } +} + +# dmenu +set dmenu_colors [list SchemeNorm background foreground \ + SchemeSel foreground background \ + SchemeOut red cyan] +proc produce_dmenu {_colors} { + global dmenu_colors + upvar $_colors colors + puts "static const char *colors\[SchemeLast\]\[2\] = \{" + foreach {name fg bg} $dmenu_colors { + set fg_color $colors($fg) + set bg_color $colors($bg) + puts "\t\[$name\] = \{ \"$fg_color\", \"$bg_color\" \}," + } + puts "\};" +} + +# Xinit +proc produce_xinit {_colors} { + upvar $_colors colors + set color $colors(blue) + puts "xsetroot -solid \"$color\" &" + puts "exec dwm" +} + +proc produce {file_format _colors} { + upvar $_colors colors + switch $file_format { + xres { + produce_xresources colors + } + st { + produce_st colors + } + dwm { + produce_dwm colors + } + dmenu { + produce_dmenu colors + } + xinit { + produce_xinit colors + } + default { + puts stderr "Unknown format." + exit 1 + } + } +} + +if {$argc < 3} { + puts "Usage:" + puts "\t$argv0 produce format color_scheme" + puts "\t$argv0 parse format file" + puts "\tformat: xres st dwm xinit" + exit 1 +} + +switch [lindex $argv 0] { + produce { + set file_format [lindex $argv 1] + set color_scheme [lindex $argv 2] + set file [open $color_scheme r] + set file_data [read $file] + close $file + array set colors [join $file_data] + produce $file_format colors + } + parse { + set file_format [lindex $argv 1] + set filename [lindex $argv 2] + if {$file_format ne "xres"} { + puts stderr "Unsuported format for parsing $file_format. Use xres." + exit 1 + } + set scheme [parse_xresources $filename] + foreach {key value} $scheme { + puts "$key $value" + } + } + default { + puts stderr "unknown command" + exit 1 + } +} diff --git a/install.sh b/install.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env sh + +./colorist.tcl produce st $1 > stcolors.h +mv stcolors.h ~/project/suckless/st +cd ~/project/suckless/st +make clean +make +sudo make install +cd - + +./colorist.tcl produce dwm $1 > dwmcolors.h +mv dwmcolors.h ~/project/suckless/dwm +cd ~/project/suckless/dwm +make clean +make +sudo make install +cd - + +./colorist.tcl produce dmenu $1 > dmenucolors.h +mv dmenucolors.h ~/project/suckless/dmenu +cd ~/project/suckless/dmenu +make clean +make +sudo make install +cd - + +./colorist.tcl produce xinit $1 > ~/.xinitrc diff --git a/schemes/kasugano b/schemes/kasugano @@ -0,0 +1,19 @@ +white_bright #edeff2 +blue #31658c +white #c8cacc +red_bright #899aff +red #6673bf +yellow_bright #98c9bb +black_bright #4d4d4d +black #3d3d3d +blue_bright #477ab3 +background #1b1b1b +green_bright #52ad91 +green #3ea290 +cyan_bright #95a7cc +cyan #8292b2 +foreground #ffffff +magenta_bright #7882bf +yellow #b0ead9 +magenta #596196 +cursor #ffffff diff --git a/schemes/s3r0-modified b/schemes/s3r0-modified @@ -0,0 +1,19 @@ +white_bright #c0b18b +blue #535c5c +white #c0b18b +red_bright #d17b49 +red #d17b49 +yellow_bright #af865a +black_bright #4a3637 +black #4a3637 +blue_bright #535c5c +background #1f1f1f +green_bright #7b8748 +green #7b8748 +cyan_bright #6d715e +cyan #6d715e +foreground #c0b18b +magenta_bright #775759 +yellow #af865a +magenta #775759 +cursor #c0b18b diff --git a/schemes/visiblue b/schemes/visiblue @@ -0,0 +1,19 @@ +white_bright #ccffff +blue #006699 +white #99cccc +red_bright #9999ff +red #6666cc +yellow_bright #6699ff +black_bright #333399 +black #333366 +blue_bright #0099cc +background #000000 +green_bright #00ccff +green #0099cc +cyan_bright #66cccc +cyan #669999 +foreground #666699 +magenta_bright #0099ff +yellow #3366cc +magenta #0066ff +cursor #666699