[Top][All Lists]

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

Changing colouring through a line of text

From: uzibalqa
Subject: Changing colouring through a line of text
Date: Mon, 20 Mar 2023 15:27:57 +0000

I am doing a bash function that takes a multiline string and prints each line.  
The first part of each line uses a blue foreground, whereas the rest of each 
line uses a white foreground.

I want to have the user define a column number from which the foreground colour 
on each line changes to white. 

I need help to do this.

The input string would be 

 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 ()
  ## Show coloured  and label

  local -r rst="$( tput sgr0 )"  # Default Graphic Rendition
  local -r blu="$( tput bold; tput setaf 39 )"  # BLUE
  local -r wht="$( tput bold; tput setaf 15 )"  # WHITE

  printf '%s\n' "$@"  \
    | while IFS="" read -r vl; do
        printf '%s%s%s%s%s\n' "${blu}" "$vl" "$wht" "$vl" "${rst}"

reply via email to

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