Debian Codegraph @

contrib/import-lab-tree-color.sh

raw
1 #!/bin/sh
2 #
3 # add color to the output of `importlab --trim --tree`
4 #
5 # cycles are flagged with `cycle {}` so we make the "cycle" red and the content
6 # of the cycle yellow to make them easy to spot.
7 #
8 # the module starting with '::' are internal module that we don't really care
9 # about (the subgraph is filtered by `--trim`)
10 #
11 # The "+" before module mark "direct" (vs "local") import and we don't really
12 # care about that.
13 #
14 # We replace new lines by null bytes during process as it is easier to have sed
15 # not do multiline work.
16
17 if [ -z "$TERM" ]; then
18 TERM=ansi
19 export TERM
20 fi
21
22 RED="$(tput setaf 1)"
23 YELLOW="$(tput setaf 3)"
24 BLUE="$(tput setaf 4)"
25 BLACK="$(tput sgr0)"
26 tr '\n' '\0' \
27 | sed 's/\bcycle\b/'${RED}'\0'${BLACK}'/g' \
28 | sed -E 's/\{[^{]+\}/'${YELLOW}'\0'${BLACK}'/g' \
29 | sed 's,:: [^\x0]*,'${BLUE}'\0'${BLACK}',g' \
30 | tr '\0' '\n'