Advertisement
Guest User

Untitled

a guest
Mar 1st, 2021
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. unit module Events;
  2. use NativeCall;
  3.  
  4. my package EXPORT::EVENTS {
  5. constant KEY_PG_DOWN = '[6~';
  6. constant KEY_PG_UP = '[5~';
  7. constant KEY_DOWN = '[B';
  8. constant KEY_UP = '[A';
  9. constant KEY_RIGHT = '[C';
  10. constant KEY_LEFT = '[D';
  11. constant KEY_F10 = '[21';
  12. constant KEY_ENTER = "\n";
  13. }
  14.  
  15. constant LIBPATH = "$*CWD/rtwl/mngrterm";
  16.  
  17.  
  18. class Event is export {
  19. has Str $.method;
  20. has $.exit_key;
  21. has %.events;
  22. has $!estr;
  23.  
  24. sub disable_stty_echo() is native(LIBPATH) { * };
  25. sub enable_stty_echo() is native(LIBPATH) { * };
  26.  
  27. method wait_events() {
  28. signal(SIGINT).tap({ self!resume(SIGINT)});
  29. signal(SIGTERM).tap({ self!resume(SIGTERM);});
  30. self!noecho();
  31. self!loop_on();
  32. }
  33. method !loop_on {
  34. my $c = 32;
  35. say 'INTO loop_on';
  36. while $c = $*IN.getc() {
  37. say 'c: ',$c;
  38. }
  39. }
  40.  
  41. method !noecho {
  42. disable_stty_echo();
  43. }
  44. method !echo {
  45. enable_stty_echo();
  46. }
  47. method !resume(Int $signal=0) {
  48. self!echo();
  49. given $signal {
  50. when 0 {;}
  51. default {say 'Received signal: ',$signal;}
  52. }
  53. exit(0);
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement