PERL6 45
Cbreak.pl Guest on 6th May 2020 01:32:42 PM
  1. $sgttyb_t   = 'C4 S';
  2.  
  3. sub cbreak {
  4.     &set_cbreak(1);
  5. }
  6.  
  7. sub cooked {
  8.     &set_cbreak(0);
  9. }
  10.  
  11. sub set_cbreak {
  12.     local($on) = @_;
  13.  
  14.     require 'sizeof.ph';
  15.     require 'sys/ioctl.ph';
  16.  
  17.     ioctl(STDIN,&TIOCGETP,$sgttyb)
  18.         || die "Can't ioctl TIOCGETP: $!";
  19.  
  20.     @ary = unpack($sgttyb_t,$sgttyb);
  21.     if ($on) {
  22.         $ary[4] |= &CBREAK;
  23.         $ary[4] &= ~&ECHO;
  24.     } else {
  25.         $ary[4] &= ~&CBREAK;
  26.         $ary[4] |= &ECHO;
  27.     }
  28.     $sgttyb = pack($sgttyb_t,@ary);
  29.     ioctl(STDIN,&TIOCSETP,$sgttyb)
  30.             || die "Can't ioctl TIOCSETP: $!";
  31.  
  32. }
  33.  
  34. 1;

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.