MCPcopy Create free account
hub / github.com/astanin/python-tabulate / _update_lines

Method _update_lines

tabulate/__init__.py:2758–2783  ·  view source on GitHub ↗

Adds a new line to the list of lines the text is being wrapped into This function will also track any ANSI color codes in this string as well as add any colors from previous lines order to preserve the same formatting as a single unwrapped string.

(self, lines, new_line)

Source from the content-addressed store, hash-verified

2756 return len(stripped)
2757
2758 def _update_lines(self, lines, new_line):
2759 """Adds a new line to the list of lines the text is being wrapped into
2760 This function will also track any ANSI color codes in this string as well
2761 as add any colors from previous lines order to preserve the same formatting
2762 as a single unwrapped string.
2763 """
2764 code_matches = [x for x in _ansi_codes.finditer(new_line)]
2765 color_codes = [
2766 code.string[code.span()[0] : code.span()[1]] for code in code_matches
2767 ]
2768
2769 # Add color codes from earlier in the unwrapped line, and then track any new ones we add.
2770 new_line = "".join(self._active_codes) + new_line
2771
2772 for code in color_codes:
2773 if code != _ansi_color_reset_code:
2774 self._active_codes.append(code)
2775 else: # A single reset code resets everything
2776 self._active_codes = []
2777
2778 # Always ensure each line is color terminated if any colors are
2779 # still active, otherwise colors will bleed into other cells on the console
2780 if len(self._active_codes) > 0:
2781 new_line = new_line + _ansi_color_reset_code
2782
2783 lines.append(new_line)
2784
2785 def _handle_long_word(self, reversed_chunks, cur_line, cur_len, width):
2786 """_handle_long_word(chunks : [string],

Callers 1

_wrap_chunksMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected