Extending terminal colors to the end of line

后端 未结 3 1022
温柔的废话
温柔的废话 2021-02-02 11:49

I have a bash script which generates a motd. The problem is depending on some terminal settings which I am not sure about the color will extend to the end of the line. Othertime

3条回答
  •  臣服心动
    2021-02-02 12:40

    Maybe use the Escape sequence to clear-to-EOL

    For some reason (on my MacOS terminal!) I only needed specify this sequence and then it worked for all the lines but for completeness I list it for all

    TC_RESET=$'\x1B[0m'
    TC_SKY=$'\x1B[0;37;44m'
    TC_GRD=$'\x1B[0;30;42m'
    TC_TEXT=$'\x1B[38;5;203m'
    CLREOL=$'\x1B[K'
    
    echo -n "${TC_SKY}${CLREOL}"
    echo -e "\n           ABC${CLREOL}\n"
    echo -e "\n              DEFG${CLREOL}\n"
    
    echo -n "${TC_GRD}"
    echo -e "\n           ABC${CLREOL}\n"
    echo -e "\n              DEFG${CLREOL}\n"
    echo ${TC_RESET}
    

提交回复
热议问题