WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [SOLVED] Set background/foreground color  (Read 2509 times)

Offline deetee

  • Newbie
  • *
  • Posts: 34
[SOLVED] Set background/foreground color
« on: April 22, 2013, 05:58:07 AM »
Hi all!

I would like to set the colors for background and foreground in the console.

I used to do it with 'setterm' which seems to be a bash-specific command, which is not supported from TC (ash, busybox-shell).
I found a way to do it with 'ESC-sequences' (i.e. 'echo -e "\033[40;1m"'), but this seems to be to complicated (need of a list for color- and effect-codes).

Is there a simpler way to change the forground and background color?

TIA deetee
« Last Edit: April 25, 2013, 04:05:02 AM by deetee »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11502
Re: Set background/foreground color
« Reply #1 on: April 22, 2013, 11:05:24 AM »

Offline deetee

  • Newbie
  • *
  • Posts: 34
Re: Set background/foreground color
« Reply #2 on: April 23, 2013, 01:41:11 AM »
Thanks for the link.

To install the package (util-linux-ng.tcz) to use setterm seems to be a fast and comfortable solution.

But regarding to a 'small footprint' - which is the primary focus of TC - installing a further package should be the second best solution.

Maybe I can automate the ESC-sequences (script) if there is no 'best solution'?

deetee
« Last Edit: April 23, 2013, 03:25:50 AM by deetee »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11502
Re: Set background/foreground color
« Reply #3 on: April 23, 2013, 02:21:09 AM »
Hi deetee
You could always pull out  setterm  if you don't need anything else from  util-linux.tcz. You might also need  libtinfo.so.5.
You can create an extension out of those two files (see the Wiki) or copy them from /tmp/tcloop/... to /usr/local/...  and
add them to your backup. If you just need colored text, there are color functions defined in  /etc/init.d/tc-functions that
you can call from a script. Look in  /etc/init.d/tc-config  to see how to include  /etc/init.d/tc-functions  and how to use colors.

Offline deetee

  • Newbie
  • *
  • Posts: 34
Re: Set background/foreground color
« Reply #4 on: April 24, 2013, 03:58:53 AM »
Hi Rich!

Thank you so much for your excellent hints.

'Extracting' the binaries of setterm is a good idea, but seems to 'intervent' to much the TC-system (I can't explain it better, but that's a gut feeling).

I ever wondered where the variables RED, GREEN, etc. are defined in TC. Now I know that this is done in /etc/init.s/tc-functions (maybe I should analize the TC-system better).
To change the color of the foreground with i.e. 'echo $RED' helps me a lot. Unfortunately TC doesn't define variables for the background (i.e. "BGRED=$(echo -e '\033[1;41m')"). But that's what I could add and automate with a script.

Thanks for guiding me the right way.
Regards deetee