Skip to content

Commit

Permalink
Merge pull request #47 from titsuki/fix-debug-option
Browse files Browse the repository at this point in the history
Fix debug option as it enables to output both user input and reply fr…
  • Loading branch information
titsuki authored Mar 20, 2023
2 parents 06167d0 + 445edf2 commit 818c553
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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 818c553

Please sign in to comment.