aboutsummaryrefslogtreecommitdiff
path: root/lib/IRC/Client.pm6
diff options
context:
space:
mode:
authorZoffix Znet <cpan@zoffix.com>2016-06-04 15:16:43 -0400
committerZoffix Znet <cpan@zoffix.com>2016-06-04 15:16:43 -0400
commit791d7981cff0cd3a85fdd504f410a7c9833272dc (patch)
tree8939f72fb9d4c496cf2f988e35a3d6351343c374 /lib/IRC/Client.pm6
parentcb0a6cace8871d17c9701edc1ccba26d1e6e0bfe (diff)
More stuff
Diffstat (limited to 'lib/IRC/Client.pm6')
-rw-r--r--lib/IRC/Client.pm628
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6
index 7d8369a..3fca5ae 100644
--- a/lib/IRC/Client.pm6
+++ b/lib/IRC/Client.pm6
@@ -19,9 +19,9 @@ has IO::Socket::Async $!sock;
method run {
await IO::Socket::Async.connect( $!host, $!port ).then({
$!sock = .result;
- self!ssay: "PASS $!password\n" if $!password.defined;
- self!ssay: "NICK $!nick\n";
- self!ssay: "USER $!username $!username $!host :$!userreal\n";
+ self!ssay: "PASS $!password" if $!password.defined;
+ self!ssay: "NICK $!nick";
+ self!ssay: "USER $!username $!username $!host :$!userreal";
my $left-overs = '';
react {
@@ -31,10 +31,10 @@ method run {
$str ~= $left-overs;
(my $events, $left-overs) = self!parse: $str;
- # for @$events -> $e {
- # say "[event] $e";
- # CATCH { warn .backtrace }
- # }
+ for $events.grep: *.defined -> $e {
+ $!debug and debug-print $e;
+ CATCH { warn .backtrace }
+ }
}
CATCH { warn .backtrace }
@@ -44,7 +44,7 @@ method run {
}
method !ssay (Str:D $msg) {
- $!debug and "$msg".put;
+ $!debug and debug-print $msg;
$!sock.print("$msg\n");
self;
}
@@ -58,3 +58,15 @@ method !parse (Str:D $str) {
),
).made;
}
+
+sub debug-print ($str, $dir where * eq 'in' | 'out') {
+ state $color = try {
+ require Terminal::ANSIColor;
+ $color = GLOBAL::Terminal::ANSIColor::EXPORT::DEFAULT::<&color>;
+ } // sub (Str $s) { '' };
+
+ put ( $dir eq 'in'
+ ?? $color('bold blue' ) ~ '▬▬▬▶ '
+ !! $color('bold green') ~ '◀▬▬▬ '
+ ) ~ $color('bold red') ~ join $color('reset'), $str.split: ' ', 2;
+}