]> git.sur5r.net Git - i3/i3/blobdiff - contrib/dump-asy.pl
dump-asy.pl: Add POD usage
[i3/i3] / contrib / dump-asy.pl
index 3ebdb858e9ef275d830765b1a54a75639790b6c4..54a1e490f2ac5124097d51ec57f3d878dac339c9 100755 (executable)
@@ -1,19 +1,30 @@
 #!/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';
+can_run('gv') or die 'Please install gv';
 
 my $i3 = i3();
 
@@ -30,7 +41,7 @@ sub dump_node {
 
     my $o = ($n->{orientation} eq 'none' ? "u" : ($n->{orientation} eq 'horizontal' ? "h" : "v"));
     my $w = (defined($n->{window}) ? $n->{window} : "N");
-    my $na = $n->{name};
+    my $na = ($n->{name} or "[Empty]");
     $na =~ s/#/\\#/g;
     $na =~ s/\$/\\\$/g;
     $na =~ s/&/\\&/g;
@@ -38,7 +49,7 @@ sub dump_node {
     $na =~ s/~/\\textasciitilde{}/g;
     my $type = 'leaf';
     if (!defined($n->{window})) {
-        $type = $n->{orientation} . '-split';
+        $type = $n->{layout};
     }
     my $name = qq|``$na'' ($type)|;
 
@@ -75,4 +86,25 @@ say $tmp "draw(n" . $root->{id} . ", (0, 0));";
 close($tmp);
 my $rep = "$tmp";
 $rep =~ s/asy$/eps/;
-system("cd /tmp && asy $tmp && gv --scale=-1000 --noresize --widgetless $rep && rm $rep");
+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'