2 # vim:ts=4:sw=4:expandtab
14 use IPC::Cmd qw[can_run];
20 my $result = GetOptions(
21 "gv!" => \$options{gv},
22 "help|?" => \$options{help},
25 pod2usage(-verbose => 2, -exitcode => 0) if $options{help};
27 # prerequisites check so we can be specific about failures caused
28 # by not having these tools in the path
29 can_run('asy') or die 'Please install asymptote';
30 can_run('gv') or die 'Please install gv' unless !$options{gv};
34 my $tree = $i3->get_tree->recv;
36 my $tmp = File::Temp->new(UNLINK => 0, SUFFIX => '.asy');
38 say $tmp "import drawtree;";
40 say $tmp "treeLevelStep = 2cm;";
43 my ($n, $parent) = @_;
45 my $o = ($n->{orientation} eq 'none' ? "u" : ($n->{orientation} eq 'horizontal' ? "h" : "v"));
46 my $w = (defined($n->{window}) ? $n->{window} : "N");
47 my $na = ($n->{name} or "[Empty]");
52 $na =~ s/~/\\textasciitilde{}/g;
54 if (!defined($n->{window})) {
57 my $name = qq|``$na'' ($type)|;
59 print $tmp "TreeNode n" . $n->{id} . " = makeNode(";
61 print $tmp "n" . $parent->{id} . ", " if defined($parent);
62 print $tmp "\"" . $name . "\");\n";
64 dump_node($_, $n) for @{$n->{nodes}};
67 sub find_node_with_name {
68 my ($node, $name) = @_;
70 return $node if ($node->{name} eq $name);
71 for my $child (@{$node->{nodes}}) {
72 my $res = find_node_with_name($child, $name);
73 return $res if defined($res);
81 # Find the specified node in the tree
82 $root = find_node_with_name($tree, $start);
87 say $tmp "draw(n" . $root->{id} . ", (0, 0));";
93 my $tmp_dir = dirname($rep);
96 system("asy $tmp"); # Create the .eps file.
97 system("gv --scale=-1000 --noresize --widgetless $rep && rm $rep") if $options{gv};
104 dump-asy.pl - Render the layout tree using asymptote
108 dump-asy.pl [workspace]
112 Render the entire tree, run:
116 Render the tree starting from the node with the specified name, run:
128 Enable or disable showing the result through gv. If disabled, an .eps file will
129 be saved in the current working directory. Enabled by default.