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
CURSES_COLOR(3) 					   BSD Library Functions Manual 					   CURSES_COLOR(3)

NAME
curses_color, has_colors, can_change_color, start_color, init_pair, pair_content, COLOR_PAIR, PAIR_NUMBER, init_color, color_content, no_color_attributes -- curses color manipulation routines LIBRARY
Curses Library (libcurses, -lcurses) SYNOPSIS
#include <curses.h> bool has_colors(void); bool can_change_color(void); int start_color(void); int init_pair(short pair, short fore, short back); int pair_content(short pair, short *fore, short *back); int COLOR_PAIR(int n); int PAIR_NUMBER(int val); int init_color(short color, short red, short green, short blue); int color_content(short color, short *red, short *green, short *blue); attr_t no_color_attributes(void); extern int COLOR_PAIRS; extern int COLORS; DESCRIPTION
These functions manipulate color on terminals that support color attributes. The function has_colors() indicates whether a terminal is capable of displaying color attributes. It returns TRUE if the terminal is capable of displaying color attributes and FALSE otherwise. The function can_change_color() indicates whether a terminal is capable of redefining colors. It returns TRUE if colors can be redefined and FALSE if they can not. The function start_color() initializes the curses color support on a terminal. It must be called before any color manipulation functions are called on that terminal. The function initializes the eight basic colors (black, red, green, yellow, blue, magenta, cyan and white) that are specified using the color macros (such as COLOR_BLACK) defined in <curses.h>. start_color() also initializes the global external variables COLORS and COLOR_PAIRS. COLORS defines the number of colors that the terminal supports and COLOR_PAIRS defines the number of color-pairs that the terminal supports. These color-pairs are initialized to white foreground on black background. start_color() sets the colors on the terminal to the curses defaults of white foreground on black background unless the functions assume_default_colors() or use_default_colors() have been called previously. The function init_pair(pair, fore, back) sets foreground color fore and background color back for color-pair number pair. The valid range for the color-pair pair is from 1 to COLOR_PAIRS - 1 and the valid range for the colors is any number less than COLORS. Specifying a nega- tive number will set that color to the default foreground or background color. The 8 initial colors are defined as: COLOR_BLACK COLOR_RED COLOR_GREEN COLOR_YELLOW COLOR_BLUE COLOR_MAGENTA COLOR_CYAN COLOR_WHITE Color-pair 0 is used as the default color pair, so changing this will have no effect. Use the function assume_default_colors() to change the default colors. The function pair_content(pair, *fore, *back) stores the foreground and background color numbers of color-pair pair in the variables fore and back, respectively. The macro COLOR_PAIR(n) gives the attribute value of color-pair number n. This is the value that is used to set the attribute of a character to this color-pair. For example, attrset(COLOR_PAIR(2)) will display characters using color-pair 2. The macro PAIR_NUMBER(val) gives the color-pair number associated with the attribute value val. The function init_color(color, red, green, blue) sets the red, green and blue intensity components of color color to the values red, green and blue, respectively. The minimum intensity value is 0 and the maximum intensity value is 1000. The function color_content(color, *red, *green, *blue) stores the red, green and blue intensity components of color color in the variables red, green, and blue, respectively. The function no_color_attributes() returns those attributes that a terminal is unable to combine with color. RETURN VALUES
The functions start_color(), init_pair(), pair_content(), init_color() and color_content() return OK on success and ERR on failure. SEE ALSO
curses_attributes(3), curses_background(3), curses_default_colors(3) STANDARDS
The NetBSD Curses library complies with the X/Open Curses specification, part of the Single Unix Specification. The function no_color_attributes() and the use of negative color numbers are extensions to the X/Open Curses specification. HISTORY
These functions first appeared in NetBSD 1.5. BSD
July 20, 2009 BSD
All times are GMT -4. The time now is 08:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy