-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtattr.nim
32 lines (30 loc) · 1.44 KB
/
tattr.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import std/os, cligen/humanUt, cligen
when not declared(stdout): import std/syncio
proc tattr(attrs: seq[string]) =
## Emit to stdout an escape string activating text colors/styles, honoring
## $NO_COLOR & also reading ~/.config/cligen for $LC_THEME-based aliases.
##
## Non-color styles (prefix with '-' to turn off):
## bold, faint, italic, inverse, struck, blink (slow), BLINK (fast),
## under{line double dot dash curl}.
##
## Regular color keywords are in lower case; Bright bank in UPPER CASE:
## black, red, green, yellow, blue, purple, cyan, white
## BLACK, RED, GREEN, YELLOW, BLUE, PURPLE, CYAN, WHITE
## Colors are foreground by default. Pre-pend "on_" for Background.
##
## 256-color or true color terminals like xterm|st|kitty also support:
## {fbu}[0..23] for F)ORE/B)ACKgrnd U)NDER grey scale
## {fbu}RGB where R, G, B are in 0..5
## {fbu}RRGGBB with RR, GG, BB are in hexadecimal (true color)
##
## An element of color scale NAME {viridis hue wLen gray pm3d} can be chosen
## via:
## {fbu}sNAME<0.-1>[,..]
## where only `hue` and `wLen` take [,sat,val] optionally.
## "wLen" is for "waveLength" - (yes, I know RGB light is a mixture; terms are
## just to contrast with "frequency order" or hot..cold / cold..hot).
if attrs.len == 0:
raise newException(ValueError, "\n Need >= 1 attrs. See tattr --help")
stdout.write textAttrOn(attrs, plain=existsEnv("NO_COLOR"))
dispatch(tattr)