Implement IO.ANSI format/2 and format_fragment/2

Fixes #2550.