2 # vim:ts=4:sw=4:expandtab
13 use IPC::Cmd qw[can_run];
18 my $result = GetOptions(
19 "help|?" => \$options{help},
22 pod2usage(-verbose => 2, -exitcode => 0) if $options{help};
24 # prerequisites check so we can be specific about failures caused
25 # by not having these tools in the path
26 can_run('asy') or die 'Please install asymptote';
27 can_run('gv') or die 'Please install gv';
31 my $tree = $i3->get_tree->recv;
33 my $tmp = File::Temp->new(UNLINK => 0, SUFFIX => '.asy');
35 say $tmp "import drawtree;";
37 say $tmp "treeLevelStep = 2cm;";
40 my ($n, $parent) = @_;
42 my $o = ($n->{orientation} eq 'none' ? "u" : ($n->{orientation} eq 'horizontal' ? "h" : "v"));
43 my $w = (defined($n->{window}) ? $n->{window} : "N");
44 my $na = ($n->{name} or "[Empty]");
49 $na =~ s/~/\\textasciitilde{}/g;
51 if (!defined($n->{window})) {
54 my $name = qq|``$na'' ($type)|;
56 print $tmp "TreeNode n" . $n->{id} . " = makeNode(";
58 print $tmp "n" . $parent->{id} . ", " if defined($parent);
59 print $tmp "\"" . $name . "\");\n";
61 dump_node($_, $n) for @{$n->{nodes}};
64 sub find_node_with_name {
65 my ($node, $name) = @_;
67 return $node if ($node->{name} eq $name);
68 for my $child (@{$node->{nodes}}) {
69 my $res = find_node_with_name($child, $name);
70 return $res if defined($res);
78 # Find the specified node in the tree
79 $root = find_node_with_name($tree, $start);
84 say $tmp "draw(n" . $root->{id} . ", (0, 0));";
89 my $tmp_dir = dirname($rep);
90 system("cd $tmp_dir && asy $tmp && gv --scale=-1000 --noresize --widgetless $rep && rm $rep");
96 dump-asy.pl - Render the layout tree using asymptote
100 dump-asy.pl [workspace]
104 Render the entire tree, run:
108 Render the tree starting from the node with the specified name, run: