help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing colouring through a line of text


From: Greg Wooledge
Subject: Re: Changing colouring through a line of text
Date: Mon, 20 Mar 2023 11:40:00 -0400

On Mon, Mar 20, 2023 at 03:27:57PM +0000, uzibalqa wrote:
> The input string would be 
> 
> str='
>  marinex-dgrul    Digit
>  marinex-ltrul    Letter
>  marinex-nmrul    Numeric'
> 
> Then one would call
> 
> marinex-ndic 18 "$str"
> 
> The plan is to have the beginning of each line being blue, whilst from column 
> number 18 the colour changes to white.

marinex-ndic() {
    local blue=$(tput setaf 4)
    local norm=$(tput sgr0)
    local lines line left right

    mapfile -t lines < <(printf '%s\n' "$2")
    for line in "${lines[@]}"; do
        left=${line:0:$1}
        right=${line:$1}
        printf '%s%s%s%s\n' "$blue" "$left" "$norm" "$right"
    done
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]