#!/usr/bin/env zsh

vertical_label()
{
	c=$3
	ce="\x1b[0m"
	label=$2
	i=1
	# The `s/^/x/' marks each line's beginning with a non-whitespace character
	# `x' so that when we pipe it to the `read' zsh builtin, we read all leading
	# indentation as well (otherwise we lose it). The `s/\t/ /g' standardizes
	# all tab characters to four spaces; this is purely for visual aesthetics.
	eval $1 | sed  's/^/x/ ; s/\t/    /g ; s/%/%%%%/g' | while read -r line; do
		case $label[$i] in
		" ") printf "  " ;;
		"-") printf " $c\u2503$ce" ;;
		*) printf " $c$label[$i]$ce" ;;
		esac
		line_without_x=$line[2,-1]
		printf "  ${line_without_x//\\/\\\\\\\\}\n"
		((i+=1))
		if (( i > $#label )); then
			i=1
		fi
	done
}
