/* This file is part of Lcrzo.
*/

int lcrzo_stdin_press(const char *message)
#if defined LCRZODEF_SYSTEM_Unix
{ struct termios old_termios, new_termios;

  /*change de mode*/
  if (tcgetattr(STDIN_FILENO, &old_termios)) return(LCRZO_ERR_FUTCGETATTR);
  new_termios=old_termios;
  new_termios.c_lflag &= (~ICANON); /*desactive le mode canonique*/
  new_termios.c_cc[VMIN] = 1;       /*passe si au moins un caractere*/
  new_termios.c_cc[VTIME] = 0;      /*attend indefiniment l'appui*/
  new_termios.c_lflag &= ~ECHO;     /*caractere invisible*/
  if (tcsetattr(STDIN_FILENO, TCSANOW, &new_termios))
    return(LCRZO_ERR_FUTCSETATTR);

  /*attend la pression d'une touche*/
  if (message!=NULL) if (message[0]!='\0') printf("%s ", message);
  lcrzo_er(lcrzo_stream_flush(stdin));
  fgetc(stdin);
  if (message!=NULL) if (message[0]!='\0') printf("\n");

  /*remet le mode d'origine*/
  if (tcsetattr(STDIN_FILENO, TCSANOW, &old_termios))
    return(LCRZO_ERR_FUTCSETATTR);

  return(LCRZO_ERR_OK);
}
#elif defined LCRZODEF_SYSTEM_Windows
{
  /*attend la pression d'une touche*/
  if (message!=NULL) if (message[0]!='\0') printf("%s ", message);
  lcrzo_er(lcrzo_stream_flush(stdin));
  _getch();
  if (message!=NULL) if (message[0]!='\0') printf("\n");
  lcrzo_err_purge();

  return(LCRZO_ERR_OK);
}
#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif

