Esempio n. 1
0
void delete_cowboy(int side)
{
   int i;

   assert(side == RIGHT || side == LEFT);

   for ( i = 0; i < COWBOY_HEIGHT; i++ ) {
      move(cowboys[side].y+i, cowboys[side].x);
      delch(); delch(); delch(); delch();
      insch(' '); insch(' '); insch(' '); insch(' ');
   }

   refresh();
}
Esempio n. 2
0
void moveBlockToRight(int row, int *start, int *end, int screen_width) {
    if(*end >= screen_width) return;
    SET_COLOR_WHITE;
    move(row, *start);
    delch();
    insch(' ');
    (*start)++;

    SET_COLOR_RED;
    move(row, *end);
    delch();
    insch(' ');
    (*end)++;
    return;
}
Esempio n. 3
0
void backspace()
{   
  getyx(mywin, r, c);
  move(r, c-1);   
  delch();   
  refresh();       
}     
Esempio n. 4
0
void moveBlockToLeft(int row, int *start, int *end) {
    if(*start < 1) return;
    SET_COLOR_RED;
    (*start)--;
    move(row, *start);
    delch();
    insch(' ');

    SET_COLOR_WHITE;
    move(row, *end);
    delch();
    insch(' ');
    (*end)--;
    move(row, *end);
    return;
}
Esempio n. 5
0
void Field::backs(int c)
  {
  if(cursor)
    {
    --cursor;
    delch(0);
    redraw();
    }
  }
Esempio n. 6
0
void backspace()
{
  noraw();
  move(cursor_row,cursor_col-1);
  delch();
  raw();
  refresh();
  getsyx(cursor_row,cursor_col);
}
Esempio n. 7
0
void delete_bomb(Block *bomb) {
    int index;
    SET_COLOR_WHITE;
    for(index = 2; index < bomb->screen_height - 1; ++index) {
        move(index, bomb->col);
        delch();
        insch(' ');
    }
}
Esempio n. 8
0
char * getPassphraseNcurses() {
    size_t size = PASSPHRASE_SIZE_INCS;
    char *ph = attemptSecureAlloc(size), *tmp;
    int written = 0, x, y;
    int ch;

    initscr();
    raw(); // Turn off buffering
    noecho(); // Turn off echoing
    keypad(stdscr, TRUE);
    clear();

    mvprintw(0, 0, "Enter decryption key: ");
    move(1, 0);
    curs_set(2);
    refresh();
    while (ch = getch()) {
        if (written >= PASSPHRASE_SIZE_INCS) {
            tmp = gcry_realloc(ph, size + PASSPHRASE_SIZE_INCS);
            if (tmp != NULL) {
                ph = tmp; written = 0;
            }
            else {
                getyx(stdscr, y, x);
                mvprintw(y + 1, 0, "Not enough memory for a longer passphrase.");
                move(y, x);
                refresh();
            }
        }

        if ((ch == KEY_BACKSPACE) || (ch == KEY_DC)) {
            if (written > 0) {
                --written;
                getyx(stdscr, y, x);
                move(y, x - 1);
                delch();
                refresh();
            }
            continue;
        }

        if (ch == '\n') {
            ph[written++] = '\0';
            break;
        }
        else {
            ph[written++] = ch;
            addch('*' | A_BOLD); refresh();
        }
    }
    clear();
    endwin();

    return ph;
}
Esempio n. 9
0
void draw(char dc)
{
  move(r, c);
  delch();
  insch(dc);
  refresh();
  r++;
  if (r == nrows) {
    r = 0;
    c++;
    if (c == ncols) c = 0;
  }
}
Esempio n. 10
0
void move_bullets()
{
  int i, side;

  for ( i = 0; i < maxbalas; i++ ) {
    for ( side = LEFT; side <= RIGHT; side++ ) {
      if ( !bullets[side][i].empty ) {
        move(bullets[side][i].y, bullets[side][i].x);
        delch();
        insch(' ');
        if ( side == LEFT ) {
          bullets[side][i].x++;
          if ( bullets[side][i].x >= NCOLS ) {
            bullets[side][i].empty = 1;
          }
          else {
            move(bullets[side][i].y, bullets[side][i].x);
            delch();
            insch('>');
          }
        }
        else {
          bullets[side][i].x--;
          if ( bullets[side][i].x < 0 ) {
            bullets[side][i].empty = 1;
          }
          else {
            move(bullets[side][i].y, bullets[side][i].x);
            delch();
            insch('<');
          }
        }
      }
    }
  }

  refresh();
}
Esempio n. 11
0
/*  Handle the keyboard input  */ 
void keyhandler() 
{ 
  
  getyx(mywin, r, c);
  /*  Handle input here */    
  ch = getch();   
  if (ch == KEY_BACKSPACE)    backspace();  
  else if (ch == KEY_DC)      delch(); 
  else if (ch == KEY_LEFT)    left(); 
  else if (ch == KEY_RIGHT)   right(); 
  else if (ch == KEY_UP)      up();
  else if (ch == KEY_DOWN)    down();     
  else if (ch == KEY_IC)      insert();      
  else put(ch); 
                        
}     
Esempio n. 12
0
void *create_bomb(void *arg) {
    Block *bomb;
    bomb = (Block *) arg;
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
    pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
    pthread_mutex_lock(&mutex);
    addThread(pthread_self());
    pthread_mutex_unlock(&mutex);
    while(bomb->row <= bomb->screen_height) {
        if(bomb->row == bomb->screen_height - 1) {
            pthread_mutex_lock(&mutex);
            if(bomb->col >= bomb->block->start && bomb->col <= bomb->block->end) {
                increaseScore();
                displayScore();
            } else {
                flash();
                decreaseScore(score);
                displayScore();
            }
            delete_bomb(bomb);
            pthread_mutex_unlock(&mutex);
            break;
        }
        pthread_mutex_lock(&mutex);
        SET_COLOR_BLUE;
        move(bomb->row, bomb->col);
        delch();
        insch(' ');
        (bomb->row)++;
        SET_COLOR_RED;
        pthread_mutex_unlock(&mutex);
        refresh();
        pthread_testcancel();
        napms(150);
    }

    pthread_mutex_lock(&mutex);
    bomb->cols[bomb->col] = 0;
    removeThread(pthread_self());
    pthread_mutex_unlock(&mutex);

    free(bomb);
    pthread_exit((void *) 0);
}
Esempio n. 13
0
/*****************************************************
 * Draws whole screen based on (*chip8).screen array *
 * ***************************************************/
int draw(chip8* myChip8)
{
	int x;
	int y;

	// loop through every x,y postion
	for(y = 0; y < 32; y++){
		for(x = 0; x < 64; x++){
			move(y, x); // move the cursor to position x, y
			delch(); // delect the character currently in this postion
			if((*myChip8).screen[x][y] == 1) // if pixel is set
				insch('#'); // draw a pixel
			else
				insch('-'); // draw a blank
		}	
	}
	move(33, 0);

	refresh(); // after the new screen is drawn, refresh the terminal so it show the changes
	return 1;
}
Esempio n. 14
0
void tf_backspace(TxtField *tf)
{
    // Don't want this function running if there is no input.
    if (tf == NULL || tf->length < 1)
        return;

    // The index in the message buffer to perform deletion.
    unsigned delete_at = (TF_CURSOR_POS - 1) + ECHO_OFFSET;

    for (size_t i = delete_at; i < tf->length; ++i)
        tf->value[i] = tf->value[i + 1];

    moveby(0, -1);
    delch();
    --tf->length;

    if (get_cursor(X) <= tf->x)
        tf_reset_echo(tf);
        /* Remember: This can cause prompt to be removed by tf_backspace if cursor offset is not 0.
         * Will fix after fixing the issue with inserting text in the middle of the message. */
}
Esempio n. 15
0
File: IoCurses.c Progetto: Akiyah/io
IoObject *IoCurses_delete(IoCurses *self, IoObject *locals, IoMessage *m)
{
	/*doc Curses delete(n)
	Deletes n characters at the current position. Text to the right is shifted left. 
	n is optional and defaults to 1. Returns self.
	*/

	int n = 1;

	if (IoMessage_argCount(m) > 0)
	{
		n = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 0));
	}

	for (n = n; n > 0; n--)
	{
		if (delch() == ERR)
		{
			IoCurses_showError(self, m, "Curses.delete", "Failed to delete string.");
		}
	}
	return self;
}
int
window_new_identity_run_command (int c)
{
  int y, x;

  getmaxyx (stdscr, y, x);

  if (gui_window_new_identity.x1 == -999)
    {
  } else
    x = gui_window_new_identity.x1;

  switch (c)
    {
      case KEY_DC:
        delch ();
        break;
      case KEY_BACKSPACE:
      case 127:
        if (active_gui->xcursor > 10)
          {
            int xcur, ycur;

            active_gui->xcursor--;
            getyx (stdscr, ycur, xcur);
            move (ycur, xcur - 1);
            delch ();
          }
        break;
      case '\n':
      case '\r':
      case KEY_ENTER:
      case KEY_DOWN:
        if (gui_window_new_identity.ycursor < 3)
          {
            gui_window_new_identity.ycursor++;
            gui_window_new_identity.xcursor = 10;
          }
        break;
      case KEY_UP:
        if (gui_window_new_identity.ycursor > 0)
          {
            gui_window_new_identity.ycursor--;
            gui_window_new_identity.xcursor = 10;
          }
        break;
      case KEY_RIGHT:
        if (gui_window_new_identity.xcursor < (x - gui_window_new_identity.x0 - 1))
          gui_window_new_identity.xcursor++;
        break;
      case KEY_LEFT:
        if (gui_window_new_identity.xcursor > 0)
          gui_window_new_identity.xcursor--;
        break;

        /* case 20: *//* Ctrl-T */
      case 1:                  /* Ctrl-A */
        {
          int ycur = gui_window_new_identity.y0;
          int xcur = gui_window_new_identity.x0 + 10;
          char sipurl[200];
          char telurl[200];
          char email[200];
          char phone[200];

          mvinnstr (ycur, xcur, sipurl, x - gui_window_new_identity.x0 - 10);
          ycur++;
          mvinnstr (ycur, xcur, telurl, x - gui_window_new_identity.x0 - 10);
          ycur++;
          mvinnstr (ycur, xcur, email, x - gui_window_new_identity.x0 - 10);
          ycur++;
          mvinnstr (ycur, xcur, phone, x - gui_window_new_identity.x0 - 10);

          _josua_add_contact (sipurl, telurl, email, phone);
          /* mvinnstr(ycur, xcur, tmp, 199); */
        }
        break;
      case 4:                  /* Ctrl-D */
        {
          char buf[200];

          attrset (COLOR_PAIR (0));
          snprintf (buf, 199, "%199.199s", " ");
          mvaddnstr (gui_window_new_identity.y0 +
                     gui_window_new_identity.ycursor,
                     gui_window_new_identity.x0 + 10, buf,
                     x - gui_window_new_identity.x0 - 10 - 1);
          gui_window_new_identity.xcursor = 10;
        }
        break;
      case 5:                  /* Ctrl-E */
        gui_window_new_identity.xcursor = 10;
        gui_window_new_identity.ycursor = 0;
        window_new_identity_print ();
        break;
      default:
        /*
           fprintf(stderr, "c=%i", c);
           exit(0);
         */
        if (gui_window_new_identity.xcursor < (x - gui_window_new_identity.x0 - 1))
          {
            gui_window_new_identity.xcursor++;
            attrset (COLOR_PAIR (0));
            echochar (c);
        } else
          beep ();
        return -1;
    }

  return 0;
}
Esempio n. 17
0
/* TODO: all length calculations of the string must be rebuilt.
 *
 * BUG:
 *          Når jeg står på slutten av linjen så blir cursor pos
 *          justert mot venstre selv om jeg ikke sletter noe.
 *
 * */
void
prompt_str(int row, int col, const char *promptstr, wchar_t * answer)
{
	wchar_t *line = answer;

	int len, col0;

	/* struct sgttyb _tty ; */
	register int code, i, j;

	/* Converts  the promptstr to a  wide version.              */
	wchar_t *wpromptstr = mbstowcs_alloc(promptstr);

	if (wpromptstr == NULL) {
        yerror( YMBS_WCS_ERR,"prompt_str->mbstowcs_alloc", "wpromptstr", YX_EXTERNAL_CAUSE ) ;
    }

	wchar_t ch;

	/* Print the wide prompt at (row,col).                          */
	mvaddwstr(row, col, wpromptstr);

	refresh();

	/* Calc "column zero", which is at right end of prompt.     */
	col += wcslen(wpromptstr);
	col0 = col;
	mvaddwstr(row, col, answer);
    len = wcslen(answer) ;
    col += len ; 
	/* Read chars till we get what we want. Useris allowed      */
	/* basic EMACS-style line editing.                          */
	while ((code = get_wch(&ch)) != EOF) {
		switch (ch) {
		case CTRL('a'):	/* beginning of line            */
			col = col0;
			break;
		case KEY_LEFT:
		case CTRL('b'):	/* back character               */
			if (col > col0)
				col--;
			break;
		case CTRL('d'):	/* delete character             */
			/*
			 * If there's stuff in the string,
			 * delete this character.
			 */
			if (col == (col0 + (int)wcslen(line))) {
				col--;
			} else if (len) {
				/* Calc string pos of char to delete.           */
				i = col - col0;

				/* Shuffle the string "left" one place.         */
				while (i < len) {
					line[i] = line[i + 1];
					i++;
				}

				/* Delete char on the screen.                   */
				len -= 1;
				delch();	/* prob ok that isn't wide. */
                if (col== (col0 + (int)wcslen(line)) ) {
                    --col ;
                }
			}

			break;
		case CTRL('e'):	/* end of line                  */
			col = col0 + len;
			break;
		case KEY_RIGHT:
		case CTRL('f'):	/* forward character            */
			if ((col - col0) < len)
				col++;
			break;
		case KEY_BACKSPACE:
		case CTRL('h'):	/* backspace delete */
		case '\177':
			/* If stuff in the string, delete char.             */
			if (len && ((col - 1) >= col0)) {
				/* Calc pos in string of char to delete         */
				int l = col - col0 - 1;
				if (l < 0)
					break;
				/* Shuffle the string "left" one place.         */
				while (l < len) {
					line[l] = line[l + 1];
					l++;
				}

				len -= 1;
				/* Delete the character on the screen.          */
				move(row, --col);
				delch();
			}
			break;
		case CTRL('k'):	/* kill line                    */
			/* Clear the string.                                */
			if (len) {
				i = col - col0;

				line[i] = '\0';
				len = i;

				clrtoeol();
			}
			break;
		case CTRL('l'):	/* redraw screen                */
			wrefresh(curscr);
			break;
		case KEY_ENTER:
		case '\r':	/* return the string            */
		case '\n':	/* return the string            */
			line[len] = '\0';
			return;
		default:	/* regular character            */
			if (ch == KEY_DL) {
				move(row, col0);
				clrtoeol();
				col = col0;

				*line = '\0';
				len = 0;
			} else if (code != KEY_CODE_YES) {
				if (iswctype(ch, wctype("print"))) {
					if (col == (COLS - 1)) {
						beep();
						break;
					}
					/* Calculate position of char in string.    */
					i = col - col0;

					/* If we have to, move string "right" one   */
					/* place to insert the character.           */
					if (i < len) {
						for (j = len; j >= i; j--)
							line[j + 1] = line[j];
					}
					line[i] = ch;
					len += 1;
					col++;

					/* Insert the character on the screen.      */
					InsWch((chtype) ch);
					/* ins_wch(&ch); */
				}
			}
			break;
		}

		/* Move the cursor.                                     */
		move(row, col);
		refresh();
	}
}
std::string namePreset() {
    int         row, col, mincol, ch;
    int         sh = 65;
    int         nums = 0;

    printw("Use the number pad arrows to enter a name.\n\n");
    printw("'8' / '2' == 'UP' / 'DOWN'\t|\t'6' / '4' == NEXT / PREVIOUS ENTRY\n\n");
    printw("Enter a name for the preset: ");

    getyx(stdscr,row,col);  // get cursor loc
    mincol = col;           // initialize far left
    mvaddch(row,col,sh);    // print letter
    move(row,col);          // keep cursor there
    refresh();
    while ( ( ch = getch() ) != (char)'\n' ) {
        switch (ch) {
        case UP:
            sh++;
            mvaddch(row,col,sh);
            break;
        case DOWN:
            sh--;
            mvaddch(row,col,sh);
            break;
        case RIGHT:
            col++;
            sh = 65;
            mvaddch(row,col,sh);
            break;
        case LEFT:
            if ( col == mincol ) {
                break;
            }
            col--;
            delch();
            break;

        }
        // Don't allow cursor beyond mincol
        if ( col < mincol ) {
            col = mincol;
        }
        // Check for Num->Letter wrapping
        if ( ( sh < 65 ) && !nums ) {
            nums = 1;
            sh = 57;
            mvaddch(row,col,sh);
        } else if ( ( sh < 48 ) && nums ) {
            nums = 0;
            sh = 90;
            mvaddch(row,col,sh);
        } else if ( sh > 90 ) {
            sh = 48;
            nums = 1;
            mvaddch(row,col,sh);
        } else if ( ( sh > 57 ) && ( sh < 65 ) ) {
            sh = 65;
            nums = 0;
            mvaddch(row,col,sh);
        }
        // Refresh with cursor in correct
        move(row,col);
        refresh();

    }

    move(row,mincol);

    char            *str = (char*) malloc(sizeof(char)*50);
    int             i = 0;
    int             k = 0;
    instr(str);                 // get char array
    while ( str[i] != ' ' ) i++;

    char            *newstr = (char*) malloc(sizeof(char)*50);

    while ( k <= i ) {
        newstr[k] = str[k];
        k++;
    }
    newstr[k-1] = '\0';
    std::string name(newstr);    // create string
    name += ".txt";         // conc .txt

    return name;
}
Esempio n. 19
0
int window_new_identity_run_command(gui_t* gui, int c)
{
    ogmp_curses_t* ocui = gui->topui;

    int max = 5;

    switch (c)
    {
    case KEY_DC:
    {
        editline_remove_char(newid_edit[cursor_newid]);

        delch();

        break;
    }
    case '\b':
    {
        if (editline_move_pos(newid_edit[cursor_newid], -1) >= 0)
            editline_remove_char(newid_edit[cursor_newid]);
        else
            beep();

        break;
    }
    case '\n':
    case '\r':
    case KEY_ENTER:
    case KEY_DOWN:
    {
        cursor_newid++;
        cursor_newid %= max;

        break;
    }
    case KEY_UP:
    {
        cursor_newid += max-1;
        cursor_newid %= max;

        break;
    }
    case KEY_RIGHT:
    {
        if (editline_move_pos(newid_edit[cursor_newid], 1) < 0)
            beep();

        break;
    }
    case KEY_LEFT:
    {
        if (editline_move_pos(newid_edit[cursor_newid], -1) < 0)
            beep();

        break;
    }
    case 1:  /* Ctrl-A */
    {
        int sec = 0;

        if(newid_regsec[0])
            sec = strtol(newid_regsec, NULL, 10);

        if(sec <= 0)
            break;

        if(newid_fullname[0] && newid_registary[0] && newid_regname[0])
        {
            if(!ocui->edit_profile)
                user_add_profile(ocui->user, newid_fullname, strlen(newid_fullname),
                                 newid_bookloc, newid_registary, newid_regname, sec);
            else
                user_set_profile(ocui->user, ocui->edit_profile, newid_fullname, strlen(newid_fullname),
                                 newid_bookloc, newid_registary, newid_regname, sec);

            gui_hide_window(gui);
        }

        break;
    }
    case 3:  /* Ctrl-C */
    {
        gui_hide_window(gui);

        break;
    }
    case 4:  /* Ctrl-D */
    {
        editline_clear(newid_edit[cursor_newid]);

        break;
    }
    default:
    {
        if(editline_append(newid_edit[cursor_newid], (char*)&c, 1) == 0)
        {
            beep();

            return -1;
        }
    }
    }

    gui_update(gui);

    return 0;
}
Esempio n. 20
0
int modifica_janela(char **campos, int side, int codigo)
{
   int i;

   switch(codigo)
   {
      case NSH:

         if(strcmp(campos[1],"P2")==0)
            side=RIGHT;
         if(strcmp(campos[1],"P1")==0)
            side=LEFT;

         /**SE SYNC - TEM QUE ACTIVAR THREAD PARA ACTUALIZAR BALAS**/
         for ( i = 0; i < maxbalas; i++ )
         {
            if ( bullets[side][i].empty )
            {
               break;
            }
         }

         if ( i < maxbalas )
         {
            bullets[side][i].empty = FALSE;
            bullets[side][i].y = cowboys[side].y + 2;
/***BLOQUEAR*/
            cowboys[side].bulletsleft--;

            if ( side == LEFT )
            {
               bullets[side][i].x = cowboys[side].x+4;
               move(bullets[side][i].y, bullets[side][i].x);
               delch();
               insch('>');
            }
            else
            {
               bullets[side][i].x = cowboys[side].x-1;
               move(bullets[side][i].y, bullets[side][i].x);
               delch();
               insch('<');
            }
            refresh();
         }

         return FALSE;

      break;


      case REL:
/****BLOQUEAR***/
         cowboys[LEFT].bulletsleft=maxbalas;
         cowboys[RIGHT].bulletsleft=maxbalas;
         free(campos[0]);
         return FALSE;

      break;


      case BLT:
         /**Move as balas*/
         if(!check_dead(LEFT) && !check_dead(RIGHT))
         {
            for ( i = 0; i < maxbalas; i++ ) {
               if ( bullets[side][i].empty )
               {
                  break;
               }
            }

            if(i<maxbalas+1) move_bullets();
         }

         free(campos[0]);
         return FALSE;

      break;

      case MOV:
         if(strcmp(campos[1],"P1")==0)
            side = LEFT;
         else
            side = RIGHT;

         delete_cowboy(side);

         cowboys[side].y = atoi(campos[2]);

         draw_cowboy(side);
         return FALSE;
         break;

      case EOG:

         clear();

         if(strcmp(campos[1],"P1")==0)
         {
            mvwprintw(wnd, NROWS/2, NCOLS/2-(strlen("VENCEDOR DA PARTIDA: ")+strlen(cowboys[LEFT].name))/2, "Vencedor da partida: %s",cowboys[LEFT].name);
            cowboys[LEFT].games=atoi(campos[2]);
         }
         else if(strcmp(campos[1],"P2")==0)
         {
            mvwprintw(wnd, NROWS/2, NCOLS/2-(strlen("VENCEDOR DA PARTIDA: ")+strlen(cowboys[RIGHT].name))/2, "Vencedor da partida: %s",cowboys[RIGHT].name);
            cowboys[RIGHT].games=atoi(campos[2]);
         }
         else
         {
            mvwprintw(wnd, NROWS/2-4, NCOLS/2-(strlen("VENCEDOR DA PARTIDA: JOGADOR EMPATE"))/2, "Vencedor da partida: Empate");
         }
         wtimeout(wnd,-1);

         mvwprintw(wnd, 0, 0, "High Noon - Projecto de Programacao de Sistemas");
         /**Colocar numero da partida?*/

         mvwprintw(wnd, 1, 0, "Fim da Partida Numero: %d",cowboys[RIGHT].games+cowboys[LEFT].games);

         mvwprintw(wnd, NROWS-1, 0, "Pressione uma tecla qualquer para começar um novo jogo\n");

         refresh();

         getch();

         clear();

         refresh();
         /**Recebe novamente tudo*/

         close_HN_window();

         /*delwin(wnd);*/

         boas_vindas(side,FALSE);

         com_partida(side);

         clear();

         refresh();

         draw_cowboy(LEFT);
         draw_cowboy(RIGHT);
         return FALSE;
         break;

      case EXT:
         if(strcmp(campos[1],"P1")==0)
            side = LEFT;
         else
            side = RIGHT;

         cowboys[side].games=atoi(campos[2]);

         cowboys[!side].games=atoi(campos[3]);

         return TRUE;
         break;

      case ERR:
         break;

      default:
         close_HN_window();
         printf("ERRO: Mensagem nao reconhecida!\n");
         exit(EXIT_FAILURE);
      break;

   }
   return FALSE;
}
Esempio n. 21
0
void delchar() 
{    
   delch();   
   refresh();             
}     
Esempio n. 22
0
void draw_cowboy(int side)
{
   assert(side == RIGHT || side == LEFT);

   move(cowboys[side].y, cowboys[side].x+side);
   delch(); delch(); delch();
   insch('_'); insch('M'); insch('_');

   move(cowboys[side].y+1, cowboys[side].x+side+1);
   delch();
   insch('|');

   move(cowboys[side].y+2, cowboys[side].x+side);
   delch(); delch(); delch();
   insch('-'); insch('O'); insch('-');

   move(cowboys[side].y+3, cowboys[side].x+side+1);
   delch();
   insch('|');

   move(cowboys[side].y+4, cowboys[side].x+side);
   delch(); delch(); delch();
   insch('\\'); insch(' '); insch('/');

   if ( side == LEFT ) {
      move(cowboys[side].y+2, cowboys[side].x+3);
      delch();
      insch('>');
   }
   else {
      move(cowboys[side].y+2, cowboys[side].x);
      delch();
      insch('<');
   }

   refresh();
}
Esempio n. 23
0
/*
 * Delete the character at the current position
 */
void
screen_delete_char(void)
{
    delch();
}
Esempio n. 24
0
void commandMode(char* author, char* title, char* filename, int row, int col, char** array){
    //initialise the ncurses
    (void) initscr();
    (void) nonl();
    (void) cbreak();

    // display curses at the bottom screen for command mode
    int h = 0;
    int w = 0;
    getmaxyx(stdscr, h, w); 
    //move curses to the bottom of the screen
    move(h-1, 0); 
    clrtoeol();

    char buffer[20];
    char *keySearch = " ";
    char* token1 = NULL;
    char* token2 = NULL;
    char* token3 = "0";
    char* token4 = "0";
    
    //reset string buffer
    for (int i =0; i<20;i++){
        buffer[i] = ' ';
    }
    
    addch(':');//add : as default 
    for(;;){
        int ch = getch();
        if(ch == ERR){
            

        }else if(ch == 13){
            if(buffer != NULL){
                char *cstr = strdup(buffer); //clone the buffer 
                token1 = strtok(cstr, keySearch);   //cut it
                token2 = strtok(NULL, keySearch);
                token3 = strtok(NULL, keySearch);
                token4 = strtok(NULL, keySearch);
                
                if(strcmp(token1, "q") == 0){
                    //exit
                    for (int i = 0; i < 20;i++){
                        buffer[i] = ' ';
                    }
                    //free(cstr);
                    clear();
                    refresh();
                    endwin();
                    exit(EXIT_SUCCESS);
                    //system("clear");
                    break;
                } else if ((strcmp(token1, "w") == 0) && ((strcmp(token2, "q") == 0) || (strcmp(token2, "P") == 0))){
                    //write level to current file
                    writeToFile(author, title, filename, row, col, array);
                    
                    move(h - 1, 0);
                    clrtoeol();
                    printw("Saved");
                    move(0,0);
                    break;
                } else if ((strcmp(token1, "w") == 0)  && (token2 != NULL)){
                    //write level to current file with specific name
                    writeToFile(author, title, token2, row, col, array);
                    
                    move(h - 1, 0);
                    clrtoeol();
                    printw("Saved to %s.pac", token2);
                    move(0,0);
                    break;
                } else if(strcmp(token1, "wq") == 0 && ((strcmp(token2, "q") == 0) || (strcmp(token2, "P") == 0))){
                    //write then quit
                    writeToFile(author, title, filename, row, col, array);
                    //free(cstr);
                    clear();
                    refresh();
                    endwin();
                    exit(EXIT_SUCCESS);
                    
                } else if(strcmp(token1, "wq") == 0 && token2 != NULL){
                    //write to specific file then quit;
                    writeToFile(author, title, token2, row, col, array);
                    
                    //free(cstr);
                    clear();
                    refresh();
                    endwin();
                    exit(EXIT_SUCCESS);
                } else if(strcmp(token1, "r") == 0 && token2 != NULL){
                    //read file name
                    filename = token2;
                    array = readFromFile(author, title, filename, &row, &col, array);
                    clear();
                    refresh();
                    drawMap(author, title, filename, row, col, array);
                } else if(strcmp(token1, "n") == 0 && token2 != NULL && token3 != NULL && token4 != NULL && isdigit(*token3) && isdigit(*token4)){
                    //create new map with specific row and collumn
                    int inputRow = atoi(token3);
                        //int *inputRowPt = &inputRow;
                    int inputCol = atoi(token4);
                        //int *inputColPt = &inputCol;
                    //initialize new array for writing
                    char** newArray;
                    newArray = malloc(inputCol*sizeof(char*));  
                    for (int i = 0; i < inputRow; i++) {
                        newArray[i] = malloc(inputRow*sizeof(char));  
                    }
                    
                    for (int i = 0; i < inputRow; i++)
                    {
                        for (int j = 0; j < inputCol; j++)
                        {
                            newArray[i][j] = 's';
                        }
                    }
                    
                    writeToFile(author, title, token2, inputRow, inputCol, newArray);

                    //free(cstr);
                    clear();
                    refresh();
					endwin();                   
                    exit(EXIT_SUCCESS);
                } else if ((strcmp(token1, "m") == 0)  && (token2 != NULL) && (token3 != NULL)){
                    //modify author and title
                    writeToFile(token2, token3, filename, row, col, array);
                    
                    move(h - 1, 0);
                    clrtoeol();
                    printw("%s.pac modified", filename);
                    move(0,0);
                    break;
                } else {
					clear_Line(h-1,0);
					move(h-1,0);
                    printw("Error input");
                    break;
                }
            } else {
                for (int i =0; i<20;i++){
                    buffer[i] = ' ';
                    //free(buffer);
                }
                move(h - 1, 0);
                clrtoeol();
                move(0,0);
                break;
            }

        }else if (ch == 27){
            //exit command mode with escape
            for (int i =0; i<20;i++){
                buffer[i] = ' ';
            }
            move(h - 1, 0);
            clrtoeol();
            move(0,0);
            break;
        } else if(ch == KEY_BACKSPACE){
            int x = getcurx(stdscr);
			
            if(x != 1){
                //erase character
                move(h-1, getcurx(stdscr)-1);
                delch();
                buffer[getcurx(stdscr)-1] = '\0';           
            }
        }
        
        else {
            //read the character user input in command mode            
            buffer[getcurx(stdscr)-1] =  ch;
            addch(ch);
        }
            
    }
}
Esempio n. 25
0
int main(int argc, char *argv[])
{
	int continuer = 1;

	Commande *commande = malloc(sizeof(commande));
	initialiseCommande(commande);
	// signal(SIGINT, interrupt);

	Niveau *niveau = malloc(sizeof(niveau));
	decompression(choixNiveau(argc, argv), commande, niveau);


	/***
	*/


	struct sigaction act;
 
	memset (&act, '\0', sizeof(act));
 
	/* Use the sa_sigaction field because the handles has two additional parameters */
	act.sa_sigaction = &hdl;
 
	/* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */
	act.sa_flags = SA_SIGINFO;
 
	if (sigaction(SIGINT, &act, NULL) < 0) {
		perror ("sigaction");
		return 1;
	}
	/****
	*/

	int ch;
	int finCommande = 0;
	initscr();
	idlok(stdscr, TRUE);
	scrollok(stdscr, TRUE);
	cbreak();
    	noecho();
    	keypad(stdscr, TRUE);
    	intrflush(stdscr, FALSE);
    printw("nom : %s\n", niveau->nom);
	int x, y;
	int nbAppuiUp = 0;
	char *saisie;
	while(continuer){      
		finCommande = 0;
		saisie = malloc(TAILLE_MAX_COMMANDE*sizeof(char));
		debutLigne(commande, niveau);

		while(finCommande == 0){
			ch = wgetch(stdscr);
			if(ch != KEY_UP && ch !=KEY_DOWN)
				nbAppuiUp = 0;
			if (ch == KEY_BACKSPACE)
			{
				getyx(stdscr, y, x);
				if(x > strlen(commande->directory)+3){
					move(y, x-1);
					delch();
					strcpy(saisie, substr(saisie, 0, strlen(saisie)-1));
				}
			}
			else if(ch == KEY_LEFT){
				getyx(stdscr, y, x);
				move(y, x-1);
			}
			else if(ch == KEY_RIGHT){
				getyx(stdscr, y, x);
				move(y, x+1);
			}
			else if (ch == KEY_UP)
			{
				nbAppuiUp++;
				String *temp = malloc(sizeof(String));
				temp = niveau->history->premier;
				if (temp->suivant != NULL)
				{
					int i = 0;
					while(i < nbAppuiUp && temp->suivant != NULL){
						temp = temp->suivant;
						i++;
					}
					free(saisie);
					saisie = malloc(sizeof(char)*TAILLE_MAX_COMMANDE);
					strcpy(saisie, temp->string);
					effaceCommande(commande);
					printw("%s", saisie);
				}
			}
			else if (ch == KEY_DOWN)
			{
				nbAppuiUp--;
				String *temp = malloc(sizeof(String));
				temp = niveau->history->premier;
				if (temp->suivant != NULL)
				{
					int i = 0;
					while(i < nbAppuiUp && temp->suivant != NULL){
						temp = temp->suivant;
						i++;
					}
					free(saisie);
					saisie = malloc(sizeof(char)*TAILLE_MAX_COMMANDE);
					strcpy(saisie, temp->string);
					effaceCommande(commande);
					printw("%s", saisie);
				}
			}
			else if(ch == KEY_DC){
				delch();
				strcpy(saisie, substr(saisie, 0, strlen(saisie)-1));
			}
			else if(ch == '\t'){
				effaceCommande(commande);
				
				char *essai = malloc(sizeof(char)*TAILLE_MAX_COMMANDE);
				if(strlen(autoComplete(saisie, niveau)) == 0)
					finCommande = 1;
				else{
					strcpy(saisie, strcat(saisie, autoComplete(saisie, niveau)));
					printw("%s", saisie);
				}
			}
    		else if(ch == '\n'){
    			finCommande = 1;
    			printw("\n");
    		}
    		else{
    			printw("%c", ch);
    			sprintf(saisie, "%s%c", saisie, ch);
    		}
		}
		strcpy(commande->commande, saisie);
		execution(commande, niveau);
		// free(saisie);
	}
	endwin();
	return 0;
}
Esempio n. 26
0
 /*
    Returns whether we should save our changes or not.

    Edits an existing an entry. This routine is far to big, and handles
    everything, from movement between fields, and editing fields, even
    painting the screen.

 */
int
edit_entry(dbrecord * entry, const char *operationDesc, const char *entryDesc)
{
	int *len;
	int col0;
	wchar_t *line=NULL;
	char tbuf[MAXSCREENWIDTH];
	int code = 0;
	wchar_t ch;
	dbbuffer tmp;
	register int i, j, row, col;
    initHeading() ;
	/* Where is "column zero"? To right of longest field name.  */
	col0 = idx.idx_maxlen + 2;

	 clear();		/* Clear the screen.                            */
    initEntryLine() ;
    paintHeading(operationDesc) ;
	/* get max col TODO: change this when sigwhinch */
    /* first time: allocat wchar fulldbdir name
       fulldbdir is a static.*/
	for (row = STARTROW; row < (idx.idx_nlines+STARTROW); row++) { 
		/* print field names.                                   */
		mvaddwstr(row, 0, idx.idx_lines[row-STARTROW]);
	}
	/* Allocate some space in a temporary entry, and copy entry */
	/* to be edited into it.  This way they can abort the edit. */
	/* Here we need to allocate some extra space so we can edit */

	for (i = STARTROW; i < (idx.idx_nlines+STARTROW); i++) {
        int k = i-STARTROW ;
		if (entry->db_lens[k] == 0) {
			/* Allocate memory for this line.                   */
            size_t linelen = (MAXSCREENWIDTH * sizeof(wchar_t));
			tmp.db_lines[k] =
                 (wchar_t *) ymalloc(linelen,
                    "edit_entry","tmp.db_lines[k]" );
            memset(tmp.db_lines[k],0,linelen);
			tmp.db_lens[k] = 0;
		} else {
			/* Copy and print the line from the entry.          */
			tmp.db_lines[k] =
			    wcsFromUnicode_alloc((size_t *) & tmp.db_lens[k],
						 entry->db_lines[k],
						 (int32_t) entry->db_lens[k]);
			if (tmp.db_lines[k] == NULL) {
                yerror( YICU_CONV_ERR ,"edit_entry->wcsFromUnicode_alloc", "tmp.db_lines[k]", YX_EXTERNAL_CAUSE ) ;
			}
			/* reallocates more space to maximum linebuffer size. */
			tmp.db_lines[k] =
			    (wchar_t *) yrealloc(tmp.db_lines[k], (size_t)
						(MAXSCREENWIDTH * sizeof(wchar_t)),"edit_entry","tmp.db_lines[k]");
		}

		move(i, col0);
		clrtoeol();
		if (tmp.db_lens[k] > 0) {
			addwstr(tmp.db_lines[k]);
		}
	}			/* *could* have factored out the index code.              */
	col = col0;
	row = STARTROW;		/* row er hvilke rad i recorden (felt). */

	move(row, col);
	refresh();
	/* Editing entry. We provide basic EMACS-style cntrl chars. */
	while ((code = get_wch(&ch)) != EOF) {
		/* Get the current line and line length.                */
		line = tmp.db_lines[row-STARTROW];
		/* f.p. *len = &tmp.db_lens[row]; */
		len = &tmp.db_lens[row-STARTROW];
		switch (ch) {
		case CTRL('a'):	/* beginning of line            */
			col = col0;
			break;
		case KEY_LEFT:
		case CTRL('b'):	/* back character               */
			if (col > col0)
				col--;
			break;
		case CTRL('d'):	/* delete character             */
			if (col == (col0 + (int)wcslen(line))) {
				col--;
			} else if (*len) {
				/* Calculate position of character in string.   */
				int l = col - col0;

				/* Shuffle the string to the "left".            */
				while (l < *len) {
					line[l] = line[l + 1];
					l++;
				}
				*len -= 1;
				/* Delete the character on the screen.          */
				delch();
                if (col== (col0 + (int)wcslen(line)) ) {
                    --col ;
                }
			}

			break;
		case CTRL('e'):	/* end of line                  */
			col = col0 + *len;
			break;
		case KEY_RIGHT:
		case CTRL('f'):	/* forward character            */
			if ((col - col0) < *len)
				col++;
			break;
		case KEY_BACKSPACE:
		case CTRL('h'):	/* backspace delete             */
		case '\177':
			if (*len && ((col - 1) >= col0)) {
				/* Calculate position of character to delete.   */
				int l = col - col0 - 1;
				if (l < 0)
					break;
				/* Shuffle string "left".                        */
				while (l < *len) {
					line[l] = line[l + 1];
					l++;
				}

				*len -= 1;

				/* Delete the character from the screen.        */
				move(row, --col);
				delch();
			}
			break;
		case CTRL('k'):	/* kill line                    */
			if (len) {
                
			    int l = col - col0;

				line[l] = (wchar_t) '\0';
				*len = l;

				clrtoeol();
			}
			break;
		case CTRL('l'):	/* redraw screen                */
			wrefresh(curscr);
			break;
		case KEY_DOWN:
		case CTRL('n'):	/* next line                    */
			/* Wrap around to the top if necessary.             */
			if (++row >= (idx.idx_nlines+STARTROW))
				row = STARTROW; 
			/* If nothing in this column, move to nearest       */
			/* non-empty column.                                */
			if ((col - col0) > tmp.db_lens[row-STARTROW])
				col = col0 + tmp.db_lens[row-STARTROW];
			line[*len] = (wchar_t) '\0';
			break;
		case KEY_UP:
		case CTRL('p'):	/* previous line                */
			/* Wrap around if necessary.                        */
			if (--row < STARTROW)
				row = (idx.idx_nlines+STARTROW) - 1;

			/* If nothing in this column, move to nearest       */
			/* on-empty column.                                 */
			if ((col - col0) > tmp.db_lens[row-STARTROW])
				col = col0 + tmp.db_lens[row-STARTROW];
			line[*len] = (wchar_t) '\0';
			break;
		case CTRL('['):	/* save entry:  ESC or something...  */
			if (line[*len] != (wchar_t) '\0')
				line[*len] = (wchar_t) '\0';
			sprintf(tbuf, "Save %s entry in database (y/n)? ", entryDesc);
			ch = prompt_char(idx.idx_nlines + 2+ STARTROW, 0, tbuf, "yYnN");

			/* See what they said.                              */
			switch (ch) {
			case '\n':	/* never mind                       */
				move(idx.idx_nlines + 2, 0);
				clrtoeol();
				break;
			case 'Y':	/* save entry                       */
			case 'y':
				/* Copy the temporary entry into the real entry. */
				/* if there isn't anything to copy, then the entry db gets the value
				   NULL, and length 0 */
				for (i = 0; i < idx.idx_nlines; i++) {

					/* remove old contents in entry             */
					if (entry->db_lens[i] > 0) {
						free(entry->db_lines[i]);
						entry->db_lines[i] = NULL;
						entry->db_lens[i] = 0;
					} 
                    
                    if (tmp.db_lens[i] > 0) {
                        entry->db_lens[i]=tmp.db_lens[i] ;
						entry->db_lines[i] =
						    unicodeFromWcs_alloc((size_t *) &entry->db_lens[i],tmp.db_lines[i]);

					    if (entry->db_lines[i] == NULL) {
                            yerror( YICU_CONV_ERR ,"edit_entry->unicodeFromWcs_alloc", "entry->db_lines[i]", YX_EXTERNAL_CAUSE ) ;
                        }
                    } /* had a dangling else bug here ? */
					free(tmp.db_lines[i]);
                    tmp.db_lines[i] = NULL ;
				    tmp.db_lens[i] = 0;
				}
				return (1);
			case 'N':	/* don't save entry                 */
			case 'n':
				/* Free temporary memory.                       */
				for (i = 0; i < idx.idx_nlines; i++) {
					tmp.db_lens[i] = 0;
					free(tmp.db_lines[i]);
					tmp.db_lines[i] = NULL;
				}
				return (0);
			}
			break;
		case '\r':	/* return the string            */
		case '\n':	/* go to next line                  */
			/* Wrap around if necessary.                        */
			if (++row >= (idx.idx_nlines+STARTROW))
				row = STARTROW;
			col = col0;
			break;
		default:	/* something else                   */
			/* User's kill character: accepted to del line too. */
			if (ch == KEY_DL) {
				move(row, col0);
				clrtoeol();
				col = col0;

				*line = (wchar_t) '\0';
				*len = 0;
			} else if (code != KEY_CODE_YES) {
				/* If it's a printable character, insert it into */
				/* the string.                                  */
				if (iswctype(ch, wctype("print"))) {
					if (col == (COLS - 1)) {
						beep();
						break;
					}
					/* Calculate character position.            */
					i = col - col0;

					/* If necessary, move string * to "right"   */
					/* to insert the character.                 */
					if (i < *len) {
						for (j = *len; j >= i; j--)
							line[j + 1] = line[j];
					}

					line[i] = ch;
					*len += 1;
					col++;

					/* Insert the character on the screen.       */
					InsWch((chtype) ch);

				}
			}
			break;
		}

		/* Move to the current row/column.                       */
		move(row, col);
		refresh();
	}
	return (0);
}
Esempio n. 27
0
int window_new_call_run_command(gui_t* gui, int c)
{
	ogmp_curses_t* ocui = gui->topui;

	int max = 3;

	switch (c)
    {
		case KEY_DC:
		{
			editline_remove_char(newcall_edit[cursor_newcall]);
			
			delch();

			break;
		}
		case '\b':
		{
			if (editline_move_pos(newcall_edit[cursor_newcall], -1) >= 0)
				editline_remove_char(newcall_edit[cursor_newcall]);
			else
				beep();

			break;
		}
		case '\n':
		case '\r':
		case KEY_ENTER:
		case KEY_DOWN:
		{
			cursor_newcall++;
			cursor_newcall %= max;

			break;
		}
		case KEY_UP:
		{
			cursor_newcall += max-1;
			cursor_newcall %= max;

			break;
		}
		case KEY_RIGHT:
		{
			if (editline_move_pos(newcall_edit[cursor_newcall], 1) < 0)
				beep();

			break;
		}
		case KEY_LEFT:
		{
			if (editline_move_pos(newcall_edit[cursor_newcall], -1) < 0)
				beep();

			break;
		}
		case 1: /* Ctrl-A */
		{
			/* if (_josua_start_call(cfg.identity, to, subject, route) != 0) beep(); */
			sipua_set_t* call = ocui->sipua->new_call(ocui->sipua, newcall_inputs[NEWCALL_SUBJ], strlen(newcall_inputs[NEWCALL_SUBJ]), newcall_inputs[NEWCALL_MSG], strlen(newcall_inputs[NEWCALL_MSG]));
			
			if(call)
				ocui->sipua->call(ocui->sipua, call, newcall_inputs[NEWCALL_TO]);

			gui_activate_window(gui, GUI_SESSION);

			break;
		}
		case 3:  /* Ctrl-C */
		{
			gui_hide_window(gui);

			break;
		}
		case 4:  /* Ctrl-D */
		{
			editline_clear(newcall_edit[cursor_newcall]);
	
			break;
		}
		case 15: /* Ctrl-O */
		{
			/* if (_josua_start_options(cfg.identity, to, route) != 0) beep(); */
			break;
		}
		case 19: /* Ctrl-S */
		{
			/* if (_josua_start_subscribe(cfg.identity, to, route) != 0) beep(); */
			break;
		}
		default:
		{
			if(editline_append(newcall_edit[cursor_newcall], (char*)&c, 1) == 0)
				beep();
	
			return -1;
		}
	}

	return 0;
}
Esempio n. 28
0
cell pp_curs_delch(cell x) {
	if (!Running) return UNSPECIFIC;
	delch();
	return UNSPECIFIC;
}
Esempio n. 29
0
/* get a line from the terminal in non-canonical mode */
int
mygetline(char p[], char s[], unsigned size, int firstchar, BOOL iscaseless)
{
    int	c;
    unsigned int i = 0, j;
    char *sright;	/* substring to the right of the cursor */
    unsigned int ri = 0;		/* position in right-string */

    /* Inserts and deletes are always performed on the left-string,
     * but we'll also have a right-string 'sright' to hold characters
     * which are on the right of the cursor [insertion point].
     *
     * Think of 'sright' as a stack -- we push chars into it when the cursor
     * moves left, and we pop chars off it when the cursor moves right again.
     * At the end of the function, we'll pop off any remaining characters
     * onto the end of 's'
     */
    sright = calloc(sizeof(char), size );

    strcpy ( s, p);
    i += strlen(p);
    /* if a character already has been typed */
    if (firstchar != '\0') {
	if(iscaseless == YES) {
	    firstchar = tolower(firstchar);
	}
	addch(firstchar);	/* display it */
	s[i++] = firstchar;	/* save it */
    }
    /* until the end of the line is reached */
    while ((c = mygetch()) != '\r' && c != '\n' && c != KEY_ENTER) {
	if (c == KEY_LEFT || c == ctrl('B')) {	/* left */
	    if (i > 0) {
		addch('\b');
		/* move this char into the second (rhs) string */
		sright[ri++] = s[--i];
	    }
	} else if (c == KEY_RIGHT || c == ctrl('F')) {	/* right */
	    if (i < size && ri > 0) {
		/* move this char to the left of the cursor */
		s[i++] = sright[--ri];
		addch(s[i-1]);
	    }
	} else if (
#ifdef KEY_HOME
		   c == KEY_HOME ||
#endif
		   c == ctrl('A') ) {
	    while (i > 0) {
		sright[ri++] = s[--i];
		addch('\b');
		addch(s[i]);
		addch('\b');
	    }
	} else if (
#ifdef KEY_END
		   c == KEY_END ||
#endif
		   c == ctrl('E') ) {
	    while (ri > 0) {
		s[i++] = sright[--ri];
		addch(s[i-1]);
	    }
	} else if (c == erasechar() || c == KEY_BACKSPACE
		   || c == DEL || c == ctrl('H') ) {
	    /* erase */
	    if (i > 0) {
		if (ri == 0)  {
		    addstr("\b \b");
		} else {
		    addch('\b');
		    delch();
		}
		s[i] = '\0';
		--i;
	    }
	} else if (c == killchar() || c == KEY_BREAK) {
	    /* kill */
	    for (j = 0; j < i; ++j) {
		addch('\b');
	    }
	    for (j = 0; j < i; ++j) {
		addch(' ');
	    }
	    for (j = 0; j < i; ++j) {
		addch('\b');
	    }
	    i = 0;
	} else if (isprint(c) || c == '\t') {
	    /* printable */
	    if(iscaseless == YES) {
		c = tolower(c);
	    }
	    /* if it will fit on the line */
	    if (i < size) {
		s[i++] = c;	/* save it */
		if (ri == 0) {
		    addch(c);	/* display it */
		} else {
		    insch(c);	/* display it */
		    addch(c);	/* advance cursor */
		}
	    }
#if UNIXPC
	} else if (unixpcmouse == YES && c == ESC) {	/* mouse */
	    getmouseaction(ESC);	/* ignore it */
#endif
	} else if (mouse == YES && c == ctrl('X')) {
	    getmouseaction(ctrl('X'));	/* ignore it */
	} else if (c == EOF) {				/* end-of-file */
	    break;
	}

	/* return on an empty line to allow a command to be entered */
	if (firstchar != '\0' && (i+ri) == 0) {
	    break;
	}
    }

    /* move any remaining chars on the rhs of the cursor
     * onto the end of our string
     */
    while (ri > 0) {
	s[i++] = sright[--ri];
    }
    free(sright);

    s[i] = '\0';
    return(i);
}
Esempio n. 30
0
void
Elis::Application::run()
{
    char key;
    Elis::UI::Line line;

    window->new_line();
    window->show();

    configure_ncurses();

    while(true) /*laço infinito*/
    {
        key = getch(); /*ler caractere*/

        if (key == Elis::Keys::QUIT)
            break;

        switch(key)
        {
            case Elis::Keys::DELETE:
            case Elis::Keys::BACKSPACE:
                current_line.pop_back(); /*Remove o último caractere*/
                addch('\b');
                delch();
                break;
            case Elis::Keys::ENTER:
                line = window->new_line();
                current_line.push_back('\n'); /*Nova linha*/

                printw("\n");
                line.show();

                break;
            case Elis::Keys::ESCAPE:
                printw("\n: "); /*Ler o que será digitado*/

                while (true)
                {
                    key = getch();

                    addch(key);

                    if (key == Elis::Keys::QUIT)
                        break;

                    else if (key == 'W' || key == 'w')
                    {
                        std::string s;

                        while((key = getch()) != Elis::Keys::ENTER)
                        {
                            s.push_back(key);
                            addch(key);
                        }

                        //s.erase( std::remove(s.begin(), s.end(), ' '), s.end() );

                        if (!s.empty())
                            filename = s;

                        std::ofstream file;

                        file.open(filename);
                        file << current_line;
                        file.close();
                        break;
                    }
                }
                break;
            default:
                current_line.push_back(key);
                addch(key);
        }

        refresh();
    }

    window->hide();
}