@@ -48,10 +48,12 @@ package Evalbot;
48
48
use File::Temp qw( tempfile) ;
49
49
use Carp qw( confess) ;
50
50
use Scalar::Util qw( reftype) ;
51
+ use charnames qw( :full) ;
51
52
my $prefix = ' ' ;
52
53
my $postfix = qr / :\s / ;
53
54
54
55
my $home = glob ' ~' ;
56
+ my $max_output_len = 290;
55
57
56
58
my %aliases = (
57
59
nom => ' rakudo' ,
@@ -190,6 +192,8 @@ package Evalbot;
190
192
my $evalbot_version = get_revision();
191
193
192
194
my $regex = $prefix . ' (' . join (' |' , keys (%impls ), keys (%aliases )) . " )$postfix " ;
195
+ my $format_res = " %s : OUTPUT«%s »\n " ;
196
+ my $format_nores = " %s : ( no output )\n " ;
193
197
194
198
sub help {
195
199
return " Usage: <$regex \$ perl6_program>" ;
@@ -223,8 +227,7 @@ package Evalbot;
223
227
}
224
228
my $result = ' ' ;
225
229
while (my ($text , $names ) = each %results ){
226
- $result .= join (' , ' , @$names );
227
- $result .= sprintf (" : %s \n " , $text );
230
+ $result .= format_output(join (' , ' , @$names ), $text );
228
231
}
229
232
return $result ;
230
233
}
@@ -238,7 +241,7 @@ package Evalbot;
238
241
if (reftype($e ) eq ' HASH' && $e -> {revision }){
239
242
$revision = ' ' . $e -> {revision }-> ();
240
243
}
241
- return sprintf " %s%s : %s " , $eval_name , $revision , $result ;
244
+ return format_output( " $eval_name$revision " , $result ) ;
242
245
} elsif ( $message =~ m /\A evalbot\s *control\s +(\w +)/ ) {
243
246
my $command = $1 ;
244
247
if ($command eq ' restart' ){
@@ -261,6 +264,27 @@ package Evalbot;
261
264
return ;
262
265
}
263
266
267
+ sub format_output {
268
+ my ($prefix , $response ) = @_ ;
269
+
270
+ if (!length $response ) {
271
+ return sprintf $format_nores , $response ;
272
+ }
273
+
274
+ my $newline = ' ' ;
275
+ my $null = " \N{SYMBOL FOR NULL} " ;
276
+ $response =~ s /\n / $newline / g ;
277
+ $response =~ s /\x00 / $null / g ;
278
+
279
+ my $format_len = bytes::length (sprintf $format_res , $prefix , ' ' );
280
+ if (bytes::length ($response ) + $format_len > $max_output_len ){
281
+ my $target = $max_output_len - 3 - $format_len ;
282
+ $response = substr $response , 0, $target ;
283
+ $response .= ' …' ;
284
+ }
285
+ return sprintf $format_res , $prefix , $response ;
286
+ }
287
+
264
288
sub get_revision {
265
289
qx/ git log --pretty=%h -1/ ;
266
290
}
@@ -321,7 +345,7 @@ package main;
321
345
$revision = ' ' . $e -> {revision }-> ();
322
346
}
323
347
binmode STDOUT , ' :utf8' ;
324
- printf " %s%s : %s \n " , $eval_name , $revision , $result ;
348
+ print Evalbot::format_output( " $eval_name$revision " , $result ) ;
325
349
exit 0;
326
350
}
327
351
0 commit comments