Browse Source

Added command-line arguments

* The script is now ready for primetime because users can output to
any template they please
Macoy Madson 5 years ago
  1. 42
  2. 2
  3. 18


@ -3,6 +3,8 @@
import random
import colorsys
import sys
import argparse
This script generates a "base16" color theme intended for code syntax highlighting.
@ -26,14 +28,26 @@ Base16 Style (from
base0F - Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?>
argParser = argparse.ArgumentParser(
description='This script generates a base16 color theme intended for code syntax highlighting from a source image.')
argParser.add_argument('--inputColorPaletteFile', type=str, dest='inputColorPaletteFile', default='colors.txt',
help='The colors the script will select from will be read in from this file. The file should'
' be a list of hexadecimal color values separated by newlines')
argParser.add_argument('template', type=str,
help='The template which the hex colors will be output to. This template should'
' have 16 curly brace pair (\"{}\") where the 16 colors will be output in order. Due to'
' python formatting, you\'ll need to add another brace to any non-format braces'
' ("{{" will become a single "{")')
argParser.add_argument('outputFile', type=str,
help='Colors will be inserted into outputTemplate then written to this outputFile')
argParser.add_argument('--debugColorsVerbose', action='store_const', const=True, default=False, dest='debugColorsVerbose',
help='Print detailed information about color selection')
# TODO: Add other options for templates (take as a command line argument)
outputTemplateFilename = 'emacs-base16-theme-template.el'
outputFilename = 'base16-my-auto-theme.el'
# TODO: Make these into modes that auto-set these constraints
# TODO: Make contrast ratio mode which meets accessibility guidelines (see
@ -219,8 +233,8 @@ Procedure
def main():
colorsFile = open('colors.txt', 'r')
def main(inputColorsFilename, outputTemplateFilename, outputFilename):
colorsFile = open(inputColorsFilename, 'r')
colorsLines = colorsFile.readlines()
@ -259,13 +273,14 @@ def main():
# base0F - Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?>
Base16Color('base0F', pickHighContrastBrightColorUniqueOrRandom)]
# For testing
colorPool = ['#001b8c', '#0a126b', '#010e44', '#772e51', '#ca4733', '#381f4d', '#814174',
'#90142e', '#720d21', '#28217d', '#6d2c88', '#3b0010', '#6e095b', '#827e7b',
'#645361', '#560041']
# The colors we are able to choose from
colorPool = []
if colorsLines:
colorPool = colorsLines
print('Error: Could not parse colors from input colors file {}'.format(inputColorsFilename))
# Remove duplicate colors; these throw off the algorithm
colorPool = list(set(colorPool))
@ -316,4 +331,11 @@ def main():
print('Wrote {} using template {}'.format(outputFilename, outputTemplateFilename))
if __name__ == '__main__':
if len(sys.argv) == 1:
args = argParser.parse_args()
debugColorsVerbose = args.debugColorsVerbose
main(args.inputColorPaletteFile, args.template, args.outputFile)


@ -6,7 +6,6 @@
**** base08, base0B, base0E should be unique between eachother (diff colors)
**** Always have base08 variables be darker than 0A classes, 0D functions, and 0E keywords?
**** Ensure no other foreground text values are the same as base03 comments?
** TODO Take template to use as a command line argument
** TODO Support different heuristic modes (e.g. light theme, more muted, more contrasty)
** TODO IMPORTANT Make sure things are contrasty relative to line highlight (base01?)
** TODO Figure out how to update base16 theme colors without having to reload emacs (just unset and set in customize-themes?)
@ -22,3 +21,4 @@
*** blade2.jpg makes it seem like I need some background brightness clamping system
** DONE Fix blade1.jpg backgrounds getting clamped too hard
** DONE Fix DadSuper8Title not having some things show up (it was a duplicate color in the palette)
** DONE Take template to use as a command line argument


@ -5,18 +5,24 @@ This script generates a [[][base16]] color
This means you can have *beautiful, readable* themes which match your desktop background without having to do any work.
I'm primarily focusing on doing this for Emacs, but it should work for any editor which supports base16.
I currently only have a template for Emacs, but it should work for any editor which supports base16. If you create a template for your format/editor of choice, please feel free to create a pull request adding that template so others can benefit from it.
** Setup
This script relies on [[][schemer2]] to choose colors from images. It then takes the output of schemer2 and selects colors which fit the base16 format. Make sure you have Go installed, then install schemer2:
: go get
Additionally, requires Python 3. requires Python 3.
** How to Use
Run the following command, replacing "your image" with the image you want the theme's colors to be pulled from:
: schemer2 -format img::colors -in [your image] -out colors.txt && python3
Automating the execution of this so that it updates with your desktop background is left as an exercise for the reader :).
Run the following command, replacing `your image` with the image you want the theme's colors to be pulled from:
: schemer2 -format img::colors -in [your image] -out colors.txt && python3 [your template] [your output file]
`schemer2` generates the color palette from the source image and outputs a list of color values to `colors.txt`. We then run (which loads `colors.txt` by default). selects from these color values (and modifies them, if necessary) such that a good theme is created. It loads `your template` and writes the final theme to `your output file`.
For example, I have an image 'wallpaper.jpg' and I want an [[][Emacs base16]] theme to be generated:
: schemer2 -format img::colors -in wallpaper.jpg -out colors.txt && python3 emacs-base16-theme-template.el base16-my-wallpaper-theme.el
I can then copy `base16-my-wallpaper-theme.el` into my Emacs base16 directory and evaluate it, then select it as a theme.
*** Additional Arguments
Note that running
: python3
will output help with argument descriptions.
** Example results