Пример #1
0
int setup_env()
{
  setlocale(LC_ALL, "C");

  initscr();
  cbreak();
  noecho();
  nonl();
  intrflush(stdscr, FALSE);
  keypad(stdscr, TRUE);
  curs_set(0);

  define_key("q", KEY_Q);
  define_key("w", KEY_W);
  define_key("e", KEY_E);
  define_key("s", KEY_S);
  define_key("d", KEY_D);
  define_key("z", KEY_Z);
  define_key("x", KEY_X);
  define_key("r", KEY_R);
  define_key("p", KEY_P);

  start_color();
  init_pair(FOOD_COLOR, COLOR_RED, COLOR_BLACK); /*food color*/
  init_pair(SNAKE_COLOR, COLOR_GREEN, COLOR_BLACK); /*snake color*/
  init_pair(WALL_COLOR, COLOR_WHITE, COLOR_BLACK); /*wall color*/

  return 0;
}
Пример #2
0
define_key(const char *str, int keycode)
{
    int code = ERR;

    T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode));
    if (SP == 0) {
	code = ERR;
    } else if (keycode > 0) {
	if (str != 0) {
	    define_key(str, 0);
	} else if (has_key(keycode)) {
	    while (_nc_remove_key(&(SP->_keytry), (unsigned) keycode))
		code = OK;
	}
	if (str != 0) {
	    if (key_defined(str) == 0) {
		(void) _nc_add_to_try(&(SP->_keytry), str, (unsigned) keycode);
		code = OK;
	    } else {
		code = ERR;
	    }
	}
    } else {
	while (_nc_remove_string(&(SP->_keytry), str))
	    code = OK;
    }
    returnCode(code);
}
Пример #3
0
static void
really_define_key(WINDOW *win, const char *new_string, int code)
{
    int rc;
    const char *code_name = keyname(code);
    char *old_string;
    char *vis_string = 0;
    char temp[80];

    if (code_name == 0) {
	sprintf(temp, "Keycode %d", code);
	code_name = temp;
    }

    if ((old_string = keybound(code, 0)) != 0) {
	wprintw(win, "%s is %s\n",
		code_name,
		vis_string = visible(old_string));
    } else {
	wprintw(win, "%s is not bound\n",
		code_name);
    }
    log_last_line(win);

    if (vis_string != 0) {
	free(vis_string);
	vis_string = 0;
    }

    vis_string = visible(new_string);
    if ((rc = key_defined(new_string)) > 0) {
	wprintw(win, "%s was bound to %s\n", vis_string, keyname(rc));
	log_last_line(win);
    } else if (new_string != 0 && rc < 0) {
	wprintw(win, "%s conflicts with longer strings\n", vis_string);
	log_last_line(win);
    }
    rc = define_key(new_string, code);
    if (rc == ERR) {
	wprintw(win, "%s unchanged\n", code_name);
	log_last_line(win);
    } else if (new_string != 0) {
	wprintw(win, "%s is now bound to %s\n",
		vis_string,
		code_name);
	log_last_line(win);
    } else if (old_string != 0) {
	wprintw(win, "%s deleted\n", code_name);
	log_last_line(win);
    }
    if (vis_string != 0)
	free(vis_string);
    if (old_string != 0)
	free(old_string);
}
Пример #4
0
int main() {
	int ok = 0, key = 0;
	char sequence_str[] = "x[6A";
	sequence_str[0] = 27;

	initscr();
	keypad(stdscr, TRUE);
	noecho();
	ok = define_key(sequence_str, 42);
	key = getch();
	endwin();
	printf("ok = %d, key = %d\n", ok, key);
	return 0;
}
Пример #5
0
static PyObject*
curses_ex_define_key(PyObject *self, PyObject *args) {
    const char *definition = NULL;
    int keycode = -1;
    if (!PyArg_ParseTuple(args, "|yi:define_key", &definition, &keycode))
        return NULL;

    if (ERR == define_key(definition, keycode)) {
        curses_ex_seterror("define_key");
        return NULL;
    }

    Py_RETURN_NONE;
}
Пример #6
0
Файл: CRT.c Проект: lyase/htop
void CRT_init(int delay, int colorScheme) {
     initscr();
     noecho();
     CRT_delay = delay;
     CRT_colorScheme = colorScheme;
     halfdelay(CRT_delay/2);
     nonl();
     intrflush(stdscr, false);
     keypad(stdscr, true);
     curs_set(0);
     if (has_colors()) {
          start_color();
          CRT_hasColors = true;
     } else {
          CRT_hasColors = false;
     }
     CRT_termType = getenv("TERM");
     if (String_eq(CRT_termType, "xterm") || String_eq(CRT_termType, "xterm-color") || String_eq(CRT_termType, "vt220")) {
          define_key("\033[H", KEY_HOME);
          define_key("\033[F", KEY_END);
          define_key("\033OP", KEY_F(1));
          define_key("\033OQ", KEY_F(2));
          define_key("\033OR", KEY_F(3));
          define_key("\033OS", KEY_F(4));
          define_key("\033[11~", KEY_F(1));
          define_key("\033[12~", KEY_F(2));
          define_key("\033[13~", KEY_F(3));
          define_key("\033[14~", KEY_F(4));
          define_key("\033[17;2~", KEY_F(18));
     }
#ifndef DEBUG
     signal(11, CRT_handleSIGSEGV);
#endif
     signal(SIGTERM, CRT_handleSIGTERM);
     use_default_colors();
     if (!has_colors())
          CRT_colorScheme = 1;
     CRT_setColors(CRT_colorScheme);

     mousemask(BUTTON1_CLICKED, NULL);
}
Пример #7
0
Файл: CRT.c Проект: EliteTK/htop
void CRT_init(int delay, int colorScheme) {
   initscr();
   noecho();
   CRT_delay = delay;
   if (CRT_delay == 0) {
      CRT_delay = 1;
   }
   CRT_colors = CRT_colorSchemes[colorScheme];
   CRT_colorScheme = colorScheme;
   
   for (int i = 0; i < LAST_COLORELEMENT; i++) {
      unsigned int color = CRT_colorSchemes[COLORSCHEME_DEFAULT][i];
      CRT_colorSchemes[COLORSCHEME_BROKENGRAY][i] = color == (A_BOLD | ColorPair(Black,Black)) ? ColorPair(White,Black) : color;
   }
   
   halfdelay(CRT_delay);
   nonl();
   intrflush(stdscr, false);
   keypad(stdscr, true);
   mouseinterval(0);
   curs_set(0);
   if (has_colors()) {
      start_color();
      CRT_hasColors = true;
   } else {
      CRT_hasColors = false;
   }
   CRT_termType = getenv("TERM");
   if (String_eq(CRT_termType, "linux"))
      CRT_scrollHAmount = 20;
   else
      CRT_scrollHAmount = 5;
   if (String_eq(CRT_termType, "xterm") || String_eq(CRT_termType, "xterm-color") || String_eq(CRT_termType, "vt220")) {
      define_key("\033[H", KEY_HOME);
      define_key("\033[F", KEY_END);
      define_key("\033[7~", KEY_HOME);
      define_key("\033[8~", KEY_END);
      define_key("\033OP", KEY_F(1));
      define_key("\033OQ", KEY_F(2));
      define_key("\033OR", KEY_F(3));
      define_key("\033OS", KEY_F(4));
      define_key("\033[11~", KEY_F(1));
      define_key("\033[12~", KEY_F(2));
      define_key("\033[13~", KEY_F(3));
      define_key("\033[14~", KEY_F(4));
      define_key("\033[17;2~", KEY_F(18));
      char sequence[3] = "\033a";
      for (char c = 'a'; c <= 'z'; c++) {
         sequence[1] = c;
         define_key(sequence, KEY_ALT('A' + (c - 'a')));
      }
   }
#ifndef DEBUG
   signal(11, CRT_handleSIGSEGV);
#endif
   signal(SIGTERM, CRT_handleSIGTERM);
   signal(SIGQUIT, CRT_handleSIGTERM);
   use_default_colors();
   if (!has_colors())
      CRT_colorScheme = 1;
   CRT_setColors(CRT_colorScheme);

   /* initialize locale */
   setlocale(LC_CTYPE, "");

#ifdef HAVE_LIBNCURSESW
   if(strcmp(nl_langinfo(CODESET), "UTF-8") == 0)
      CRT_utf8 = true;
   else
      CRT_utf8 = false;
#endif

   CRT_treeStr =
#ifdef HAVE_LIBNCURSESW
      CRT_utf8 ? CRT_treeStrUtf8 :
#endif
      CRT_treeStrAscii;

#if NCURSES_MOUSE_VERSION > 1
   mousemask(BUTTON1_RELEASED | BUTTON4_PRESSED | BUTTON5_PRESSED, NULL);
#else
   mousemask(BUTTON1_RELEASED, NULL);
#endif

}
Пример #8
0
static void cui_start(void)
{
	initscr();			/* Initialize ncurses. */
	cbreak();			/* Disable line buffering. */
	noecho();			/* Disable getch() echo. */
	keypad(stdscr, TRUE);		/* Enable num keypad keys. */
	nonl();				/* Disable new-line translation. */
	intrflush(stdscr, FALSE);	/* Disable interrupt flush. */
	curs_set(0);			/* Make cursor invisible */
	nodelay(stdscr, TRUE);		/* Enable non-blocking getch() */

	/* We may be operating with an incorrect $TERM type; in this case
	 * the keymappings will be slightly broken. We want at least
	 * backspace to work though, so we'll define both DEL and ^H to
	 * map to backspace */
	define_key("\x7f", KEY_BACKSPACE);
	define_key("\x08", KEY_BACKSPACE);

	/* we need backtab too, for form navigation. vt220 doesn't include
	 * this (kcbt), but we don't want to require a full linux/xterm termcap
	 */
	define_key("\x1b[Z", KEY_BTAB);

	/* We'll define a few other keys too since they're commonly
	 * used for navigation but the escape character will cause
	 * Petitboot to exit if they're left undefined */
	define_key("\x1b\x5b\x35\x7e", KEY_PPAGE);
	define_key("\x1b\x5b\x36\x7e", KEY_NPAGE);
	define_key("\x1b\x5b\x31\x7e", KEY_HOME);
	define_key("\x1b\x5b\x34\x7e", KEY_END);
	define_key("\x1b\x4f\x48", KEY_HOME);
	define_key("\x1b\x4f\x46", KEY_END);
	define_key("OH", KEY_HOME);
	define_key("OF", KEY_END);
	define_key("\x1b\x5b\x41", KEY_UP);
	define_key("\x1b\x5b\x42", KEY_DOWN);
	define_key("\x1b\x5b\x33\x7e", KEY_DC);

	while (getch() != ERR)		/* flush stdin */
		(void)0;
}
Пример #9
0
/*
 * Setup and run the interactive portion of the program.
 */
void
screen_start(void)
{
    if (initscr() == 0)		/* should return a "WINDOW *" */
	exit(EXIT_FAILURE);
#if HAVE_KEYPAD
    keypad(stdscr, TRUE);
#endif
#if HAVE_DEFINE_KEY
    define_key("\033Ok", '+');
    define_key("\033Ol", ',');
    define_key("\033Om", '-');
    define_key("\033On", '.');
    define_key("\033Op", '0');
    define_key("\033Oq", '1');
    define_key("\033Or", '2');
    define_key("\033Os", '3');
    define_key("\033Ot", '4');
    define_key("\033Ou", '5');
    define_key("\033Ov", '6');
    define_key("\033Ow", '7');
    define_key("\033Ox", '8');
    define_key("\033Oy", '9');
    define_key("\033OM", '\n');
#endif
#if defined(COLOR_BLUE) && defined(COLOR_WHITE) && HAVE_COLOR_PAIR
    if (has_colors()) {
	start_color();
	init_pair(1, COLOR_WHITE, COLOR_BLUE);	/* normal */
	SetColors(1);
#if HAVE_BKGD
	bkgd(CURRENT_COLOR);
#endif
    }
#endif
#if HAVE_TYPEAHEAD
    typeahead(-1);		/* disable typeahead */
#endif
#if SYS_MSDOS && defined(F_GRAY) && defined(B_BLUE)
    wattrset(stdscr, F_GRAY | B_BLUE);	/* patch for old PD-Curses */
#endif
    raw();
    nonl();
    noecho();
    set_screensize();
}
Пример #10
0
int
ncurses_init()
{
    int bg, fg;
    const char *term;
    // Set Locale
    setlocale(LC_CTYPE, "");

    // Initialize curses
    if (!initscr()) {
        fprintf(stderr, "Unable to initialize ncurses mode.\n");
        return -1;
    }

    // Check if user wants a black background
    if (setting_has_value(SETTING_BACKGROUND, "dark")) {
        assume_default_colors(COLOR_WHITE, COLOR_BLACK);
    } else {
        use_default_colors();
    }
    // Enable Colors
    start_color();
    cbreak();

    // Dont write user input on screen
    noecho();
    // Hide the cursor
    curs_set(0);
    // Only delay ESC Sequences 25 ms (we dont want Escape sequences)
    ESCDELAY = 25;

    // Redefine some keys
    term = getenv("TERM");
    if (term
        && (!strcmp(term, "xterm") || !strcmp(term, "xterm-color") || !strcmp(term, "vt220"))) {
        define_key("\033[H", KEY_HOME);
        define_key("\033[F", KEY_END);
        define_key("\033OP", KEY_F(1));
        define_key("\033OQ", KEY_F(2));
        define_key("\033OR", KEY_F(3));
        define_key("\033OS", KEY_F(4));
        define_key("\033[11~", KEY_F(1));
        define_key("\033[12~", KEY_F(2));
        define_key("\033[13~", KEY_F(3));
        define_key("\033[14~", KEY_F(4));
        define_key("\033[17;2~", KEY_F(18));
    }

    if (setting_has_value(SETTING_BACKGROUND, "dark")) {
        fg = COLOR_WHITE;
        bg = COLOR_BLACK;
    } else {
        fg = COLOR_DEFAULT;
        bg = COLOR_DEFAULT;
    }

    // Initialize colorpairs
    init_pair(CP_CYAN_ON_DEF, COLOR_CYAN, bg);
    init_pair(CP_YELLOW_ON_DEF, COLOR_YELLOW, bg);
    init_pair(CP_MAGENTA_ON_DEF, COLOR_MAGENTA, bg);
    init_pair(CP_GREEN_ON_DEF, COLOR_GREEN, bg);
    init_pair(CP_RED_ON_DEF, COLOR_RED, bg);
    init_pair(CP_BLUE_ON_DEF, COLOR_BLUE, bg);
    init_pair(CP_WHITE_ON_DEF, COLOR_WHITE, bg);
    init_pair(CP_DEF_ON_CYAN, fg, COLOR_CYAN);
    init_pair(CP_DEF_ON_BLUE, fg, COLOR_BLUE);
    init_pair(CP_WHITE_ON_BLUE, COLOR_WHITE, COLOR_BLUE);
    init_pair(CP_BLACK_ON_CYAN, COLOR_BLACK, COLOR_CYAN);
    init_pair(CP_WHITE_ON_CYAN, COLOR_WHITE, COLOR_CYAN);
    init_pair(CP_YELLOW_ON_CYAN, COLOR_YELLOW, COLOR_CYAN);
    init_pair(CP_BLUE_ON_CYAN, COLOR_BLUE, COLOR_CYAN);
    init_pair(CP_BLUE_ON_WHITE, COLOR_BLUE, COLOR_WHITE);
    init_pair(CP_CYAN_ON_WHITE, COLOR_CYAN, COLOR_WHITE);
    init_pair(CP_CYAN_ON_BLACK, COLOR_CYAN, COLOR_BLACK);

    return 0;
}
Пример #11
0
Файл: main.c Проект: purchae/xtc
int main(int argc, char* argv[]) {

	int screen_height, screen_width;
#ifdef HAVE_DEFINE_KEY
	char key_string[10];
#endif
	char *termtype;

	config_load();
	initscr();
	if ((in_color = has_colors())) start_color();
	hide_cursor();
	raw();        /* immediate char return */
	noecho ();    /* no immediate echo */
	keypad(stdscr,TRUE);
	termtype = getenv("TERM");
	if (termtype && !strncmp(termtype,"xterm",5)) {
		/* A quick and dirty hack to get certain keys working properly in xterm */
		/* For kvt, you might need to set your terminal emulation to "Original Xterm II" */
#ifdef HAVE_DEFINE_KEY
		sprintf(key_string,"%cOH",033); define_key(key_string,KEY_HOME);
		sprintf(key_string,"%cOF",033); define_key(key_string,KEY_END);
		sprintf(key_string,"%cOj",033); define_key(key_string,'*');
		sprintf(key_string,"%cOm",033); define_key(key_string,'-');
		sprintf(key_string,"%cOM",033); define_key(key_string,KEY_ENTER);
		sprintf(key_string,"%c*k",033); define_key(key_string,'+');
#endif
	}
	
	set_special_chars(config.misc.use_ext_chars);

	getmaxyx(stdscr,screen_height,screen_width);
	if (screen_height >= 40) minifl_height = 8;
	else minifl_height = 4;
	
	
	main_window_draw();
	refresh();
	file_window_init();
	info_window_init();
	status_line_init();
	dir_window_init();

#ifdef HAVE_RESIZETERM
	(void) signal(SIGWINCH, resize_screen); /* arrange interrupts to resize */
#endif


	if (argc >= 2) dir_window_set_path(argv[1]);
	else dir_window_set_initial_path();

	
	dir_window_activate();	
	main_loop();
	
	show_cursor();
	remove_color();
	erase();
	refresh();
	noraw();
	endwin();
	return 0;
}
Пример #12
0
int xyControl()
{
	define_key("\033Op", 1000);
	define_key("\033Oq", 1001);
	define_key("\033Or", 1002);
	define_key("\033Os", 1003);
	define_key("\033Ot", 1004);
	define_key("\033Ou", 1005);
	define_key("\033Ov", 1006);
	define_key("\033Ow", 1007);
	define_key("\033Ox", 1008);
	define_key("\033Oy", 1009);

	// non-arrow keypad keys (for macros)
	define_key("\033OM", 1010); // Enter
	define_key("\033OP", 1011); // NumLock
	define_key("\033OQ", 1012); // /
	define_key("\033OR", 1013); // *
	define_key("\033OS", 1014); // -
	define_key("\033Oj", 1015); // *
	define_key("\033Ok", 1016); // +
	define_key("\033Ol", 1017); // +
	define_key("\033Om", 1018); // .
	define_key("\033On", 1019); // .
	define_key("\033Oo", 1020); // -
	clearScreen();
	echo();
	curs_set(2);
	int Xdist = 0;
	int Ydist = 0;
	while(!quit)
	{    //must be acuroind to servoblaster wiring convention
		move(10,0);
		clrtoeol();
		move(14,0);
		clrtoeol();
		refresh();
		mvprintw(10,5,"Curent Position: X:%d\tY:%d",posX,posY);
		mvprintw(14,5,"Move:");
		mvprintw(14,12,"X:%d",Xdist);
		mvprintw(14,22,"Y:%d",Ydist);
		move(14,14);
		refresh();
		char valueString [6];
		char c = getch();
		if(c=='q'||c=='Q')
			return 0;
		if(c!='\n')
		{
			printw("     ");
			refresh();
			ungetch(c);
			move(14,14);
			getnstr(valueString,6);
			Xdist = atoi(valueString);
		}
		move(14,24);
		c = getch();
		if(c=='q'||c=='Q')
			return 0;
		if(c!='\n')
		{
			printw("     ");
			refresh();
			ungetch(c);
			move(14,24);
			getnstr(valueString,6);
			Ydist = atoi(valueString);
		
		}
		move(15,4);
		clrtoeol;
		//getch();
		mvprintw(15,5,"MOVING       X:%d,   Y:%d              ",Xdist,Ydist);
		refresh();
		posX +=Xdist;
		posY +=Ydist;
		moveXY(Xdist,Ydist);
	}

}