Home Explore Blog CI



7abeb7ee7a3f20125e43d9ef3cf0a6382310762cb0be080400000002000147be.png

Extracted Text
coloring > ref_table.nu You, 5 days ago | 1 author (You) 1 # This script will print a table 8 rows by 36 columns 2 # of background colors using ansi index coloring 3 4 # This prints the column headers 5 let nl = (char newline) 6 let plus = $"($nl) + 7 let cols = (seq 0 35 | each { |col| $"($col)" | str lpad -c ' -l 3 } | str collect) 8 $"($plus)($cols)" 9 10 let ansi_bg = (ansi -e '48;5;') 11 let ansi_reset = (ansi reset) 12 $"($nl)($nl)" 13 14 # This prints the row headers 15 let row_header = ' 0 16 let row_data = (seq 0 15 | each { |row| 17 $"($ansi_bg)($row)m ($ansi_reset)" 18 } | str collect) 19 $"($row_header)($row_data)($nl)($nl)" 20 21 # This is the meat of the script that prints the little squares of color 22 seq 0 6 | each { |row_idx| 23 let r = ($"($row_idx) * 36 + 16" | math eval) 24 let row_header = (echo $r | into string -d 0 | str lpad -c ' -l 4) 25 let row_data = (seq 0 35 | each { |row| 26 let val = ($"($r + $row)" | math eval | into string -d 0) 27 $"($ansi_bg)($val)m (ansi -e 'm') " 28 } | str collect) 29 $"($row_header) ($row_data)($nl)($nl)" 30 } | str collect
Explanation
The image shows code for a shell script called `ref_table.nu` written by the user. The script is designed to generate a table with 8 rows and 36 columns, using ANSI index coloring for the background colors. The script includes sections for printing column and row headers, and it generates the table cells with colored squares.