]> git.sur5r.net Git - i3/i3/blobdiff - contrib/dump-asy.pl
Merge pull request #3497 from stapelberg/clang-format
[i3/i3] / contrib / dump-asy.pl
index 866cf8e0361979ca652cb82c1451956215f9c5d0..5af4c72f313763a7fb6a459ba59cada1d273d2c2 100755 (executable)
@@ -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},
 );
 
@@ -44,7 +46,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} or "[Empty]");
+    my $na = ($n->{name} or ($n->{type} eq "floating_con" ? "[Floating con]" : "[Empty]"));
     $na =~ s/#/\\#/g;
     $na =~ s/\$/\\\$/g;
     $na =~ s/&/\\&/g;
@@ -54,14 +56,16 @@ sub dump_node {
     if (!defined($n->{window})) {
         $type = $n->{layout};
     }
-    my $name = qq|``$na'' ($type)|;
+    my $marks = $n->{marks} ? ' [' . join('][', @{$n->{marks}}) . ']' : '';
+    my $name = qq|``$na'' ($type)$marks|;
 
     print $tmp "TreeNode n" . $n->{id} . " = makeNode(";
 
     print $tmp "n" . $parent->{id} . ", " if defined($parent);
     print $tmp "\"" . $name . "\");\n";
 
-       dump_node($_, $n) for @{$n->{nodes}};
+    dump_node($_, $n) for @{$n->{nodes}};
+    dump_node($_, $n) for @{$n->{floating_nodes}};
 }
 
 sub find_node_with_name {
@@ -91,10 +95,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 +129,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 +144,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