It is currently Thu, 20 Jan 2022 09:37:41 GMT



 
Author Message
 reading/setting current foreground color
I am trying to determine/set, from a bash script, the
current foreground color.

Dont know how to read that.  I tried using tcl's
source cmd to set a persistent parent environment variable
with a little script (ie., source set-fgcolor 34), but that only
works for a single child nesting. If I call source from my main
script, it is already on a child's env, so the master
env does not pass the fgcolor (not exist yet) and I cant
again pass value back to the parent.

Is there a more sane way of doing this?

Thanks for clues
TonyB

--
  __      __  _     I N C.               http://www.**-**.com/
/ __|\\// __||  \  __   __          /         to...@sysdev.org
\__ \ \/\__ \||)|/ O_)\/ /        \/  System Tools / Utilities
|___/ || ___/|_ /\___|\_/        WIntel / Linux Device Drivers



 Sat, 09 Sep 2006 04:19:08 GMT   
 reading/setting current foreground color
On Mon, 22 Mar 2004 12:19:08 -0800

I also tried a trap on EXIT(signal 0) to run the parent env
setting script from the child script, by including
source set-fgcolor 34

where set-fgcolor is
# script executed with tcl source command
# to set persistent environment variable
#
FGCOLOR=$1
export FGCOLOR

but, whereas that script works from parent command line
(single nesting) it does nothing from a trap (trap "source
set-fgcolor 34" 0), when called from a child script...

--
  __      __  _     I N C.               http://www.sysdev.org
/ __|\\// __||  \  __   __          /         to...@sysdev.org
\__ \ \/\__ \||)|/ O_)\/ /        \/  System Tools / Utilities
|___/ || ___/|_ /\___|\_/        WIntel / Linux Device Drivers



 Sat, 09 Sep 2006 04:59:18 GMT   
 reading/setting current foreground color
On Mon, 22 Mar 2004 12:19:08 -0800

Well, I was able to do it.  But I had to split the script
into 2.  One setcolour [fg [bg]] to be used with the tcl
source program to post to the environment:

source `setcolour fg bg` works because setcolour takes user
input and returns a file with the export commands that source
needs to post at the parent SHLVL=1

The second scripts just does the fancy painting, clr screen,
etc. using the environment vars and ANSI sequences with the
assistance of setterm -store.

You can get the scripts at http://www.sysdev.org bundled in the
linuxTheTools v0.6.0 archive.

--
  __      __  _     I N C.               http://www.sysdev.org
/ __|\\// __||  \  __   __          /         to...@sysdev.org
\__ \ \/\__ \||)|/ O_)\/ /        \/  System Tools / Utilities
|___/ || ___/|_ /\___|\_/        WIntel / Linux Device Drivers



 Sat, 09 Sep 2006 10:22:00 GMT   
 reading/setting current foreground color
2004-03-22, 12:19(-08), Joaco:

For terminals with ANSI colors:

To set:

tput setaf <n>

Most terminals with color support are ANSI based, so that should
work. Some other kinds of terminals have different color policies
(you define a color pair for bg/fg (with tput initp), and then
use it, with tput setp <n>). Some terminals have support for 16,
88 or 256 colors (try elinks (a text web browser) on XFree86
xterm for instance, and you'll soon find out that you can do
without mozilla). On some terminals, the "bold" attribute
affects the current foreground color, too. Some terminals have
default colors...

I don't think any terminal will let you query the current
foreground color. It's up to you to maintain that information.

Note, that in most places where color is supported,

printf '%b%s%b\n' '\033[31m' 'text' '\033[m'

should display "text" in red.

Note that the zsh shell has builtin ANSI color support (see info
page).

--
Stphane                      ["Stephane.Chazelas" at "free.fr"]



 Sun, 10 Sep 2006 03:07:15 GMT   
 reading/setting current foreground color
In article <slrnc612n3.5n.stephane.chaze...@spam.is.invalid>,
Stephane CHAZELAS  <this.addr...@is.invalid> wrote:

The SCO UNIX console and anything that emulates it correctly (for example,
SCO's terminal emulator for X, scoterm) have a RAS (Return Attribute Setting)
sequence: CSIS [0-2] M.  

If you e.g. echo '\033[=0M', you'll get "0 7<return>" (or whatever) as though
it were typed at the keyboard.

I don't know if any other terminals have such a sequence, but I wouldn't be
surprised.  Not that it's very useful without a standard terminfo entry for it.

        John
--
John DuBois  spce...@armory.com  KC6QKZ/AE  http://www.armory.com/~spcecdt/



 Sun, 10 Sep 2006 12:58:14 GMT   
 reading/setting current foreground color
On Tue, 23 Mar 2004 20:07:15 +0100

I had no problem displaying colors, but my rendering script
needs to know the background while its filling in different
color artifacts.  Tried, the '\033]=0M', the gentelman below
suggested, but that just echos itself.

Finally, opted for keeping the info myself, but didnt want
to use the filesystem and instead wanted memory.  So tried
using the env for storage, but that gave me problems with
SHLLVL's (process mem space is different when tring to set
env vars from a script). Using tcl's source program helped
a little.  Now thinking of some kind of IPC strategy, to get
the info to the process that can set its own env.

Tony

--
  __      __  _     I N C.               http://www.sysdev.org
/ __|\\// __||  \  __   __          /         to...@sysdev.org
\__ \ \/\__ \||)|/ O_)\/ /        \/  System Tools / Utilities
|___/ || ___/|_ /\___|\_/        WIntel / Linux Device Drivers



 Sun, 10 Sep 2006 09:43:18 GMT   
 reading/setting current foreground color
2004-03-24, 01:43(+00), Joaco:

Just reset the background. There's no standard way to know what
the background color is (and even what the default background
is).

tput setab 7
should set a white background.

tput setab 0
should set a black background.

(unfortunately, that's not always true, you may need to play
with standout (tput smso), just make tests).

See the man page of terminfo in sections 5, for details.

--
Stphane                      ["Stephane.Chazelas" at "free.fr"]



 Sun, 10 Sep 2006 18:00:32 GMT   
 
   [ 7 post ] 

Similar Threads

1. How to change emacs background and foreground colors?

2. Background/Foreground colors in Console

3. Background/foreground colors

4. ergonomic foreground and background colors..

5. change foreground color

6. X fonts in xterm display as solid blocks of foreground color

7. foreground/background same color after X?

8. HELP, change background/foreground color for xterm

9. Changing a terminal's foreground and background color

10. changing background and foreground color


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software