# shellcheck shell=dash

___x_cmd_term_truecolor(){
    ___x_cmd_term_truecolor_bar "$1"
}

___x_cmd_term_truecolor_bar(){
    local sample="${1:-${COLUMNS:-30}}"
    command awk -v sample="$sample" 'BEGIN{
        for (i=1; i<=sample; ++i) {
            a[i] = (i%2 == 1) ? "/" : "\\"
        }

        for (col = 0; col<=sample; col++) {
            r = 255 - col * 255 / sample
            g = col * 510 / sample;   if (g > 255) g = 510 - g
            b = col * 255 / sample
            printf( "\033[48;2;%d;%d;%dm", r, g, b )
            printf( "\033[38;2;%d;%d;%dm", 255-r, 255-g, 255-b )
            printf( "%s\033[0m", a[col] )
        }
        printf("\n")
    }'
}
