aboutsummaryrefslogtreecommitdiff
path: root/challenge-028/markus-holzer/perl6/lib
diff options
context:
space:
mode:
authorholli-holzer <holli.holzer@gmail.com>2019-10-01 00:05:42 +0200
committerholli-holzer <holli.holzer@gmail.com>2019-10-01 00:10:51 +0200
commit019e5c99d99ea7698d4f5cef235aab995e15a871 (patch)
tree25c481267b97145d7f40736720ee300a139fdb65 /challenge-028/markus-holzer/perl6/lib
parentd92bcbed1a2535200e78b948aabb2905c3ab6fa6 (diff)
downloadperlweeklychallenge-club-019e5c99d99ea7698d4f5cef235aab995e15a871.tar.gz
perlweeklychallenge-club-019e5c99d99ea7698d4f5cef235aab995e15a871.tar.bz2
perlweeklychallenge-club-019e5c99d99ea7698d4f5cef235aab995e15a871.zip
Solutions Markus Holzer
Diffstat (limited to 'challenge-028/markus-holzer/perl6/lib')
-rw-r--r--challenge-028/markus-holzer/perl6/lib/Win/VT.pm665
-rw-r--r--challenge-028/markus-holzer/perl6/lib/Win/VT/Auto.pm66
-rw-r--r--challenge-028/markus-holzer/perl6/lib/Win/VT/Auto/I.pm66
-rw-r--r--challenge-028/markus-holzer/perl6/lib/Win/VT/Auto/O.pm68
4 files changed, 85 insertions, 0 deletions
diff --git a/challenge-028/markus-holzer/perl6/lib/Win/VT.pm6 b/challenge-028/markus-holzer/perl6/lib/Win/VT.pm6
new file mode 100644
index 0000000000..88fbcb97c6
--- /dev/null
+++ b/challenge-028/markus-holzer/perl6/lib/Win/VT.pm6
@@ -0,0 +1,65 @@
+unit module Win::VT;
+
+use NativeCall;
+
+constant STD_INPUT_HANDLE = -0xA;
+constant STD_OUTPUT_HANDLE = -0xB;
+constant ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200;
+constant ENABLE_PROCESSED_INPUT = 0x0001;
+constant ENABLE_PROCESSED_OUTPUT = 0x0001;
+constant ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
+constant DWORD := uint32;
+constant BOOL := int32;
+constant HANDLE := Pointer[void];
+
+sub GetConsoleMode(HANDLE, DWORD is rw) is native('Kernel32') returns BOOL { * };
+sub SetConsoleMode(HANDLE, DWORD) is native('Kernel32') returns BOOL { * };
+sub GetStdHandle(DWORD) is native('Kernel32') returns HANDLE { * };
+
+my HANDLE $input-handle;
+my HANDLE $output-handle;
+my DWORD $output-mode;
+my DWORD $input-mode;
+
+INIT {
+ if $*VM.osname eq "mswin32"
+ {
+ $input-handle = GetStdHandle( STD_INPUT_HANDLE );
+ $output-handle = GetStdHandle( STD_OUTPUT_HANDLE );
+ }
+}
+sub foo
+{
+
+}
+
+sub vt-on(Bool :$vt-input=True, Bool :$vt-output=True ) returns Bool is export(:MANDATORY)
+{
+ return False
+ unless $input-handle.defined && $output-handle.defined;
+
+ return False
+ unless GetConsoleMode($input-handle, $input-mode) && GetConsoleMode($output-handle, $output-mode);
+
+ my $new-input-mode = $input-mode +| ENABLE_PROCESSED_INPUT +| ENABLE_VIRTUAL_TERMINAL_INPUT;
+ my $new-output-mode = $output-mode +| ENABLE_PROCESSED_OUTPUT +| ENABLE_VIRTUAL_TERMINAL_PROCESSING;
+
+ return (
+ ( $vt-input ?? SetConsoleMode($input-handle, $new-input-mode) !! 1 ) &&
+ ( $vt-output ?? SetConsoleMode($output-handle, $new-output-mode) !! 1 )
+ ).Bool;
+}
+
+sub vt-off() returns Bool is export(:MANDATORY) {
+ return (
+ $input-handle.defined && $output-handle.defined &&
+ SetConsoleMode($output-handle, $output-mode) &&
+ SetConsoleMode($input-handle, $input-mode)
+ ).Bool;
+}
+
+sub cls() is export(:cls) {
+ vt-on;
+ print chr(27) ~ '[2J' ~ chr(27) ~ '[;H';
+ vt-off;
+}
diff --git a/challenge-028/markus-holzer/perl6/lib/Win/VT/Auto.pm6 b/challenge-028/markus-holzer/perl6/lib/Win/VT/Auto.pm6
new file mode 100644
index 0000000000..d407e8012f
--- /dev/null
+++ b/challenge-028/markus-holzer/perl6/lib/Win/VT/Auto.pm6
@@ -0,0 +1,6 @@
+use Win::VT;
+
+unit module Win::VT::Auto;
+INIT { vt-on; }
+END { vt-off; }
+signal(SIGINT).tap({ vt-off; } ); \ No newline at end of file
diff --git a/challenge-028/markus-holzer/perl6/lib/Win/VT/Auto/I.pm6 b/challenge-028/markus-holzer/perl6/lib/Win/VT/Auto/I.pm6
new file mode 100644
index 0000000000..f75da7cff0
--- /dev/null
+++ b/challenge-028/markus-holzer/perl6/lib/Win/VT/Auto/I.pm6
@@ -0,0 +1,6 @@
+use Win::VT;
+
+unit module Win::VT::Auto::I;
+INIT { vt-on( :vt-output(False) ) }
+END { vt-off; }
+signal(SIGINT).tap({ vt-off; } ); \ No newline at end of file
diff --git a/challenge-028/markus-holzer/perl6/lib/Win/VT/Auto/O.pm6 b/challenge-028/markus-holzer/perl6/lib/Win/VT/Auto/O.pm6
new file mode 100644
index 0000000000..ae74ff3b1e
--- /dev/null
+++ b/challenge-028/markus-holzer/perl6/lib/Win/VT/Auto/O.pm6
@@ -0,0 +1,8 @@
+use Win::VT;
+
+unit module Win::VT::Auto::O;
+INIT { vt-on( :vt-input(False) ) }
+END { vt-off; }
+signal(SIGINT).tap({ vt-off; } );
+
+