From a3e0ce53a970bdbd0cacef13d4d7bccef27711a0 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 13 Apr 2010 20:20:03 +0200 Subject: [PATCH] add dump-asy.pl, renders the tree with asymptote --- dump-asy.pl | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 dump-asy.pl diff --git a/dump-asy.pl b/dump-asy.pl new file mode 100755 index 00000000..343a39c4 --- /dev/null +++ b/dump-asy.pl @@ -0,0 +1,45 @@ +#!/usr/bin/env perl +# vim:ts=4:sw=4:expandtab +# renders the layout tree using asymptote + +use strict; +use warnings; +use Data::Dumper; +use AnyEvent::I3; +use File::Temp; +use v5.10; + +my $i3 = i3("/tmp/nestedcons"); + +my $tree = $i3->get_workspaces->recv; + +my $tmp = File::Temp->new(UNLINK => 0, SUFFIX => '.asy'); + +say $tmp "import drawtree;"; + +say $tmp "treeLevelStep = 2cm;"; + +sub dump_node { + my ($n, $parent) = @_; + + my $o = ($n->{orientation} == 0 ? "h" : "v"); + my $w = (defined($n->{window}) ? $n->{window} : "N"); + my $na = $n->{name}; + $na =~ s/#/\\#/g; + my $name = "($na, $o, $w)"; + + 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($tree); +say $tmp "draw(n" . $tree->{id} . ", (0, 0));"; + +close($tmp); +my $rep = "$tmp"; +$rep =~ s/asy$/eps/; +system("cd /tmp && asy $tmp && gv $rep && rm $rep"); -- 2.39.5