https://github.com/neeasade/colort
colort[int]
https://github.com/neeasade/colort
c colors rice
Last synced: over 1 year ago
JSON representation
colort[int]
- Host: GitHub
- URL: https://github.com/neeasade/colort
- Owner: neeasade
- License: mit
- Created: 2016-01-16T01:22:18.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-02-04T22:12:13.000Z (over 6 years ago)
- Last Synced: 2025-03-18T15:48:39.242Z (over 1 year ago)
- Topics: c, colors, rice
- Language: C
- Homepage:
- Size: 30.3 KB
- Stars: 29
- Watchers: 9
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 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:
 |  | 
------------------------------------|-------------------------------------|------------------------------------
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.
 |  | 
------------------------------------|-------------------------------------|------------------------------------
If for some reason we wanted everything to have a blue tint, we can wrap both the above calls with a `colort -b 40`:
 |  | 
------------------------------------|-------------------------------------|------------------------------------
Input background colors used for the examples: `282828`, `AB4642`, `D8D8D8` from base16 colorsets.
### TODO
- consider accepting input from STDIN
- update the man page