Make the text representation of a report data element.

def make_text(self, width):
        """
        Make the text representation of a report data element.
        """
        def mformat(reslist):
            _text = ""
            _buffer = reslist[0]
            for j in range(1, len(reslist)):
                if (_buffer == "") or (len(_buffer) + len(reslist[j])) <= (width - len(filling)):
                    if reslist[j][0] == '[' and reslist[j][-1] == ']':
                        _buffer = '{0} {1}'.format(_buffer, reslist[j])
                    else:
                        _buffer = '{0}, {1}'.format(_buffer, reslist[j])
                else:
                    _text = '{0}{1}\n{2}'.format(_text, _buffer, filling)
                    _buffer = reslist[j]
            _text = '{0}{1}'.format(_text, _buffer)
            return _text

        text = '\n----- {0} -----\n\n'.format(self.title.strip())

        if self.function == 'total':
            width1 = max(len(res[0]) for res in self.results if res is not None)
            for res in self.results:
                padding = ' ' * (width1 - len(res[0]) + 1)
                text = '{0}{1}{2}| {3}\n'.format(text, res[0], padding, res[1])
                
        elif self.function == 'top':
            if self.results[0] is not None:
                width1 = max(len(res[0]) for res in self.results if res is not None)
                width2 = min([width-width1-4,
                              max(len(', '.join(res[1])) for res in self.results if res is not None)])

                text = '{0}{1} | {2}\n'.format(text, ' ' * width1, self.headers.strip('"'))
                text = '{0}{1}-+-{2}-\n'.format(text, '-' * width1, '-' * width2)

                for res in self.results:
                    if res is not None:
                        padding = ' ' * (width1 - len(res[0]) + 1)
                        filling = '{0}| '.format(' ' * (width1 + 1))
                        lastcol = mformat(res[1])
                        text = '{0}{1}{2}| {3}\n'.format(text, res[0], padding, lastcol)
            else:
                text = '{0} {1}\n'.format(text, 'None')
                    
        elif self.function == 'table':
            headers = re.split('\s*,\s*', self.headers)

            colwidth = []
            for i in range(len(headers)-1):
                colwidth.append(max([len(headers[i]), max(len(res[i]) for res in self.results)]))

            for i in range(len(headers)-1):
                text = '{0}{1}{2}| '\
                            .format(text, headers[i].strip('"'), ' ' * (colwidth[i]-len(headers[i])+2))

            text = '{0}{1}\n'.format(text, headers[-1].strip('"'))
            text = '{0}{1}\n'.format(text, '-' * (width-1))

            filling = ""
            for i in range(len(headers)-1):
                filling = '{0}{1}| '.format(filling, ' ' * colwidth[i])
            
            for res in sorted(self.results, key=lambda x: x[0]):
                for i in range(len(headers)-1):
                    text = '{0}{1}{2}| '.format(text, res[i], ' ' * (colwidth[i]-len(res[i])))
                lastcol = get_fmt_results(res[-1], limit=5)
                text = '{0}{1}\n'.format(text, mformat(lastcol))
        self.text = text