Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit module Events;
- use NativeCall;
- my package EXPORT::EVENTS {
- constant KEY_PG_DOWN = '[6~';
- constant KEY_PG_UP = '[5~';
- constant KEY_DOWN = '[B';
- constant KEY_UP = '[A';
- constant KEY_RIGHT = '[C';
- constant KEY_LEFT = '[D';
- constant KEY_F10 = '[21';
- constant KEY_ENTER = "\n";
- }
- constant LIBPATH = "$*CWD/rtwl/mngrterm";
- class Event is export {
- has Str $.method;
- has $.exit_key;
- has %.events;
- has $!estr;
- sub disable_stty_echo() is native(LIBPATH) { * };
- sub enable_stty_echo() is native(LIBPATH) { * };
- method wait_events() {
- signal(SIGINT).tap({ self!resume(SIGINT)});
- signal(SIGTERM).tap({ self!resume(SIGTERM);});
- self!noecho();
- self!loop_on();
- }
- method !loop_on {
- my $c = 32;
- say 'INTO loop_on';
- while $c = $*IN.getc() {
- say 'c: ',$c;
- }
- }
- method !noecho {
- disable_stty_echo();
- }
- method !echo {
- enable_stty_echo();
- }
- method !resume(Int $signal=0) {
- self!echo();
- given $signal {
- when 0 {;}
- default {say 'Received signal: ',$signal;}
- }
- exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement