Sponsored Content
Full Discussion: Ncurses colors
Top Forums Programming Ncurses colors Post 302928589 by ongoto on Saturday 13th of December 2014 03:18:17 AM
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);
    }
    }
}

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
curs_color(3)						     Library Functions Manual						     curs_color(3)

NAME
curs_color, start_color, init_pair, init_color, has_colors, can_change_color, color_content, pair_content, COLOR_PAIR, COLOR_PAIRS, COLORS, PAIR_NUMBER - Curses color-manipulation routines and variables SYNOPSIS
# include <curses.h> int start_color( void ); int init_pair( short pair, short f, short b ); int init_color( short color, short r, short g, short b ); bool has_colors( void ); bool can_change_color( void ); int color_content( short color, short *r, short *g, short *b ); int pair_content( short pair, short *f, short *b ); int COLOR_PAIR( int n ); int PAIR_NUMBER( int value ); LIBRARY
Curses Library (libcurses) STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: start_color, init_pair, init_color, has_colors, can_change_color, color_content, pair_content, COLOR_PAIR, PAIR_NUMBER: XCURSES4.2 Refer to the standards(5) reference page for more information about industry standards and associated tags. DESCRIPTION
The Curses library includes routines that manipulate color-on-color alphanumeric terminals. To use these routines, applications must call start_color, usually right after initscr. Colors are always used in pairs (referred to as color-pairs). A color-pair consists of a fore- ground color (for characters) and a background color (for the field on which the characters are displayed). An application calls init_pair to initialize a color-pair. After the color-pair is initialized, applications can call COLOR_PAIR(n) to use color attributes. If a terminal is capable of redefining colors, applications can use the routine init_color to change the definition of a color. The rou- tines has_colors and can_change_color return TRUE or FALSE, depending on whether the terminal has color capabilities and whether the appli- cation can change the colors. The routine color_content allows an application to identify the amounts of red, green, and blue components in an initialized color. The routine pair_content allows the application to find out how a given color-pair is currently defined. Routine Descriptions The start_color routine requires no arguments. It must be called if the application uses colors, and before the application calls any other color manipulation routine. It is good practice to call this routine right after initscr. The start_color routine initializes eight basic colors (black, red, green, yellow, blue, magenta, cyan, and white) and two global variables (COLORS and COLOR_PAIRS, which respectively define the maximum number of colors and color-pairs the terminal can support). The start_color routine also restores the colors on the ter- minal to the values they had when the terminal was turned on. The init_pair routine changes the definition of a color-pair. This routine takes three arguments that are identification numbers for the following: The color-pair to be changed The foreground color The background color The value of the first argument must be between 1 and the smaller of either 63 or COLOR_PAIRS-1. The values of the second and third argu- ments must be between 0 and COLORS. If the color-pair was previously initialized, the screen is refreshed and all occurrences of that color-pair are changed to the new definition. The init_color routine changes the definition of a color. This routine takes four arguments: the number of the color to be changed followed by three RGB values (for the amounts of red, green, and blue components, respectively). The value of the first argument must be between 0 and COLORS. (See the subsection Colors for the default color index.) Each of the last three arguments must be a value between 0 and 1000. When init_color is used, all occurrences of that color on the screen immediately change to the new definition. The has_colors routine requires no arguments. It returns TRUE if the terminal can manipulate colors; otherwise, the routine returns FALSE. This routine facilitates writing terminal-independent programs. For example, a programmer can use it to decide whether to use color or some other video attribute. The can_change_color routine requires no arguments. It returns TRUE if the terminal supports colors and can change their definitions; oth- erwise, the routine returns FALSE. This routine facilitates writing terminal-independent programs. The color_content routine gives users a way to find the intensity of the red, green, and blue (RGB) components in a color. This routine requires four arguments: the color number, and three addresses (of short data type) for storing the information about the amounts of red, green, and blue components in the given color. The value of the first argument must be between 0 and COLORS. The values that are stored at the addresses pointed to by the last three arguments are between 0 (no component) and 1000 (maximum amount of component). The pair_content routine allows users to find out which colors a given color-pair consists of. This routine requires three arguments: the color-pair number, and two addresses (of short data type) for storing the numbers for the foreground and background colors. The value of the first argument must be between 1 and the smaller of 63 or COLOR_PAIRS-1. The values that are stored at the addresses pointed to by the second and third arguments are between 0 and COLORS. The COLOR_PAIR(n) macro returns the value of the color-pair whose number is n. This value is the color attribute as it would be extracted from a chtype variable. Conversely, the macro PAIR_NUMBER(value) returns the number of the color-pair associated with the color attribute value. Colors In <curses.h>, the following macros are defined. These are the default colors. Curses also assumes that COLOR_BLACK is the default back- ground color for all terminals. COLOR_BLACK COLOR_RED COLOR_GREEN COLOR_YELLOW COLOR_BLUE COLOR_MAGENTA COLOR_CYAN COLOR_WHITE NOTES
The header file <curses.h> automatically includes the header file <stdio.h>. Note that COLOR_PAIR and PAIR_NUMBER may be macros. RETURN VALUES
The COLOR_PAIR, PAIR_NUMBER, can_change_color, and has_colors routines return values as indicated in the DESCRIPTION section. All other routines return ERR upon failure and OK upon successful completion. SEE ALSO
Functions: curses(3), curs_attr_get(3), curs_initscr(3) Others: standards(5) curs_color(3)
All times are GMT -4. The time now is 05:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy