Visit Our UNIX and Linux User Community


Ncurses colors


 
Thread Tools Search this Thread
Top Forums Programming Ncurses colors
# 1  
Old 12-12-2014
Ncurses colors

I am using ncurses to develop a user interface. Perhaps I should be using something else, but I am reasonably comfortable with ncurses and don't really want to climb another learning curve at this time.

One problem I have dealt with for many years is ncurses' colors. I have simply been unable to affect the standard colors that are inherent to the code. Specifically, at least a couple of the standard colors look like they have been washed in mud!

COLOR_WHITE, when used as a background, is a light grey. Using a color_pair of COLOR_BLACK, COLOR_WHITE results in dark grey letters on a light grey background.

OTOH, COLOR_WHITE,COLOR_RED has nice bright white letters on a nice red background.

The standard COLOR_YELLOW looks like mustard, not a bright yellow like I would desire.

init_color doesn't seem to have any effect at all.

I have collected sample of what ncurses gives me in the attachment. To illustrate my dislike of the ncurses colors, I have embedded the samples in a background of the same colors as GIMP supplies. The black text labeling each piece was supplied via GIMP.

Suggestions?
Ncurses colors-colorsamplepng

Last edited by BillLee; 12-12-2014 at 11:37 AM.. Reason: Added words
# 2  
Old 12-12-2014
Hi BillLee...

I am not familiar with ncurses but to get an extended range to the colours in the shell the __bold__ attribute has be on...

I assume that there is a BOLD attribute for ncurses...

This is an example, note the second loop might not work in some terminals...
Code:
#!/bin/bash
# colours.sh
n=0
for fg in {30..37}
do
	for bg in {40..47}
	do
		for bold in 0 1
		do
			# 1 = bold ON.
			printf "\x1B["$bold";"$bg";"$fg"m Line $n, bold = $bold, background = $bg, foreground = $fg...\x1B[0m\n"
			n=$((n+1))
		done
	done
done
for fg in {90..97}
do
	for bg in {100..107}
	do
		for bold in 0 1
		do
			# 1 = bold ON.
			printf "\x1B["$bold";"$bg";"$fg"m Line $n, bold = $bold, background = $bg, foreground = $fg...\x1B[0m\n"
			n=$((n+1))
		done
	done
done


Last edited by wisecracker; 12-12-2014 at 07:22 PM.. Reason: Added bold to the code.
These 2 Users Gave Thanks to wisecracker For This Post:
# 3  
Old 12-12-2014
Thanks for the reply.

I failed to note that all of the ncurses text in my example was in bold font.
# 4  
Old 12-12-2014
That are alot of lines...
Mine's not that esay share-able :|
But imho much more overseeable. Smilie

The script will not run without TUI.
Code:
#!/bin/bash
# myColors
# Description:	a little color demonstration
# ------------------------------------------------------
#
#	Variables
#
	R=$(tui-conf-get /etc/tui/colors.conf TUI_COLOR_RESET)
	R=${R/^ /}
	TC=TUI_COLOR_
	TF=TUI_FONT_
	colors="BLACK BLUE CYAN GREEN GREY PURPLE RED WHITE YELLOW"
	styles="BOLD  UNDERSCORE STROKE " #  INVERT
#
#	Functions
#
	be_color() { # STRING_NAME
	# Returns the value of STRING_NAME
	# Expects strings like: TUI_COLOR_[BF]G_<NAME> or TUI_FONT_<STYLE>
		tui-conf-get /etc/tui/colors.conf $1
	}
#
#	Display & Action
#
	tui-title "Color demonstation using tui color names"
	for font in $colors;do
	# This is the font color, and shall be used for the whole line
		F="$(be_color ${TC}FG_${font})"
		for sty in $styles;do
			S="$(be_color ${TF}${sty})"
			for col in $colors;do
				# This is the back color, used for the column
				B="$(be_color ${TC}BG_${col})"
				C="${R}${F}${B}" # Closer
				a="${TC}FG_${font} \t${TF}${sty}"
				# Regular output
				printf "${C}a${S}style"
			done
			printf "$R -- $a \n"
		done
	done

Ncurses colors-tui-bash-colorsjpg

Last edited by sea; 12-12-2014 at 09:03 PM..
# 5  
Old 12-12-2014
Again, thanks for the response, but I don't see how this addresses my original question: what do I need to do to make ncurses display reasonable colors?
# 6  
Old 12-12-2014
And, supporting wisecracker's suggestion, from the curs_color(3X) man page on OS X:
Code:
       Several caveats apply on  386  and  486  machines  with  VGA-compatible
       graphics:

       -    COLOR_YELLOW  is  actually brown.  To get yellow, use COLOR_YELLOW
            combined with the A_BOLD attribute.
       ... ... ...

# 7  
Old 12-13-2014
Hello BillLee
This is some code from a long time ago. Dont use C much anymore. If you're not using C this might not help. I hope it does though.
Code:
int
StartColors ()
{
  start_color ();

  init_pair (0, COLOR_WHITE, COLOR_BLACK);
  init_pair (1, COLOR_CYAN, COLOR_BLACK);
  init_pair (2, COLOR_WHITE, COLOR_BLUE);
  init_pair (3, COLOR_WHITE, COLOR_BLACK);
  init_pair (4, COLOR_WHITE, COLOR_RED);
  init_pair (5, COLOR_BLACK, COLOR_GREEN);
  /*
  init_pair (0, COLOR_WHITE, COLOR_BLACK);
  init_pair (DIR_NORM, COLOR_CYAN, COLOR_BLACK);
  init_pair (DIR_HI, COLOR_BLUE, COLOR_WHITE);
  init_pair (FIL_NORM, COLOR_WHITE, COLOR_BLACK);
  init_pair (FIL_HI, COLOR_RED, COLOR_WHITE);
  init_pair (5, COLOR_BLACK, COLOR_GREEN);
  init_pair (6, COLOR_MAGENTA, COLOR_BLACK);
  init_pair (7, COLOR_BLUE, COLOR_CYAN);
  init_pair (8, COLOR_RED, COLOR_BLACK);
  init_pair (9, COLOR_BLUE, COLOR_CYAN);
  init_pair (10, COLOR_GREEN, COLOR_BLACK);
  init_pair (12, COLOR_CYAN, COLOR_BLACK);
  init_pair (13, COLOR_BLUE, COLOR_WHITE);
  init_pair (14, COLOR_YELLOW, COLOR_CYAN);
  init_pair (15, COLOR_WHITE, COLOR_BLUE);
  init_pair (16, COLOR_YELLOW, COLOR_CYAN);
  init_pair (17, COLOR_BLUE, COLOR_WHITE);
  init_pair (18, COLOR_YELLOW, COLOR_RED);
  init_pair (19, COLOR_YELLOW, COLOR_BLACK);
  */

  return (0);
}



int
WbkgdSet (WINDOW * w, chtype c)
{
  if (has_colors ())
    {
      wbkgdset (w, c);
    }
  else
    {
      c &= ~A_BOLD;
      if (c == COLOR_PAIR (1) ||
      c == COLOR_PAIR (2) ||
      c == COLOR_PAIR (3) || c == COLOR_PAIR (4) || c == COLOR_PAIR (5))
    {

      wattrset (w, A_REVERSE);
    }
      else
    {
      wattrset (w, 0);
    }
    }
}


Previous Thread | Next Thread
Test Your Knowledge in Computers #91
Difficulty: Easy
To change to another directory in Linux, you use the cd command.
True or False?

10 More Discussions You Might Find Interesting

1. Programming

[C/Ncurses]Need help on a project

Hi guys I'm a newbie.Got a school project:need to convert Linux Hunt game,which is in K&R C to C99.I got some problems over Ncurses files:new library it's very different from the old one.There are some variables that with gcc are considered undefined 'cause they are no more used in the new Ncurses... (2 Replies)
Discussion started by: fracche
2 Replies

2. Programming

Memory sharing with NCURSES

Hey, Im using a shared memory segment to share a WINDOW structure among 2 processes. Basically I'm building a multi-player snake game in which multiple prrocesses access the window. The 'parent' process initializes the shared memory segment and puts the window in it. I can access and perform... (1 Reply)
Discussion started by: dgre0018
1 Replies

3. Programming

ncurses refresh()

i have read in one of links, there its documented but i am using following code int main () { char ch; initscr(); printw("Enter a char :"); ch=getch(); printw("You Entered '%c' ",ch); getch(); endwin(); return 0; } the code does... (2 Replies)
Discussion started by: MrUser
2 Replies

4. UNIX for Dummies Questions & Answers

ncurses not in library?

I tried to complile a text-based messenger program but, while configuring, got a message saying that ncurses wasn't found. Though it appears to be there... This is the program: http://sourceforge.net/project/showfiles.php?group_id=110124&package_id=119574&release_id=373164 I get the error... (5 Replies)
Discussion started by: riwa
5 Replies

5. Programming

Help with ncurses

Help with ncurses Hi, I need some help with ncurses.I'm supposed to write a program in C to display date and time and also to input the username and password using C.I chose ncurses for my task and here I am. Code: #include <stdio.h> #include <termios.h> #include... (1 Reply)
Discussion started by: rakesh_01
1 Replies

6. Linux

Ncurses with Ubuntu

Hi, I am new to this programming with ncurses. I want to work out few examples on this ncurses. I jus want to know whether this ncurses works with Ubuntu OS? I found tat ncurses doesn come with AIX OS, may be it could be installed as a SupportPac or something, not sure about it. Can u please... (4 Replies)
Discussion started by: julie_s
4 Replies

7. Programming

nCurses over telnet

hello all. my first post here :) i just want a little help. i have a small app tha uses ncurses for gui, and for user input. I need this app to be executed on a sever side, and have access to it through telnet. When i test it, i see that enter makes the hole gui move up, and some other... (0 Replies)
Discussion started by: tamtam
0 Replies

8. UNIX for Advanced & Expert Users

Using Ncurses for testing vi

Hi, Somebody has told me that NCurses can be used to test vi. But i was unable to figure out how. If anybody has done anything with NCurses please reply. Also is there any othre way by which we can test vi automatically? (2 Replies)
Discussion started by: rahulrathod
2 Replies

9. Programming

ncurses -> the best way to use menus

hello there, i'm exploring the curses lib and i'm having some trouble with "defining a style". to clarify: i'm creating a menu driven app and i've been thinking what's the best way to use menus: make global vars (not my favourite), creating a function which designs the menu and returns the... (2 Replies)
Discussion started by: crashnburn
2 Replies

10. Programming

ncurses/Darwin

I am using Darwin on Mac OS X.I.I (new to both Unix and C++). I downloaded the ncurses library from http://prdownloads.sourceforge.net/gnu-darwin/ncurses-5.2.tgz, but I don't know what to do with it now. Stuffit has expanded the archive, but I still have the original .tgz as well (if that's... (1 Reply)
Discussion started by: parmenides
1 Replies

Featured Tech Videos