From e025f3b9e63c6e737e848bc824f7bcdaef66dd58 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 23 Nov 2012 20:29:52 +0100 Subject: [PATCH] dump-asy: implement filtering by name, present nodes better where "better" means that we no longer use (name, orientation, window-id), but "name" (leaf) or "name" (horizontal-split) for example. --- contrib/dump-asy.pl | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/contrib/dump-asy.pl b/contrib/dump-asy.pl index 3b989bd7..47239f2d 100755 --- a/contrib/dump-asy.pl +++ b/contrib/dump-asy.pl @@ -1,6 +1,12 @@ #!/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; @@ -26,7 +32,13 @@ sub dump_node { my $w = (defined($n->{window}) ? $n->{window} : "N"); my $na = $n->{name}; $na =~ s/#/\\#/g; - my $name = "($na, $o, $w)"; + $na =~ s/_/\\_/g; + $na =~ s/~/\\textasciitilde{}/g; + my $type = 'leaf'; + if (!defined($n->{window})) { + $type = $n->{orientation} . '-split'; + } + my $name = qq|\\"$na\\" ($type)|; print $tmp "TreeNode n" . $n->{id} . " = makeNode("; @@ -36,8 +48,27 @@ sub dump_node { dump_node($_, $n) for @{$n->{nodes}}; } -dump_node($tree); -say $tmp "draw(n" . $tree->{id} . ", (0, 0));"; +sub find_node_with_name { + my ($node, $name) = @_; + + return $node if ($node->{name} eq $name); + for my $child (@{$node->{nodes}}) { + my $res = find_node_with_name($child, $name); + return $res if defined($res); + } + return undef; +} + +my $start = shift; +my $root; +if ($start) { + # Find the specified node in the tree + $root = find_node_with_name($tree, $start); +} else { + $root = $tree; +} +dump_node($root); +say $tmp "draw(n" . $root->{id} . ", (0, 0));"; close($tmp); my $rep = "$tmp"; -- 2.39.5