Merge pull request #3175 from orestisf1993/dump-asy
dump-asy.pl: Add options
This commit is contained in:
commit
6cc3a2bfe8
|
@ -1,26 +1,35 @@
|
||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
# vim:ts=4:sw=4:expandtab
|
# 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 strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
use Getopt::Long;
|
||||||
|
use Pod::Usage;
|
||||||
use AnyEvent::I3;
|
use AnyEvent::I3;
|
||||||
use File::Temp;
|
use File::Temp;
|
||||||
|
use File::Spec;
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
use v5.10;
|
use v5.10;
|
||||||
use IPC::Cmd qw[can_run];
|
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},
|
||||||
|
);
|
||||||
|
|
||||||
|
pod2usage(-verbose => 2, -exitcode => 0) if $options{help};
|
||||||
|
|
||||||
# prerequisites check so we can be specific about failures caused
|
# prerequisites check so we can be specific about failures caused
|
||||||
# by not having these tools in the path
|
# by not having these tools in the path
|
||||||
can_run('asy') or die 'Please install asymptote';
|
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();
|
my $i3 = i3();
|
||||||
|
|
||||||
|
@ -82,5 +91,60 @@ say $tmp "draw(n" . $root->{id} . ", (0, 0));";
|
||||||
close($tmp);
|
close($tmp);
|
||||||
my $rep = "$tmp";
|
my $rep = "$tmp";
|
||||||
$rep =~ s/asy$/eps/;
|
$rep =~ s/asy$/eps/;
|
||||||
|
if ($options{gv}) {
|
||||||
my $tmp_dir = dirname($rep);
|
my $tmp_dir = dirname($rep);
|
||||||
system("cd $tmp_dir && asy $tmp && gv --scale=-1000 --noresize --widgetless $rep && rm $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") if $options{gv};
|
||||||
|
if ($options{save}) {
|
||||||
|
system("mv $rep ${options{save}}");
|
||||||
|
} elsif ($options{gv}) {
|
||||||
|
system("rm $rep");
|
||||||
|
}
|
||||||
|
system("rm $tmp");
|
||||||
|
|
||||||
|
__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'
|
||||||
|
|
||||||
|
Render the entire tree, save in file 'file.eps' and show using gv, run:
|
||||||
|
|
||||||
|
./dump-asy.pl --save file.eps
|
||||||
|
|
||||||
|
=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.
|
||||||
|
|
||||||
|
=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
|
||||||
|
|
Loading…
Reference in New Issue