'Get the syntax highlighting color for the current cursor position'

def __get_current_color(self, cursor=None):

    if (cursor is None):
        cursor = self.textCursor()
    block = cursor.block()
    pos = (cursor.position() - block.position())
    layout = block.layout()
    block_formats = layout.additionalFormats()
    if block_formats:
        if cursor.atBlockEnd():
            current_format = block_formats[(-1)].format
        else:
            current_format = None
            for fmt in block_formats:
                if ((pos >= fmt.start) and (pos < (fmt.start + fmt.length))):
                    current_format = fmt.format
            if (current_format is None):
                return None
        color = current_format.foreground().color().name()
        return color
    else:
        return None
