From 791d7981cff0cd3a85fdd504f410a7c9833272dc Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sat, 4 Jun 2016 15:16:43 -0400 Subject: More stuff --- lib/IRC/Client.pm6 | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'lib/IRC/Client.pm6') 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; +} -- cgit v1.1