Ejemplo n.º 1
0
int main(int argc, char const *argv[]) {
    WIN win;
    int ch;

    initscr();
    start_color();
    cbreak();

    keypad(stdscr, TRUE);
    noecho();
    init_pair(1, COLOR_CYAN, COLOR_BLACK);

    init_win_params(&win);
    print_win_params(&win);

    attron(COLOR_PAIR(1));
    printw("Press F1 to exit");
    refresh();
    attroff(COLOR_PAIR(1));

    create_box(&win, TRUE);
    while ((ch = getch()) != KEY_F(1)) {
        switch (ch) {
        case KEY_LEFT:
            create_box(&win, FALSE);
            --win.startx;
            create_box(&win, TRUE);
            break;
        case KEY_RIGHT:
            create_box(&win, FALSE);
            ++win.startx;
            create_box(&win, TRUE);
            break;
        case KEY_UP:
            create_box(&win, FALSE);
            --win.starty;
            create_box(&win, TRUE);
            break;
        case KEY_DOWN:
            create_box(&win, FALSE);
            ++win.starty;
            create_box(&win, TRUE);
            break;
        }
    }

    endwin();
    return 0;
}
Ejemplo n.º 2
0
int main(void) {
	int flag=0;

	initscr();
	atexit(quit);
	clear();
	noecho();
	curs_set(0);
	cbreak();
	keypad(stdscr, 1);

	start_color();
	init_pair(1, COLOR_YELLOW, COLOR_BLUE);
	init_pair(2, COLOR_BLACK, COLOR_WHITE);
	init_pair(3, COLOR_BLACK, COLOR_YELLOW);

	win1 = newwin(10, 25, 5, 10);
	win2 = newwin(10, 25, 10, 15);
	box(win1, ACS_VLINE, ACS_HLINE);
	box(win2, ACS_VLINE, ACS_HLINE);
	pan1 = new_panel(win1);
	pan2 = new_panel(win2);
  
	bkgd(COLOR_PAIR(1));
	wbkgd(win1, COLOR_PAIR(2));
	wbkgd(win2, COLOR_PAIR(3));

	mvaddstr(2,4, "F9 beendet das Programm");
	mvwaddstr(win1, 2, 3, "Druecke eine Taste");
	mvwaddstr(win2, 7, 3, "Druecke eine Taste");
	
	update_panels();
	doupdate();

	while(getch() != KEY_F(9)) {
		if (flag==0) {
			top_panel(pan1);
			flag = 1; 
		} else {
			top_panel(pan2);
			flag = 0;
		}

		update_panels();
		doupdate();
	} 

	return (0);  
}
Ejemplo n.º 3
0
int main(void)
{   
  
    extern int flag;
    int i, j;
    int arr[HIGHT][WIDTH] = {0};
    int ch;

    initArr(arr);

    initscr();/* Start curses mode */
    cbreak();/* Line buffering disabled, Pass on * everty thing to me */
    keypad(stdscr, TRUE);/* I need that nift                        y F1 */
    noecho();
    start_color();/* Start the color functionality */

    printWin(arr);

    /* Initialize the window parameters */
    mvprintw(0,0,"%s","Press F1 to exit");
    while((ch = getch()) != KEY_F(1))
    {
        switch(ch)
        {
            case KEY_LEFT:
            case 'h':
            leftArrow(arr);
            printWin(arr);
            break;
            case KEY_RIGHT:
            case 'l':
            rightArrow(arr);
            printWin(arr);
            break;
            case KEY_UP:
            case 'k':
            upArrow(arr);
            printWin(arr);
            break;
            case KEY_DOWN:
            case 'j':
            downArrow(arr);
            printWin(arr);
            break;
        }
    }
    endwin();
    return 0;
}   
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{	WIN win;
	int ch;

	initscr();			/* Start curses mode 		*/
	start_color();			/* Start the color functionality */
	cbreak();			/* Line buffering disabled, Pass on
					 * everty thing to me 		*/
	keypad(stdscr, TRUE);		/* I need that nifty F1 	*/
	noecho();
	init_pair(1, COLOR_CYAN, COLOR_BLACK);

	/* Initialize the window parameters */
	init_win_params(&win);
	print_win_params(&win);

	attron(COLOR_PAIR(1));
	printw("Press F1 to exit");
	refresh();
	attroff(COLOR_PAIR(1));
	
	create_box(&win, TRUE);
	while((ch = getch()) != KEY_F(1))
	{	switch(ch)
		{	case KEY_LEFT:
				create_box(&win, FALSE);
				--win.startx;
				create_box(&win, TRUE);
				break;
			case KEY_RIGHT:
				create_box(&win, FALSE);
				++win.startx;
				create_box(&win, TRUE);
				break;
			case KEY_UP:
				create_box(&win, FALSE);
				--win.starty;
				create_box(&win, TRUE);
				break;
			case KEY_DOWN:
				create_box(&win, FALSE);
				++win.starty;
				create_box(&win, TRUE);
				break;	
		}
	}
	endwin();			/* End curses mode		  */
	return 0;
}
Ejemplo n.º 5
0
Archivo: CRT.c Proyecto: 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);
}
Ejemplo n.º 6
0
static const char *
keyCodeToString (int code)
{
    if (code >= KEY_F(1) and code <= KEY_F(12)) {
        char *buf = GetBuf ();
        sprintf (buf, "F%d", code - KEY_F(1) + 1);
        return buf;
    }

    for (int i = 0; i < n_keys; ++i)
        if (KeyNames[i].key == code)
            return KeyNames[i].name;

    if (code < ' ') {
        char *buf = GetBuf ();
        sprintf (buf, "ctrl %c", code + 64);
        return buf;
    } else {
        char *buf = GetBuf ();
        sprintf (buf, "%c", code);
        return buf;
    }
    return "(unkn)";
}
Ejemplo n.º 7
0
void Gui::handleInput()
{
    int k = getch();
    switch(k)
    {
    case ERR:
        return;
    case KEY_RESIZE:
        recreateWindows();
        return;
    case KEY_F(12):
        ioService.stop();
        return;
    }
}
Ejemplo n.º 8
0
int main(int argc, char ** argv)
{
    WINDOW * my_win;
    int startx, starty, width, height;
    int ch;

    initscr();
    cbreak(); // Line buffering disabled, Pass on everty thing to me
    keypad(stdscr, TRUE); // I need that nifty F1

    height = 3;
    width = 10;
    starty = (LINES - height) / 2; // Calculating for a center placement
    startx = (COLS  - width)  / 2; // of the window
    printw("Press F1 to exit");
    refresh();

    my_win = create_newwin(height, width, starty, startx);

    while ((ch = getch()) != KEY_F(1)) {
        switch (ch) {
        case KEY_LEFT:
            destroy_win(my_win);
            my_win = create_newwin(height, width, starty,--startx);
            break;

        case KEY_RIGHT:
            destroy_win(my_win);
            my_win = create_newwin(height, width, starty,++startx);
            break;

        case KEY_UP:
            destroy_win(my_win);
            my_win = create_newwin(height, width, --starty,startx);
            break;

        case KEY_DOWN:
            destroy_win(my_win);
            my_win = create_newwin(height, width, ++starty,startx);
            break;
        }
    }

    endwin();
    return 0;
}
Ejemplo n.º 9
0
Archivo: form.c Proyecto: smsajid/scdk
int main()
{	FIELD *f1[2];
	FORM  *frm1;
	chtype ch;
	int error;
	HOOK fptr=getbuf;
	
	initscr();
	f1[0]=new_field(24,80,0,0,1,1);
	assert(f1[0]!=NULL);
	f1[1]=NULL;
	frm1=new_form(f1);
	assert(frm1!=NULL);
	set_field_fore(f1[0],A_REVERSE);
	field_opts_off(f1[0],O_STATIC);
	//set_field_buffer(f1[0],0,"Sajid");
	set_field_type(f1[0],TYPE_ALPHA,80);
	set_field_term(f1[0],fptr);
	
	post_form(frm1);
	wrefresh(stdscr);
	keypad(stdscr,TRUE);
	
	while((ch=getch())!=KEY_F(3))
	{	switch(ch)
		{	case KEY_LEFT:
				error=form_driver(frm1,REQ_PREV_CHAR);
				if(error==E_REQUEST_DENIED)
					form_driver(frm1,REQ_SCR_BCHAR);
				break;
			case KEY_RIGHT:
				form_driver(frm1,REQ_NEXT_CHAR);
				break;
			default:
				form_driver(frm1,ch);
				break;
		}
	}
	unpost_form(frm1);
	free_form(frm1);
	free_field(f1[0]);
	getch();
	printw(ptr);
	endwin();
}
Ejemplo n.º 10
0
void wrapNcs::bye(){
 /*This method will replace exitEvent function*/
	int hIntro,wIntro,xIntro,yIntro;
	hIntro=LINES-10;
	wIntro=COLS-10;
	xIntro=(COLS-wIntro)/2;
	yIntro=(LINES-hIntro)/2;
	WINDOW *deco_w1=create_newwin(hIntro,wIntro,yIntro,xIntro);
	WINDOW *deco_w2=create_newwin(hIntro-4,wIntro-4,yIntro+2,xIntro+2);
	WINDOW *winText=create_newwinInv(hIntro-6,wIntro-6,yIntro+3,xIntro+3);
	wprintw(winText,"%s",str.c_str());
	wprintw(winText,"\nbye bye !! \nhit F2 key to finish\n");
	wrefresh(winText);
	while(getch()!=KEY_F(2)){}
	destroy_win(winText);
	destroy_win(deco_w1);
	destroy_win(deco_w2);
}
Ejemplo n.º 11
0
//циклический ввод и отправка сообщений
void MessageType(void)
{
    int ch,x,y,i=0;//,j=1;
    char message[getmaxx(mpanel[2])-1];
    while((ch=wgetch(mpanel[2]))!=KEY_F(5)&&end==0)
    {
        wrefresh(mpanel[2]);
        //обработка enter
        if(ch==10)
        {
            GetMessage(message);
            ClearPanel(2);
            wmove(mpanel[2],1,1);
            i=0;
            ClientSendMsg(message);
        }
        else if(ch==KEY_BACKSPACE)
        {
            getyx(mpanel[2],y,x);
            if(x!=1)
            {
                wmove(mpanel[2],y,x-1);
                wdelch(mpanel[2]);
                box(mpanel[2],0,0);
                wmove(mpanel[2],0,getmaxx(mpanel[2])/2-13);
                wprintw(mpanel[2]," Type your message, %ld ",(long)getpid());
                wmove(mpanel[2],1,getmaxx(mpanel[2])-2);
                wprintw(mpanel[2]," ");
                wmove(mpanel[2],y,x-1);
                i--;
            }
        }
        else
        {
            //не даем печатать за границу
            if(i>=getmaxx(mpanel[2])-2)
            {
                continue;
            }
            wprintw(mpanel[2],"%c",ch);
            i++;
        }
    }
}
Ejemplo n.º 12
0
void HelpEditHook(int Key) {
	pdebug("HelpEditHook()\n");

	char Type;

	Type = 0;
	if (Key < 256) {
		Type = 1;
	} else switch(Key) {
		case KEY_LEFT:
		case KEY_RIGHT:
		case KEY_UP:
		case KEY_DOWN:
		case KEY_HOME:
		case KEY_END:
		case KEY_PPAGE:
		case KEY_NPAGE:
		case KEY_IC:
		case '\t':
		case KEY_BACKSPACE:
		case KEY_ENTER:
		case KEY_F(9): /* XXX */
			Type = 1;
			break;
	}
	if (Type == 1 && !IsNonModal) {
		if (in_help) {
			end_loop_help(Key);
		} else {
			end_loop(Key);
		}

		if (HelpWindow) {
			/* in_help value may be different here ? */
			if (in_help) {
				start_loop_help();
			} else {
				start_loop();
			}
		}
	} else {
		ProcessSpecialKey(Key);
	}
}
Ejemplo n.º 13
0
int main(int argc, char *argv[])
{	int **s_board;
	int n, i, ch;
	tile blank;

	if(argc != 2)
	{	printf("Usage: %s <shuffle board order>\n", argv[0]);
		exit(1);
	}
	n = atoi(argv[1]);
	
	s_board = (int **)calloc(n, sizeof(int *));
	for(i = 0;i < n; ++i)
		s_board[i] = (int *)calloc(n, sizeof(int));
	init_board(s_board, n, &blank);
	initscr();
	keypad(stdscr, TRUE);
	cbreak();
	shuffle_board(s_board, n);
	while((ch = getch()) != KEY_F(1))
	{	switch(ch)
		{	case KEY_LEFT:
				move_blank(RIGHT, s_board, n, &blank);
				break;
			case KEY_RIGHT:
				move_blank(LEFT, s_board, n, &blank);
				break;
			case KEY_UP:
				move_blank(DOWN, s_board, n, &blank);
				break;
			case KEY_DOWN:
				move_blank(UP, s_board, n, &blank);
				break;
		}
		shuffle_board(s_board, n);
		if(check_win(s_board, n, &blank) == TRUE)
		{	mvprintw(24, 0, "You Win !!!\n");
			refresh();
			break;
		}
	}
	endwin();
	return 0;	
}
Ejemplo n.º 14
0
JSBool
ncurses_KEY_F (JSContext* cx, JSObject* object, uintN argc, jsval* argv, jsval* rval)
{
    if (argc < 1) {
        JS_ReportError(cx, "Not enough parameters.");
        return JS_FALSE;
    }

    jsint n; JS_ValueToInt32(cx, argv[0], &n);

    if (n < 0 || n > 63) {
        JS_ReportError(cx, "Out of range.");
        return JS_FALSE;
    }

    *rval = INT_TO_JSVAL(KEY_F(n));

    return JS_TRUE;
}
Ejemplo n.º 15
0
int main(int argc, char *argv[]) {
	WINDOW *my_win;
	int startx, starty, width, height;
	int ch;

	initscr();
	cbreak();

	keypad(stdscr, TRUE);

	height = 3;
	width = 10;
	starty = (LINES - height) / 2;
	startx = (COLS - width) / 2;
	printw("Press F1 to exit");
	refresh();
	my_win = create_newwin(height, width, starty, startx);

	while ((ch = getch()) != KEY_F(1)) {
		switch(ch) {
			case KEY_LEFT:
				destroy_win(my_win);
				my_win = create_newwin(height, width, starty, --startx);
				break;
			case KEY_RIGHT:
				destroy_win(my_win);
				my_win = create_newwin(height, width, starty, ++startx);
				break;
			case KEY_UP:
				destroy_win(my_win);
				my_win = create_newwin(height, width, --starty, startx);
				break;
			case KEY_DOWN:
				destroy_win(my_win);
				my_win = create_newwin(height, width, ++starty, startx);
				break;
		}
	}

	endwin();
	return 0;
}
Ejemplo n.º 16
0
int main(int argc, char *argv[]) {
	int ch;

	initscr();
	atexit(quit);
	clear();
	noecho();
	curs_set(0);
	nl();
	keypad(stdscr, TRUE);

	it = (ITEM **)calloc(5, sizeof(ITEM *));
	it[0] = new_item("M1", "");
	it[1] = new_item("M2", "");
	it[2] = new_item("M3", "");
	it[3] = new_item("Ende", "");
	it[4] = 0;

	me = new_menu(it);
	post_menu(me);

	mvaddstr(7, 3, "Programm mittels Menü oder F2-Funktionstaste beenden");
	refresh();

	while ((ch = getch()) != KEY_F(2)) {
		switch (ch) {
			case KEY_DOWN:
				menu_driver(me, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(me, REQ_UP_ITEM);
				break;
			case 0xA:
				if (item_index(current_item(me)) == 3) {
					exit(0);
				}
				break;
		}
	}

	return 0;
}
Ejemplo n.º 17
0
int main (void) {
    int tab[DIM_JEU][DIM_JEU], key, int_jeu_2048, score=0;
    char continuer='y';
    srand(time(NULL));
    
    init_curses();
    bkgd(COLOR_PAIR(1));
    affiche_menu();    
    key=getch();    
   
    while(key!=ESCAPE)
    {
	if(key == KEY_F(2)) 
	{
	  clear();
	  affiche_menu();
	  InitJeu(tab, &score);
	  do
	  {
	    int_jeu_2048 = jeu_2048(tab, &score);
	    if(int_jeu_2048 == 3)
	    {
		move(4,0);
		printw(" Vous avez atteint l'objectif ! \n");
		printw(" Vous voulez continuer? (y/n) ");
		continuer = SaisieOuiNon();
	    }
	  }
	  while (continuer == 'y' && int_jeu_2048 > 1);
	  
	  if(int_jeu_2048 == 0)
	      printw(" Vouz avez perdu. \n");
	  if(int_jeu_2048 == 1)
	      printw(" Vouz ne pouvez plus retasser. \n");
	}
	key=getch();
    }
    
    endwin();
    
    return 0;
}
Ejemplo n.º 18
0
int print(int *positions, int num_queens)
{	int count;
	int y = 2, x = 2, w = 4, h = 2;
	static int solution = 1;

	mvprintw(0, 0, "Solution No: %d", solution++);
	board(stdscr, y, x, num_queens, num_queens, w, h);
	for(count = 1; count <= num_queens; ++count)
	{	int tempy = y + (count - 1) * h + h / 2;
		int tempx = x + (positions[count] - 1) * w + w / 2;
		mvaddch(tempy, tempx, QUEEN_CHAR);
	}
	refresh();
	mvprintw(LINES - 2, 0, "Press Any Key to See next solution (F1 to Exit)");
	if(getch() == KEY_F(1))
	{	endwin();
		exit(0);
	}
	clear();
}
Ejemplo n.º 19
0
Archivo: tests.c Proyecto: olilea/trim
void
test1(void) {

    int ch;

    printw("Type any character to see it in bold\n\r");
    ch = getch();           /* If raw() hadn't been called we have
                             * to press enter before it gets to the
                             * program                              */
    if (ch == KEY_F(1)) {
        printw("F1 key pressed");
    } else {
        mvprintw(30, 2, "The key pressed is: ");
        attron(A_BOLD);
        printw("%c", ch);
        attroff(A_BOLD);
    }
    refresh();              /* Prints it on the real screen         */
    getch();                /* Wait for user input                  */
}
Ejemplo n.º 20
0
void
buttonbar_set_label (WButtonBar * bb, int idx, const char *text,
                     const struct global_keymap_t *keymap, const Widget * receiver)
{
    if ((bb != NULL) && (idx >= 1) && (idx <= BUTTONBAR_LABELS_NUM))
    {
        unsigned long command = CK_IgnoreKey;

        if (keymap != NULL)
            command = keybind_lookup_keymap_command (keymap, KEY_F (idx));

        if ((text == NULL) || (text[0] == '\0'))
            set_label_text (bb, idx, "");
        else
            set_label_text (bb, idx, text);

        bb->labels[idx - 1].command = command;
        bb->labels[idx - 1].receiver = WIDGET (receiver);
    }
}
Ejemplo n.º 21
0
Archivo: menus.c Proyecto: aspacsa/vlp
void billing_menu(const char *curr_path) {
  int action;
  char * from_date, * to_date;

  from_to_selector(curr_path, &from_date, &to_date, &action);
  if ( action == KEY_F(2) ) { 
    char * msg;
    size_t result = report_basic_summ_bill( from_date, to_date, &msg );
    if ( result )
      mvprintw( 20, 10, "[!] %s", msg );
    else
      mvprintw( 20, 10, "Report '%s'has been created. ", msg );
    mvprintw( 25, 10, "Press any key to continue..." );
    int ch = getch();
    free( from_date );
    free( to_date );
    free( msg );
  }
  return;
}
Ejemplo n.º 22
0
void enable_find(struct NBT_Window* window) {
  move(LINES - 1, 0);
  clrtoeol();
  printw("Search: ");
  refresh();
  int ch = 0;
  char searchbuf[BUFSIZ];
  bzero(searchbuf, sizeof(searchbuf));
  const char* s = searchbuf; /* Begin pointer */
  char* c = searchbuf; /* Current location */
  const char* end = s + sizeof(searchbuf) - 1; /* Max location */
  int found = -1;
  while((ch = getch()) != 27) {
    if (ch == KEY_BACKSPACE || isalnum(ch)) {
      if (ch == KEY_BACKSPACE) {
        *c = '\0';
        if (c != s)
          c--;
      } else {
        if (c < end)
          *c++ = ch;
      }
      move(LINES - 1, 0);
      clrtoeol();
      printw("Search: %s", searchbuf);
      found = search_item(searchbuf, 0, window);
      if (found >= 0)
        set_current_item(window->menu, window->items[found]);
    } else if (KEY_F(3)) {
      found = search_item(searchbuf, found + 1, window);
      if (found >= 0)
        set_current_item(window->menu, window->items[found]);
      else {
        move(LINES - 1, 0);
        clrtoeol();
        printw("Search: %s [No more results]", searchbuf);
      }
    }
    refresh();
  }
};
Ejemplo n.º 23
0
int main () {
	int c;
	char *s;

	initscr ();
	cbreak ();
	noecho ();
	start_color ();
	keypad (stdscr, TRUE);
	curs_set(0);

	if (!has_colors ()) {
		endwin ();
		fputs ("No colors!", stderr); 
		exit (1);
	}

	init_pair (COLOR1, COLOR_RED, COLOR_BLUE);
	init_pair (COLOR2, COLOR_YELLOW, COLOR_BLACK);

	attron (COLOR_PAIR( COLOR1 ));
	mvaddstr (2, 5, "Red on blue.");

	attron (COLOR_PAIR( COLOR2 ));
	mvaddstr (3, 5, "Yellow on black.");

	mvaddstr (LINES-1, COLS-20, "Press F10 for end.");

	while ( (c=getch()) != KEY_F(10)) {
		s = (char *) keyname(c);
		if (s)
			mvprintw (10, 20, "'%s'", s);
		else
			mvprintw (10, 20, "'%c'", (isprint(c) ? c : '.'));
	}

	erase ();
	refresh ();
	endwin ();
	return 0;
}
Ejemplo n.º 24
0
int main()
{	ITEM **my_items;
	int c;				
	MENU *my_menu;
	int n_choices, i;
	ITEM *cur_item;
	
	
	initscr();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);
	
	n_choices = ARRAY_SIZE(choices);
	my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));

	for(i = 0; i < n_choices; ++i)
	        my_items[i] = new_item(choices[i], choices[i]);
	my_items[n_choices] = (ITEM *)NULL;

	my_menu = new_menu((ITEM **)my_items);
	mvprintw(LINES - 2, 0, "F1 to Exit");
	post_menu(my_menu);
	refresh();

	while((c = getch()) != KEY_F(1))
	{   switch(c)
	    {	case KEY_DOWN:
		        menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
		}
	}	

	free_item(my_items[0]);
	free_item(my_items[1]);
	free_menu(my_menu);
	endwin();
}
Ejemplo n.º 25
0
void movep(entity *e){
	int takeinp;
	takeinp = getch();

	switch(takeinp){
		
		case KEY_LEFT:
			mvaddch(e->y, e->x, ' ');
			e->x--;
			break;
		case KEY_RIGHT:
			mvaddch(e->y, e->x, ' ');
			e->x++;
			break;
		case KEY_UP:
			mvaddch(e->y, e->x, ' ');
			e->y--;
			break;
		case KEY_DOWN:
			mvaddch(e->y, e->x, ' ');
			e->y++;
			break;
		case KEY_F(1):
			deinit();
			break;
		case 27:
			deinit();
			break;
			
			
		default:
			break;


	}




}
Ejemplo n.º 26
0
/******************************************************\
 * Description:	Checks if the exit key has been       *
 *		pressed.  If so, it checks if the     *
 *		file has been saved since the last    *
 *		modification.  If it hasn't it prompts*
 *		the user asking if they would like to *
 *		save.				      *
 * Returns:     2 == save, 1 == no save, 0 == cancel  *
\******************************************************/
int quitProgram(int notChanged, short int ch)
{   
    short int str;
							/* if exit key...     */
    if ((ch == KEY_F(8)) || (ch == CTRL_AND('q')) || (ch == CTRL_AND('x')))
    {
        if (!notChanged)				/* if changes made    */
        {
							/* prompt for exit    */
            str = questionWin("Do you want to save changes? (y/n)");

            if (str == 'Y' || str == 'y')		/* if yes, save       */
                return 2;
            else if ((str != 'N') && (str != 'n'))	/* don't quit, cancel */
                return 0;
        }

        return 1;					/* quit, don't save   */
    }
    else 
        return 0;					/* don't quit         */
}
Ejemplo n.º 27
0
bool CFileDialog::CoreHandleKey(chtype key)
{
    if (CDialog::CoreHandleKey(key))
        return true;
    
    if (key == KEY_F(2))
    {
        std::string newdir = InputBox(GetTranslation("Enter name of new directory"), "", 1024);
        
        if (newdir.empty())
            return true;
        
        if (newdir[0] != '/')
            newdir = m_Directory + '/' + newdir;
        
        try
        {
            if (MKDirNeedsRoot(newdir))
            {
                LIBSU::CLibSU suhandler;
                std::string passwd = AskPassword(suhandler);
                MKDirRecRoot(newdir, suhandler, passwd.c_str());
                passwd.assign(passwd.length(), 0);
            }
            else
                MKDirRec(newdir);
            
            OpenDir(newdir);
        }
        catch(Exceptions::CExIO &e)
        {
            WarningBox(e.what());
        }
            
        return true;
    }
    
    return false;
}
Ejemplo n.º 28
0
/* label <number> <command> <label> */
static gboolean
cmd_label(config_t *cfg, int argc, char *argv[])
{
    const name_map_t *cmd = command_names;
    const char *command, *label;
    int fn;

    if (argc != 4) {
	snprintf(error_msg, sizeof(error_msg),
		 _("%s: Syntax: %s <n> <command> <label>"), 
		argv[0], argv[0]);
	return FALSE;
    }
    
    fn	= strtol(argv[1], NULL, 0);
    command = argv[2];
    label = argv[3];

    while (cmd->name && strcasecmp(cmd->name, command) != 0)
	cmd++;

    if (!cmd->name) {
	snprintf(error_msg, sizeof(error_msg),
		 _("%s: Unknown command: `%s'"), argv[0], command);
	return FALSE;
    }
    
    if (fn < 1 || fn > 10) {
	snprintf(error_msg, sizeof(error_msg),
		 _("%s: fn should be 1-10"), argv[0]);
	return FALSE;
    }

    keymap_add(cfg->keymap, KEY_F(fn), cmd->val);
    cfg->labels[fn - 1] = g_strdup(label);

    return TRUE;
}
Ejemplo n.º 29
0
/* general key define table */
xtra_key_define_t xtra_key_defines[] = {
#if FORCE_BASE_KEY_DEFS
    {KEY_BACKSPACE, Key_backspace},
    {KEY_LEFT, Key_left},
    {KEY_RIGHT, Key_right},
    {KEY_UP, Key_up},
    {KEY_DOWN, Key_down},
    {KEY_NPAGE, Key_npage},
    {KEY_PPAGE, Key_ppage},
    {KEY_HOME, Key_home},
    {KEY_END, Key_end},
    {KEY_DC, Key_dc},
    {KEY_IC, Key_ic},
    {KEY_F (1), Key_f1},
    {KEY_F (2), Key_f2},
    {KEY_F (3), Key_f3},
    {KEY_F (4), Key_f4},
    {KEY_F (5), Key_f5},
    {KEY_F (6), Key_f6},
    {KEY_F (7), Key_f7},
    {KEY_F (8), Key_f8},
    {KEY_F (9), Key_f9},
    {KEY_F (10), Key_f10},
    {KEY_F (11), Key_f11},
    {KEY_F (12), Key_f12},
    {KEY_F (13), Key_f13},
    {KEY_F (14), Key_f14},
    {KEY_F (15), Key_f15},
    {KEY_F (16), Key_f16},
Ejemplo n.º 30
0
int worldfactory::show_worldgen_tab_confirm(WINDOW *win, WORLDPTR world)
{
    const int iTooltipHeight = 1;
    const int iContentHeight = FULL_SCREEN_HEIGHT - 3 - iTooltipHeight;

    const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0;
    const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0;

    const char* line_of_32_underscores = "________________________________";

    WINDOW *w_confirmation = newwin(iContentHeight, FULL_SCREEN_WIDTH - 2,
                                    iTooltipHeight + 2 + iOffsetY, 1 + iOffsetX);
    WINDOW_PTR w_confirmationptr( w_confirmation );

    unsigned namebar_y = 1;
    unsigned namebar_x = 3 + utf8_width(_("World Name:"));

    int line = 1;
    bool noname = false;
    input_context ctxt("WORLDGEN_CONFIRM_DIALOG");
    ctxt.register_action("HELP_KEYBINDINGS");
    ctxt.register_action("QUIT");
    ctxt.register_action("ANY_INPUT");
    ctxt.register_action("NEXT_TAB");
    ctxt.register_action("PREV_TAB");
    ctxt.register_action("PICK_RANDOM_WORLDNAME");

    std::string worldname = world->world_name;
    do {
        mvwprintz(w_confirmation, namebar_y, 2, c_white, _("World Name:"));
        mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, line_of_32_underscores);
        fold_and_print(w_confirmation, 3, 2, 76, c_ltgray,
                       _("Press <color_yellow>%s</color> to pick a random name for your world."), ctxt.get_desc("PICK_RANDOM_WORLDNAME").c_str());
        fold_and_print(w_confirmation, FULL_SCREEN_HEIGHT / 2 - 2, 2, 76, c_ltgray, _("\
Press <color_yellow>%s</color> when you are satisfied with the world as it is and are ready \
to continue, or <color_yellow>%s</color> to go back and review your world."), ctxt.get_desc("NEXT_TAB").c_str(), ctxt.get_desc("PREV_TAB").c_str());
        if (!noname) {
            mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, "%s", worldname.c_str());
            if (line == 1) {
                wprintz(w_confirmation, h_ltgray, "_");
            }
        }
        if (noname) {
            mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, line_of_32_underscores);
            noname = false;
        }

        wrefresh(win);
        wrefresh(w_confirmation);
        refresh();

        const std::string action = ctxt.handle_input();
        if (action == "NEXT_TAB") {
#ifndef LUA
            MOD_INFORMATION *temp = NULL;
            for (std::string &mod : world->active_mod_order) {
                temp = mman->mod_map[mod];
                if ( temp->need_lua ) {
                    popup(_("Mod '%s' requires Lua support."), temp->name.c_str());
                    return -2; // Move back to modselect tab.
                }
            }
#endif
            if (worldname.empty()) {
                mvwprintz(w_confirmation, namebar_y, namebar_x, h_ltgray, _("_______NO NAME ENTERED!!!!______"));
                noname = true;
                wrefresh(w_confirmation);
                if (!query_yn(_("Are you SURE you're finished? World name will be randomly generated."))) {
                    continue;
                } else {
                    world->world_name = pick_random_name();
                    if (!valid_worldname(world->world_name)) {
                        continue;
                    }
                    return 1;
                }
            } else if (query_yn(_("Are you SURE you're finished?")) && valid_worldname(worldname)) {
                world->world_name = worldname;
                return 1;
            } else {
                continue;
            }
        } else if (action == "PREV_TAB") {
            world->world_name = worldname;
            return -1;
        } else if (action == "PICK_RANDOM_WORLDNAME") {
            mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, line_of_32_underscores);
            world->world_name = worldname = pick_random_name();
        } else if (action == "QUIT") {
            // Cache the current name just in case they say No to the exit query.
            world->world_name = worldname;
            return -999;
        } else if (action == "ANY_INPUT") {
            const input_event ev = ctxt.get_raw_input();
            const long ch = ev.get_first_input();
            switch (line) {
            case 1: {
                utf8_wrapper wrap(worldname);
                utf8_wrapper newtext( ev.text );
                if( ch == KEY_BACKSPACE ) {
                    if (!wrap.empty()) {
                        wrap.erase(wrap.length() - 1, 1);
                        worldname = wrap.str();
                    }
                } else if(ch == KEY_F(2)) {
                    std::string tmp = get_input_string_from_file();
                    int tmplen = utf8_width( tmp );
                    if(tmplen > 0 && tmplen + utf8_width(worldname) < 30) {
                        worldname.append(tmp);
                    }
                } else if( !newtext.empty() && is_char_allowed( newtext.at( 0 ) ) ) {
                    // No empty string, no slash, no backslash, no control sequence
                    wrap.append( newtext );
                    worldname = wrap.str();
                }
                mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, line_of_32_underscores);
                mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, "%s", worldname.c_str());
                wprintz(w_confirmation, h_ltgray, "_");
            }
            break;
            }
        }
    } while (true);

    return 0;
}