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.
This commit is contained in:
parent
0560fc7964
commit
e025f3b9e6
|
@ -1,6 +1,12 @@
|
||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
# vim:ts=4:sw=4:expandtab
|
# vim:ts=4:sw=4:expandtab
|
||||||
# renders the layout tree using asymptote
|
# 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 strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
@ -26,7 +32,13 @@ sub dump_node {
|
||||||
my $w = (defined($n->{window}) ? $n->{window} : "N");
|
my $w = (defined($n->{window}) ? $n->{window} : "N");
|
||||||
my $na = $n->{name};
|
my $na = $n->{name};
|
||||||
$na =~ s/#/\\#/g;
|
$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(";
|
print $tmp "TreeNode n" . $n->{id} . " = makeNode(";
|
||||||
|
|
||||||
|
@ -36,8 +48,27 @@ sub dump_node {
|
||||||
dump_node($_, $n) for @{$n->{nodes}};
|
dump_node($_, $n) for @{$n->{nodes}};
|
||||||
}
|
}
|
||||||
|
|
||||||
dump_node($tree);
|
sub find_node_with_name {
|
||||||
say $tmp "draw(n" . $tree->{id} . ", (0, 0));";
|
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);
|
close($tmp);
|
||||||
my $rep = "$tmp";
|
my $rep = "$tmp";
|
||||||
|
|
Loading…
Reference in New Issue