From 9521f69e11e68a5fdc855c738f4cf500f5ccad7a Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Wed, 14 Mar 2018 12:11:53 +0200 Subject: [PATCH 1/3] dump-asy.pl: Add POD usage --- contrib/dump-asy.pl | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/contrib/dump-asy.pl b/contrib/dump-asy.pl index 9bb2db3a..54a1e490 100755 --- a/contrib/dump-asy.pl +++ b/contrib/dump-asy.pl @@ -1,22 +1,26 @@ #!/usr/bin/env perl # vim:ts=4:sw=4:expandtab -# renders the layout tree using asymptote -# -# ./dump-asy.pl -# will render the entire tree -# ./dump-asy.pl 'name' -# will render the tree starting from the node with the specified name, -# e.g. ./dump-asy.pl 2 will render workspace 2 and below use strict; use warnings; use Data::Dumper; +use Getopt::Long; +use Pod::Usage; use AnyEvent::I3; use File::Temp; use File::Basename; use v5.10; use IPC::Cmd qw[can_run]; +my %options = ( + help => 0, +); +my $result = GetOptions( + "help|?" => \$options{help}, +); + +pod2usage(-verbose => 2, -exitcode => 0) if $options{help}; + # prerequisites check so we can be specific about failures caused # by not having these tools in the path can_run('asy') or die 'Please install asymptote'; @@ -84,3 +88,23 @@ my $rep = "$tmp"; $rep =~ s/asy$/eps/; my $tmp_dir = dirname($rep); system("cd $tmp_dir && asy $tmp && gv --scale=-1000 --noresize --widgetless $rep && rm $rep"); + +__END__ + +=head1 NAME + +dump-asy.pl - Render the layout tree using asymptote + +=head1 SYNOPSIS + +dump-asy.pl [workspace] + +=head1 EXAMPLE + +Render the entire tree, run: + + ./dump-asy.pl + +Render the tree starting from the node with the specified name, run: + + ./dump-asy.pl 'name' From 883cf4041d6fcccf8d3003ed279d7fc0fa984bce Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Wed, 14 Mar 2018 12:18:58 +0200 Subject: [PATCH 2/3] dump-asy.pl: Add --gv option --- contrib/dump-asy.pl | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/contrib/dump-asy.pl b/contrib/dump-asy.pl index 54a1e490..866cf8e0 100755 --- a/contrib/dump-asy.pl +++ b/contrib/dump-asy.pl @@ -8,14 +8,17 @@ use Getopt::Long; use Pod::Usage; use AnyEvent::I3; use File::Temp; +use File::Spec; use File::Basename; use v5.10; use IPC::Cmd qw[can_run]; my %options = ( + gv => 1, help => 0, ); my $result = GetOptions( + "gv!" => \$options{gv}, "help|?" => \$options{help}, ); @@ -24,7 +27,7 @@ pod2usage(-verbose => 2, -exitcode => 0) if $options{help}; # prerequisites check so we can be specific about failures caused # by not having these tools in the path can_run('asy') or die 'Please install asymptote'; -can_run('gv') or die 'Please install gv'; +can_run('gv') or die 'Please install gv' unless !$options{gv}; my $i3 = i3(); @@ -86,8 +89,13 @@ say $tmp "draw(n" . $root->{id} . ", (0, 0));"; close($tmp); my $rep = "$tmp"; $rep =~ s/asy$/eps/; -my $tmp_dir = dirname($rep); -system("cd $tmp_dir && asy $tmp && gv --scale=-1000 --noresize --widgetless $rep && rm $rep"); +if ($options{gv}) { + my $tmp_dir = dirname($rep); + chdir($tmp_dir); +} +system("asy $tmp"); # Create the .eps file. +system("gv --scale=-1000 --noresize --widgetless $rep && rm $rep") if $options{gv}; +system("rm $tmp"); __END__ @@ -108,3 +116,16 @@ Render the entire tree, run: Render the tree starting from the node with the specified name, run: ./dump-asy.pl 'name' + +=head1 OPTIONS + +=over 8 + +=item B<--gv> + +=item B<--no-gv> + +Enable or disable showing the result through gv. If disabled, an .eps file will +be saved in the current working directory. Enabled by default. + +=back From dda340cbc6bfe38d6071b54512ea5c28ea9d5503 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Wed, 14 Mar 2018 14:43:12 +0200 Subject: [PATCH 3/3] dump-asy.pl: Add --save option --- contrib/dump-asy.pl | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/contrib/dump-asy.pl b/contrib/dump-asy.pl index 866cf8e0..c183db33 100755 --- a/contrib/dump-asy.pl +++ b/contrib/dump-asy.pl @@ -15,10 +15,12 @@ use IPC::Cmd qw[can_run]; my %options = ( gv => 1, + save => undef, help => 0, ); my $result = GetOptions( "gv!" => \$options{gv}, + "save=s" => \$options{save}, "help|?" => \$options{help}, ); @@ -91,10 +93,18 @@ my $rep = "$tmp"; $rep =~ s/asy$/eps/; if ($options{gv}) { my $tmp_dir = dirname($rep); + $options{save} = File::Spec->rel2abs($options{save}) if $options{save}; chdir($tmp_dir); +} else { + $rep = basename($rep); # Output in current dir. } system("asy $tmp"); # Create the .eps file. -system("gv --scale=-1000 --noresize --widgetless $rep && rm $rep") if $options{gv}; +system("gv --scale=-1000 --noresize --widgetless $rep") if $options{gv}; +if ($options{save}) { + system("mv $rep ${options{save}}"); +} elsif ($options{gv}) { + system("rm $rep"); +} system("rm $tmp"); __END__ @@ -117,6 +127,10 @@ Render the tree starting from the node with the specified name, run: ./dump-asy.pl 'name' +Render the entire tree, save in file 'file.eps' and show using gv, run: + + ./dump-asy.pl --save file.eps + =head1 OPTIONS =over 8 @@ -128,4 +142,9 @@ Render the tree starting from the node with the specified name, run: Enable or disable showing the result through gv. If disabled, an .eps file will be saved in the current working directory. Enabled by default. +=item B<--save> + +Save result using the specified file-name. If omitted, no file will be saved +when using '--gv' or a random name will be used when using '--no-gv'. + =back