def _writemsgwith(write, dest, *args, **opts):
    """Write ui message with the given ui._write*() function

    The specified message type is translated to 'ui.<type>' label if the dest
    isn't a structured channel, so that the message will be colorized.
    """
    if 'type' in opts and not getattr(dest, 'structured', False):
        opts['label'] = opts.get('label', b'') + b' ui.%s' % opts.pop('type')
    write(dest, *args, **opts)
