import pprint
import re
import typing

import msgpack


from mitmproxy.contentviews import base

PARSE_ERROR = object()


def parse_msgpack(s: bytes) -> typing.Any:
    try:
        return msgpack.unpackb(s, raw=False)
    except (ValueError, msgpack.ExtraData, msgpack.FormatError, msgpack.StackError):
        return PARSE_ERROR


def format_msgpack(data):
    current_line: base.TViewLine = []
    current_line.append(("text", pprint.pformat(data, indent=4)))
    yield current_line


class ViewMsgPack(base.View):
    name = "MsgPack"
    content_types = [
        "application/msgpack",
        "application/x-msgpack",
    ]

    def __call__(self, data, **metadata):
        data = parse_msgpack(data)
        if data is not PARSE_ERROR:
            return "MsgPack", format_msgpack(data)

@@ -334,156 +334,664 @@
 def 
-format_msgpack(data):%0A    current_line: base.TViewLine = %5B%5D%0A    current_line.append((%22text%22, pprint.pformat(data,
+pretty(value, htchar=%22    %22, lfchar=%22%5Cn%22, indent=0):%0A    nlch = lfchar + htchar * (indent + 1)%0A    if type(value) is dict:%0A        items = %5B%0A            nlch + repr(key) + %22: %22 + pretty(value%5Bkey%5D, htchar, lfchar, indent + 1)%0A            for key in value%0A        %5D%0A        return %22%7B%25s%7D%22 %25 (%22,%22.join(items) + lfchar + htchar * indent)%0A    elif type(value) is list:%0A        items = %5B%0A            nlch + pretty(item, htchar, lfchar, indent + 1)%0A            for item in value%0A        %5D%0A        return %22%5B%25s%5D%22 %25 (%22,%22.join(items) + lfchar + htchar *
  indent
-=4))
 )%0A    
-yield current_line
+else:%0A        return repr(value)%0A%0Adef format_msgpack(data):%0A    return base.format_text(pretty(data))
 %0A%0A%0Ac

Improve the formatting of the msgpack content viewer.