bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Color


From: Ricardo Cantu
Subject: Color
Date: Mon, 22 Jan 2007 15:35:35 -0700
User-agent: KMail/1.9.5

It seems that once data has been keyed into a field, the keyed in
data can not have its color changed.. 
In the following example, when you first enter a field I want the color
to be SEL, then when you start typing I want the color to be HIGH, then after 
you leave the field I want the color to be NORM. But the color of the keyed 
in data stays HIGH even after doing a  set_field_back(current_field(my_form), 
COLOR_PAIR (NORM)) on the field. Is there a way to change the color of 
already keyed in data?


/*
*  C Implementation: form
*
* Description: Test color
*
*
* Author: Ricardo Cantu <address@hidden>, (C) 2006
*
* Copyright: See COPYING file that comes with this distribution
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <ncurses.h>
#include <form.h>

#define STARTX 15
#define STARTY 4
#define WIDTH 35

#define N_FIELDS 4

int main()
{
  FIELD *field[N_FIELDS];
  FORM  *my_form;
  int    ch, i;
  char   KEY_ESC = '\x1b';
  enum {NORM=1,SEL,HIGH};

  /* Initialize curses */
  initscr();
  cbreak();
  noecho();
  keypad(stdscr, TRUE);
  start_color ();

  /* Normal */
  init_pair (NORM, COLOR_BLACK, COLOR_WHITE);

  /* Selected */
  init_pair (SEL, COLOR_BLACK, COLOR_RED);

  /* Highlighted */
  init_pair (HIGH, COLOR_BLACK, COLOR_YELLOW);

  /* Initialize the fields */
  for(i = 0; i < N_FIELDS - 1; ++i)
  {
    field[i] = new_field(1, WIDTH, STARTY + i * 2, STARTX, 0, 0);

    /* Set field options */
    set_field_back(field[i], COLOR_PAIR (NORM) | A_UNDERLINE);
    field_opts_on(field[i], O_ACTIVE);
    field_opts_on(field[i], O_PUBLIC);
    field_opts_on(field[i], O_AUTOSKIP);
  }
  field[i] = NULL;

  set_field_back(field[0], COLOR_PAIR (SEL));
  set_field_buffer(field[0], 0, "Key something here then press TAB");

  /* Create the form and post it */
  my_form = new_form(field);
  post_form(my_form);
  refresh();

  /* Loop through to get user requests */
  while((ch = getch()) != KEY_ESC)
    {
      switch(ch)
        {
          case '\x09':
          {
            /* This color change is NOT effecting the typed in TEXT  WHY!!*/
            set_field_back(current_field(my_form), COLOR_PAIR (NORM));

            /* Go to next field */
            form_driver(my_form, REQ_NEXT_FIELD);
            set_field_back(current_field(my_form), COLOR_PAIR (SEL));
            break;
          }

          default:
          {
            set_field_back(current_field(my_form), COLOR_PAIR (HIGH));
            form_driver(my_form, ch);
            break;
          }
        }
    }

  endwin();
  return 0;
}
-- 
Ricardo Cantu
Computer Services
3506 Buchanan St Suite C
Wichita Falls, TX 76308
(940) 696-3010





reply via email to

[Prev in Thread] Current Thread [Next in Thread]