Skip to content

Commit

Permalink
Fix debug option as it enables to output both user input and reply fr…
Browse files Browse the repository at this point in the history
…om gnuplot
  • Loading branch information
titsuki committed Mar 20, 2023
1 parent 06167d0 commit d29358b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Binary file modified histogram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions lib/Chart/Gnuplot.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,13 @@ method multiplot(:$title, :$font-name, :$font-size, Bool :$enhanced, :@layout, :
method dispose {
self.command: "exit";
$!gnuplot.close-stdin;
await $!promise;
try sink await $!promise;
}

method command(Str $command) {
method command(Str $command, :$stderr = $*ERR) {
if $!debug {
$stderr.say: $command;
}
try sink await $!gnuplot.say: $command;
}

Expand Down
8 changes: 8 additions & 0 deletions t/01-basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ use Chart::Gnuplot;
}, "Chart::Gnuplot.new should create a new instance."
}

{
my $msg;
my $gnu = Chart::Gnuplot.new(:terminal("png"), :filename("sample.svg"), :debug);
$gnu.command("set terminal svg", :stderr(class { method print(*@args){ $msg ~= @args.join; }; method flush{}}));
sleep .5;
ok $msg ~~ "set terminal svg\n", "Chart::Gnuplot.command should print given command to stderr with newline when debug option is enabled.";
}

done-testing;

0 comments on commit d29358b

Please sign in to comment.