port PrettyListing class from Homebrew-fork

and simplify it considerably
Merge pull request #8189 from rolandwalker/port_homebrew_prettylisting

port PrettyListing class from Homebrew-fork