File: import-lab-tree-color.sh

package info (click to toggle)
mercurial 7.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 45,080 kB
  • sloc: python: 208,589; ansic: 56,460; tcl: 3,715; sh: 1,839; lisp: 1,483; cpp: 864; makefile: 769; javascript: 649; xml: 36
file content (30 lines) | stat: -rwxr-xr-x 862 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh
#
# add color to the output of `importlab --trim --tree`
#
# cycles are flagged with `cycle {}` so we make the "cycle" red and the content
# of the cycle yellow to make them easy to spot.
#
# the module starting with '::' are internal module that we don't really care
# about (the subgraph is filtered by `--trim`)
#
# The "+" before module mark "direct" (vs "local") import and we don't really
# care about that.
#
# We replace new lines by null bytes during process as it is easier to have sed
# not do multiline work.

if [ -z "$TERM" ]; then
    TERM=ansi
    export TERM
fi

RED="$(tput setaf 1)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BLACK="$(tput sgr0)"
tr '\n' '\0' \
  | sed 's/\bcycle\b/'${RED}'\0'${BLACK}'/g' \
  | sed -E 's/\{[^{]+\}/'${YELLOW}'\0'${BLACK}'/g' \
  | sed 's,:: [^\x0]*,'${BLUE}'\0'${BLACK}',g' \
  | tr '\0' '\n'