#include "request.h"

char *get_magic( WINDOW *old_win, char *put_string )
{
  WINDOW *new_win;
  char data[40];
  int counter = 0;
  chtype c;

  new_win = subwin( old_win, 6, 44, 10, 19 );
  
  raw( );
  curs_set(0);
  werase( new_win );
  box( new_win, 0, 0 );
  mvwaddstr( new_win, 2, 1, put_string );
  mvwaddch( new_win, 3, 1, '>' );
  wrefresh( new_win );
  
  while( (c = wgetch(new_win)) && (c != 27) && (c != 10) )
    {

      if ((c == 127) && (counter > 0))
	{
	  c = 32;
	  mvwaddch( new_win, 3, 2 + counter, toupper(c) ); 
	  data[counter] = toupper(c);
	  counter--;
	  mvwaddch( new_win, 3, 2 + counter, toupper(c) ); 

	}
      else
	{
	  mvwaddch( new_win, 3, 2 + counter, toupper(c) ); 
	  data[counter] = toupper(c);
	  if (counter < 39)
	    counter++;	  
	}

      wrefresh( new_win );

    }

  if ( c != 27 )
    { 
      if ( !strcmp( put_string, "Magic" ) )
	  data[counter++]=10;
      data[counter]='\0';
    }
  else
    data[0]='\0';

  delwin( new_win );
  return data;
}


