src/console/conio.c
static void rawmode(FILE *input)
{
   struct termios t;
   static char term_buf[2048];
   static char *term_buffer = term_buf;
   char *termtype = (char *)getenv("TERM");

   /* Make sure we are dealing with a terminal */
   if (!isatty(fileno(input))) {
      return;
   }
   if (tcgetattr(0, &old_term_params) != 0) {
      printf("conio: Cannot tcgetattr()\n");
      exit(1);
   }
   old_term_params_set = true;
   t = old_term_params;
   t.c_cc[VMIN] = 1; /* satisfy read after 1 char */
   t.c_cc[VTIME] = 0;
   t.c_iflag &= ~(BRKINT | IGNPAR | PARMRK | INPCK |
                  ISTRIP | ICRNL | IXON | IXOFF | INLCR | IGNCR);
   t.c_iflag |= IGNBRK;
   t.c_oflag |= ONLCR;
   t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON |
                  NOFLSH | TOSTOP);
   tcflush(0, TCIFLUSH);
   if (tcsetattr(0, TCSANOW, &t) == -1) {
      printf("Cannot tcsetattr()\n");
   }

   /* Defaults, the main program can override these */
   signal(SIGQUIT, SIG_IGN);
   signal(SIGHUP, SIG_IGN);
   trapctlc();
   signal(SIGWINCH, SIG_IGN);

   if (!termtype) {
      printf("Cannot get terminal type.\n");
      normode();
      exit(1);
   }
   if (tgetent(term_buffer, termtype) < 0) {
      printf("Cannot get terminal termcap entry.\n");
      normode();
      exit(1);
   }
   t_width = t_height = -1;
   /* Note (char *)casting is due to really stupid compiler warnings */
   t_width = tgetnum((char *)"co") - 1;
   t_height = tgetnum((char *)"li");
   BC = NULL;
   UP = NULL;
   t_cm = (char *)tgetstr((char *)"cm", &term_buffer);
   t_cs = (char *)tgetstr((char *)"cl", &term_buffer); /* clear screen */
   t_cl = (char *)tgetstr((char *)"ce", &term_buffer); /* clear line */
   t_dl = (char *)tgetstr((char *)"dl", &term_buffer); /* delete line */
   t_il = (char *)tgetstr((char *)"al", &term_buffer); /* insert line */
   t_honk = (char *)tgetstr((char *)"bl", &term_buffer); /* beep */
   t_ti = (char *)tgetstr((char *)"ti", &term_buffer);
   t_te = (char *)tgetstr((char *)"te", &term_buffer);
   t_up = (char *)tgetstr((char *)"up", &term_buffer);
   t_do = (char *)tgetstr((char *)"do", &term_buffer);
   t_sf = (char *)tgetstr((char *)"sf", &term_buffer);

   num_stab = MAX_STAB;                  /* get default stab size */
   stab = (stab_t **)malloc(sizeof(stab_t *) * num_stab);
   memset(stab, 0, sizeof(stab_t *) * num_stab);

   /* Key bindings */
   kl = (char *)tgetstr((char *)"kl", &term_buffer);
   kr = (char *)tgetstr((char *)"kr", &term_buffer);
   ku = (char *)tgetstr((char *)"ku", &term_buffer);
   kd = (char *)tgetstr((char *)"kd", &term_buffer);
   kh = (char *)tgetstr((char *)"kh", &term_buffer);
   kb = (char *)tgetstr((char *)"kb", &term_buffer);
   kD = (char *)tgetstr((char *)"kD", &term_buffer);
   kI = (char *)tgetstr((char *)"kI", &term_buffer);
   kN = (char *)tgetstr((char *)"kN", &term_buffer);
   kP = (char *)tgetstr((char *)"kP", &term_buffer);
   kH = (char *)tgetstr((char *)"kH", &term_buffer);
   kE = (char *)tgetstr((char *)"kE", &term_buffer);

   add_smap(kl, F_CSRLFT);
   add_smap(kr, F_CSRRGT);
   add_smap(ku, F_CSRUP);
   add_smap(kd, F_CSRDWN);
   add_smap(kI, F_TINS);
   add_smap(kN, F_PAGDWN);
   add_smap(kP, F_PAGUP);
   add_smap(kH, F_HOME);
   add_smap(kE, F_EOF);


   add_esc_smap("[A",   F_CSRUP);
   add_esc_smap("[B",   F_CSRDWN);
   add_esc_smap("[C",   F_CSRRGT);
   add_esc_smap("[D",   F_CSRLFT);
   add_esc_smap("[1~",  F_HOME);
   add_esc_smap("[2~",  F_TINS);
   add_esc_smap("[3~",  F_DELCHR);
   add_esc_smap("[4~",  F_EOF);
   add_esc_smap("f",    F_NXTWRD);
   add_esc_smap("b",    F_PRVWRD);
}
/* Set raw mode on terminal file.  Basically, get the terminal into a
   mode in which all characters can be read as they are entered.  CBREAK
   mode is not sufficient.
 */
Set raw mode on terminal file.  Basically, get the terminal into a
mode in which all characters can be read as they are entered.  CBREAK
mode is not sufficient.
Set raw mode on terminal file . Basically get the terminal into a mode in which all characters can be read as they are entered . CBREAK mode is not sufficient .
static void rawmode(FILE *input)
{
   struct termios t;
   static char term_buf[2048];
   static char *term_buffer = term_buf;
   char *termtype = (char *)getenv("TERM");
   if (!isatty(fileno(input))) {
      return;
   }
   if (tcgetattr(0, &old_term_params) != 0) {
      printf("conio: Cannot tcgetattr()\n");
      exit(1);
   }
   old_term_params_set = true;
   t = old_term_params;
   t.c_cc[VMIN] = 1; 
   t.c_cc[VTIME] = 0;
   t.c_iflag &= ~(BRKINT | IGNPAR | PARMRK | INPCK |
                  ISTRIP | ICRNL | IXON | IXOFF | INLCR | IGNCR);
   t.c_iflag |= IGNBRK;
   t.c_oflag |= ONLCR;
   t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON |
                  NOFLSH | TOSTOP);
   tcflush(0, TCIFLUSH);
   if (tcsetattr(0, TCSANOW, &t) == -1) {
      printf("Cannot tcsetattr()\n");
   }
   signal(SIGQUIT, SIG_IGN);
   signal(SIGHUP, SIG_IGN);
   trapctlc();
   signal(SIGWINCH, SIG_IGN);
   if (!termtype) {
      printf("Cannot get terminal type.\n");
      normode();
      exit(1);
   }
   if (tgetent(term_buffer, termtype) < 0) {
      printf("Cannot get terminal termcap entry.\n");
      normode();
      exit(1);
   }
   t_width = t_height = -1;
   t_width = tgetnum((char *)"co") - 1;
   t_height = tgetnum((char *)"li");
   BC = NULL;
   UP = NULL;
   t_cm = (char *)tgetstr((char *)"cm", &term_buffer);
   t_cs = (char *)tgetstr((char *)"cl", &term_buffer); 
   t_cl = (char *)tgetstr((char *)"ce", &term_buffer); 
   t_dl = (char *)tgetstr((char *)"dl", &term_buffer); 
   t_il = (char *)tgetstr((char *)"al", &term_buffer); 
   t_honk = (char *)tgetstr((char *)"bl", &term_buffer); 
   t_ti = (char *)tgetstr((char *)"ti", &term_buffer);
   t_te = (char *)tgetstr((char *)"te", &term_buffer);
   t_up = (char *)tgetstr((char *)"up", &term_buffer);
   t_do = (char *)tgetstr((char *)"do", &term_buffer);
   t_sf = (char *)tgetstr((char *)"sf", &term_buffer);
   num_stab = MAX_STAB;                  
   stab = (stab_t **)malloc(sizeof(stab_t *) * num_stab);
   memset(stab, 0, sizeof(stab_t *) * num_stab);
   kl = (char *)tgetstr((char *)"kl", &term_buffer);
   kr = (char *)tgetstr((char *)"kr", &term_buffer);
   ku = (char *)tgetstr((char *)"ku", &term_buffer);
   kd = (char *)tgetstr((char *)"kd", &term_buffer);
   kh = (char *)tgetstr((char *)"kh", &term_buffer);
   kb = (char *)tgetstr((char *)"kb", &term_buffer);
   kD = (char *)tgetstr((char *)"kD", &term_buffer);
   kI = (char *)tgetstr((char *)"kI", &term_buffer);
   kN = (char *)tgetstr((char *)"kN", &term_buffer);
   kP = (char *)tgetstr((char *)"kP", &term_buffer);
   kH = (char *)tgetstr((char *)"kH", &term_buffer);
   kE = (char *)tgetstr((char *)"kE", &term_buffer);
   add_smap(kl, F_CSRLFT);
   add_smap(kr, F_CSRRGT);
   add_smap(ku, F_CSRUP);
   add_smap(kd, F_CSRDWN);
   add_smap(kI, F_TINS);
   add_smap(kN, F_PAGDWN);
   add_smap(kP, F_PAGUP);
   add_smap(kH, F_HOME);
   add_smap(kE, F_EOF);
   add_esc_smap("[A",   F_CSRUP);
   add_esc_smap("[B",   F_CSRDWN);
   add_esc_smap("[C",   F_CSRRGT);
   add_esc_smap("[D",   F_CSRLFT);
   add_esc_smap("[1~",  F_HOME);
   add_esc_smap("[2~",  F_TINS);
   add_esc_smap("[3~",  F_DELCHR);
   add_esc_smap("[4~",  F_EOF);
   add_esc_smap("f",    F_NXTWRD);
   add_esc_smap("b",    F_PRVWRD);
}
static void rawmode ( FILE * input ) { struct termios t ; static char term_buf [ 2048 ] ; static char * term_buffer = term_buf ; char * termtype = ( char * ) getenv ( " " ) ; if ( ! isatty ( fileno ( input ) ) ) { return ; } if ( tcgetattr ( 0 , & old_term_params ) != 0 ) { printf ( " \n " ) ; exit ( 1 ) ; } old_term_params_set = true ; t = old_term_params ; t . c_cc [ VMIN ] = 1 ; t . c_cc [ VTIME ] = 0 ; t . c_iflag &= ~ ( BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | ICRNL | IXON | IXOFF | INLCR | IGNCR ) ; t . c_iflag |= IGNBRK ; t . c_oflag |= ONLCR ; t . c_lflag &= ~ ( ECHO | ECHOE | ECHOK | ECHONL | ICANON | NOFLSH | TOSTOP ) ; tcflush ( 0 , TCIFLUSH ) ; if ( tcsetattr ( 0 , TCSANOW , & t ) == -1 ) { printf ( " \n " ) ; } signal ( SIGQUIT , SIG_IGN ) ; signal ( SIGHUP , SIG_IGN ) ; trapctlc ( ) ; signal ( SIGWINCH , SIG_IGN ) ; if ( ! termtype ) { printf ( " \n " ) ; normode ( ) ; exit ( 1 ) ; } if ( tgetent ( term_buffer , termtype ) < 0 ) { printf ( " \n " ) ; normode ( ) ; exit ( 1 ) ; } t_width = t_height = -1 ; t_width = tgetnum ( ( char * ) " " ) - 1 ; t_height = tgetnum ( ( char * ) " " ) ; BC = NULL ; UP = NULL ; t_cm = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; t_cs = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; t_cl = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; t_dl = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; t_il = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; t_honk = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; t_ti = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; t_te = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; t_up = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; t_do = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; t_sf = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; num_stab = MAX_STAB ; stab = ( stab_t * * ) malloc ( sizeof ( stab_t * ) * num_stab ) ; memset ( stab , 0 , sizeof ( stab_t * ) * num_stab ) ; kl = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; kr = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; ku = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; kd = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; kh = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; kb = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; kD = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; kI = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; kN = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; kP = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; kH = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; kE = ( char * ) tgetstr ( ( char * ) " " , & term_buffer ) ; add_smap ( kl , F_CSRLFT ) ; add_smap ( kr , F_CSRRGT ) ; add_smap ( ku , F_CSRUP ) ; add_smap ( kd , F_CSRDWN ) ; add_smap ( kI , F_TINS ) ; add_smap ( kN , F_PAGDWN ) ; add_smap ( kP , F_PAGUP ) ; add_smap ( kH , F_HOME ) ; add_smap ( kE , F_EOF ) ; add_esc_smap ( " " , F_CSRUP ) ; add_esc_smap ( " " , F_CSRDWN ) ; add_esc_smap ( " " , F_CSRRGT ) ; add_esc_smap ( " " , F_CSRLFT ) ; add_esc_smap ( " " , F_HOME ) ; add_esc_smap ( " " , F_TINS ) ; add_esc_smap ( " " , F_DELCHR ) ; add_esc_smap ( " " , F_EOF ) ; add_esc_smap ( " " , F_NXTWRD ) ; add_esc_smap ( " " , F_PRVWRD ) ; }
Set raw mode on terminal file.
Set raw mode on terminal file .
/* Make sure we are dealing with a terminal */ /* satisfy read after 1 char */ /* Defaults, the main program can override these */ /* Note (char *)casting is due to really stupid compiler warnings */ /* clear screen */ /* clear line */ /* delete line */ /* insert line */ /* beep */ /* get default stab size */ /* Key bindings */