How to use the texttable.ansi_len function in texttable

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 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
github cisco-system-traffic-generator / trex-core / scripts / automation / trex_control_plane / interactive / trex / console / trex_tui.py View on Github external
# success
                if func_rc is None:
                    self.last_status = format_text("[OK]", 'green')
                # errors
                else:
                    err_msgs = ascii_split(str(func_rc))
                    if not err_msgs:
                        err_msgs = ['Unknown error']
                    self.last_status = format_text(clear_formatting(err_msgs[0]), 'red')
                    if len(err_msgs) > 1:
                        self.last_status += " [{0} more errors messages]".format(len(err_msgs) - 1)
                    color = 'red'


        # trim too long lines
        if ansi_len(self.last_status) > TrexTUI.MIN_COLS:
            self.last_status = format_text(self.last_status[:TrexTUI.MIN_COLS] + "...", color, 'bold')
github cisco-system-traffic-generator / trex-core / scripts / automation / trex_control_plane / stl / trex_stl_lib / trex_stl_client.py View on Github external
self.remove_all_streams(opts.ports)

        # pack the profile
        try:
            for port in opts.ports:

                profile = STLProfile.load(opts.file[0],
                                          direction = tunables.get('direction', port % 2),
                                          port_id = port,
                                          **tunables)

                self.add_streams(profile.get_streams(), ports = port)

        except STLError as e:
            for line in e.brief().splitlines():
                if ansi_len(line.strip()):
                    error = line
            msg = format_text("\nError loading profile '{0}'".format(opts.file[0]), 'bold')
            self.logger.log(msg + '\n')
            self.logger.log(e.brief() + "\n")
            return RC_ERR("%s: %s" % (msg, error))


        if opts.dry:
            self.validate(opts.ports, opts.mult, opts.duration, opts.total)
        else:

            self.start(opts.ports,
                       opts.mult,
                       opts.force,
                       opts.duration,
                       opts.total,