forked from nushell/nu_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nu_index_fg2.nu
24 lines (21 loc) · 826 Bytes
/
nu_index_fg2.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# this script uses foreground ansi index colors to print
# a table of 16 rows by 16 colums where each item is a
# different color
def show_index_colors [] {
let prefix = "38;5;"
echo 1..256 | each {
let cr = $(echo $(build-string $it % 16) | math eval)
let color = $(echo [$(ansi -e $prefix) $(build-string $it) 'm'] | str collect)
let padded_number = $(echo $(build-string $it | str lpad -l 3 -c '0'))
if $cr == 0 {
echo [$color $padded_number ' ' $(char newline)]
} {
echo [$color $padded_number ' ']
}
} | str collect
}
show_index_colors
# one-liner version that just prints
# it all on one line which wraps in
# your terminal
#echo 1..256 | each {echo [$(ansi -e '38;5;') $(build-string $it) 'm' $(build-string $it) ' ']} | str collect