Skip to content
colort[int]
Branch: master
Clone or download
Latest commit 412392a Sep 24, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore markdown, binary Jan 16, 2016
LICENSE license Sep 24, 2017
Makefile
README.md
colort.c change exit on limit Aug 14, 2016
test.sh

README.md

colort[int]

A small program for 'tinting' colors by values. Also supports inverting colors.

command output
colort 1 "#000000" #010101
colort -l 1 "#FFFFFF" #FFFFFF
colort -l 1 "#FFFFFF" #FFFFFF, exit status 0
colort -i "#000000" #FFFFFF
colort 60 "#000000" #3C3C3C
colort -60 "#000000" #C4C4C4
colort -s 4 1 "spam000000spam" spam010101spam
colort -t -s 4 1 "spam000000spam" 010101
colort -t "ff000000" 000000
colort -r 1 "#000000" #010000

Notes:

  • The color is assumed to be the last 6 chars of the input string (can be changed with -s)
  • If the tint value is omitted, defaults to 0.
  • The -l flag limits color tinting by not letting values roll around.
    • if 2 or more of RGB is limited when this is turned on, exit status of 1.
  • The -i flag inverts colors.
  • The -s flag selects the index in the input string to start getting color from.
  • The -t flag makes the output only the color string
  • The -c flag calculates the contrast of the color. If this evaluates to black, exit status 0. If white, exit status 1.
  • If the -r, -g, or -b flags are used, red, green, or blue are affected by the operation respectively.
  • The tint value can be within the set of values supported by a long datatype.

Example use cases:

Invert a background color to have readable text on any background:

1 2 3

Auto-determine select and icon colors for GTK themes based on the background (using oomox and acyl in these examples)

  • Select_color="$(colort -c "$BG" && colort 25 "$BG" || colort -25 "$BG")"
    • If the background contrast is 'dark', tint up, else tint down.
  • Icon_color="$(colort -c "$BG" && colort -l 80 "$BG" || colort -l -80 "$BG")"
    • the same logic, but tinted further to make icons more bold, and a flag to top out at white or black.
1 2 3

If for some reason we wanted everything to have a blue tint, we can wrap both the above calls with a colort -b 40:

1 2 3

Input background colors used for the examples: 282828, AB4642, D8D8D8 from base16 colorsets.

TODO

  • consider accepting input from STDIN
  • update the man page
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.