How to use texttable - 10 common examples

To help you get started, we’ve selected a few texttable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bufordtaylor / python-texttable / texttable.py View on Github external
missing = max_cell_lines - len(cell)
                cell[:0] = [""] * (missing // 2)
                cell.extend([""] * (missing // 2 + missing % 2))
            elif valign == "b":
                cell[:0] = [""] * (max_cell_lines - len(cell))
            else:
                cell.extend([""] * (max_cell_lines - len(cell)))
        return line_wrapped

if __name__ == '__main__':
    table = Texttable()
    table.set_cols_align(["l", "r", "c"])
    table.set_cols_valign(["t", "m", "b"])
    table.add_rows([ [get_color_string(bcolors.GREEN, "Name Of Person"), "Age", "Nickname"],
                     ["Mr\nXavier\nHuon", 32, "Xav'"],
                     [get_color_string(bcolors.BLUE,"Mr\nBaptiste\nClement"), 1, get_color_string(bcolors.RED,"Baby")] ])
    print(table.draw() + "\n")

    table = Texttable()
    table.set_deco(Texttable.HEADER)
    table.set_cols_dtype(['t',  # text
                          'f',  # float (decimal)
                          'e',  # float (exponent)
                          'i',  # integer
                          'a']) # automatic
    table.set_cols_align(["l", "r", "r", "r", "l"])
    table.add_rows([['text',    "float", "exp", "int", "auto"],
                    ["abcd",    "67",    654,   89,    128.001],
                    ["efghijk", 67.5434, .654,  89.6,  12800000000000000000000.00023],
                    ["lmn",     5e-78,   5e-78, 89.4,  .000000000000128],
                    ["opqrstu", .023,    5e+78, 92.,   12800000000000000000000]])
    print(table.draw())
github bufordtaylor / python-texttable / texttable.py View on Github external
valign = "t"
            if valign == "m":
                missing = max_cell_lines - len(cell)
                cell[:0] = [""] * (missing // 2)
                cell.extend([""] * (missing // 2 + missing % 2))
            elif valign == "b":
                cell[:0] = [""] * (max_cell_lines - len(cell))
            else:
                cell.extend([""] * (max_cell_lines - len(cell)))
        return line_wrapped

if __name__ == '__main__':
    table = Texttable()
    table.set_cols_align(["l", "r", "c"])
    table.set_cols_valign(["t", "m", "b"])
    table.add_rows([ [get_color_string(bcolors.GREEN, "Name Of Person"), "Age", "Nickname"],
                     ["Mr\nXavier\nHuon", 32, "Xav'"],
                     [get_color_string(bcolors.BLUE,"Mr\nBaptiste\nClement"), 1, get_color_string(bcolors.RED,"Baby")] ])
    print(table.draw() + "\n")

    table = Texttable()
    table.set_deco(Texttable.HEADER)
    table.set_cols_dtype(['t',  # text
                          'f',  # float (decimal)
                          'e',  # float (exponent)
                          'i',  # integer
                          'a']) # automatic
    table.set_cols_align(["l", "r", "r", "r", "l"])
    table.add_rows([['text',    "float", "exp", "int", "auto"],
                    ["abcd",    "67",    654,   89,    128.001],
                    ["efghijk", 67.5434, .654,  89.6,  12800000000000000000000.00023],
                    ["lmn",     5e-78,   5e-78, 89.4,  .000000000000128],
github foutaise / texttable / tests.py View on Github external
def test_chaining():
    table = Texttable()
    table.reset()
    table.set_max_width(50)
    table.set_chars(list('-|+='))
    table.set_deco(Texttable.BORDER)
    table.set_header_align(list('lll'))
    table.set_cols_align(list('lll'))
    table.set_cols_valign(list('mmm'))
    table.set_cols_dtype(list('ttt'))
    table.set_cols_width([3, 3, 3])
    table.set_precision(3)
    table.header(list('abc'))
    table.add_row(list('def'))
    table.add_rows([list('ghi')], False)
    s1 = table.draw()
    s2 = (Texttable()
          .reset()
          .set_max_width(50)
          .set_chars(list('-|+='))
          .set_deco(Texttable.BORDER)
          .set_header_align(list('lll'))
github grow / grow / grow / deployments / tests.py View on Github external
def print_results(results):
    for message in results.test_results:
        if message.result == messages.Result.PASS:
            color = texttable.bcolors.GREEN
        elif message.result == messages.Result.FAIL:
            color = texttable.bcolors.GREEN
        else:
            color = texttable.bcolors.YELLOW
        label = texttable.get_color_string(color, message.result)
        logging.info('{} {}'.format(label, message.title))
github grow / grow / grow / deployments / tests.py View on Github external
def print_results(results):
    for message in results.test_results:
        if message.result == messages.Result.PASS:
            color = texttable.bcolors.GREEN
        elif message.result == messages.Result.FAIL:
            color = texttable.bcolors.GREEN
        else:
            color = texttable.bcolors.YELLOW
        label = texttable.get_color_string(color, message.result)
        logging.info('{} {}'.format(label, message.title))
github grow / grow / grow / deployments / tests.py View on Github external
def print_results(results):
    for message in results.test_results:
        if message.result == messages.Result.PASS:
            color = texttable.bcolors.GREEN
        elif message.result == messages.Result.FAIL:
            color = texttable.bcolors.GREEN
        else:
            color = texttable.bcolors.YELLOW
        label = texttable.get_color_string(color, message.result)
        logging.info('{} {}'.format(label, message.title))
github bufordtaylor / python-texttable / texttable.py View on Github external
def _splitit(self, line, isheader):
        """Split each element of line to fit the column width

        Each element is turned into a list, result of the wrapping of the
        string to the desired width
        """

        line_wrapped = []
        for cell, width in zip(line, self._width):
            array = []
            original_cell = cell
            lost_color = bcolors.WHITE
            for attr in bcolors_public_props():
                cell = cell.replace(
                    getattr(bcolors, attr), '').replace(bcolors.ENDC,'')
                if cell.replace(bcolors.ENDC,'') != original_cell.replace(
                        bcolors.ENDC,'') and attr != 'ENDC':
                    if not lost_color:
                        lost_color = attr
            for c in cell.split('\n'):
                if type(c) is not str:
                    try:
                        c = str(c, 'utf')
                    except UnicodeDecodeError as strerror:
                        sys.stderr.write("UnicodeDecodeError exception for string '%s': %s\n" % (c, strerror))
                        c = str(c, 'utf', 'replace')
                try:
                    array.extend(
github grow / grow / grow / deployments / indexes.py View on Github external
    @classmethod
    def _make_diff_row(cls, color, label, message):
        label = texttable.get_color_string(color, label)
        path = texttable.get_color_string(
            texttable.bcolors.WHITE, message.path)
        formatted_author = cls._format_author(message.deployed_by, True)
        deployed = str(message.deployed).split('.')[0][
            :-3] if message.deployed else ''
        return [label, path, deployed, formatted_author]
github bufordtaylor / python-texttable / texttable.py View on Github external
def _len_cell(self, cell):
        """Return the width of the cell

        Special characters are taken into account to return the width of the
        cell, such like newlines and tabs
        """

        for attr in bcolors_public_props():
            cell = cell.replace(getattr(bcolors, attr), '').replace(bcolors.ENDC,'')

        cell_lines = cell.split('\n')
        maxi = 0
        for line in cell_lines:
            length = 0
            parts = line.split('\t')
            for part, i in zip(parts, list(range(1, len(parts) + 1))):
                for attr in bcolors_public_props():
                    part = part.replace(getattr(bcolors, attr), '')
                length = length + len(part)
                if i < len(parts):
                    length = (length//8 + 1) * 8
            maxi = max(maxi, length)
        return maxi
github cisco-system-traffic-generator / trex-core / scripts / automation / trex_control_plane / interactive / trex / console / trex_tui.py View on Github external
def ascii_split (s):
    output = []

    lines = s.split('\n')
    for elem in lines:
        if ansi_len(elem) > 0:
            output.append(elem)

    return output