Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_cell_width(self, row, column):
"""
Gets cell width.
:type row: list
:type column: int
:rtype: int
"""
try:
cell = row[column]
cell_width = Helper.len_without_decoration(self._output.get_formatter(), cell)
if isinstance(cell, TableCell) and cell.colspan > 1:
# we assume that cell value will be across more than one column.
cell_width = cell_width // cell.colspan
return cell_width
except IndexError:
return 0
def _overwrite(self, message):
"""
Overwrites a previous message to the output.
:type message: str
"""
lines = message.split('\n')
# Append whitespace to match the line's length
if self._last_messages_length is not None:
for i, line in enumerate(lines):
if self._last_messages_length > Helper.len_without_decoration(self._output.get_formatter(), line):
lines[i] = line.ljust(self._last_messages_length, '\x20')
if self._should_overwrite:
# move back to the beginning of the progress bar before redrawing it
self._output.write('\x0D')
elif self._step > 0:
# move to new line
self._output.writeln('')
if self._format_line_count:
self._output.write('\033[%dA' % self._format_line_count)
self._output.write('\n'.join(lines))
self._last_messages_length = 0
if self._should_overwrite:
# move back to the beginning of the progress bar before redrawing it
self._output.write('\x0D')
elif self._step > 0:
# move to new line
self._output.writeln('')
if self._format_line_count:
self._output.write('\033[%dA' % self._format_line_count)
self._output.write('\n'.join(lines))
self._last_messages_length = 0
for line in lines:
length = Helper.len_without_decoration(self._output.get_formatter(), line)
if length > self._last_messages_length:
self._last_messages_length = length
width = self._column_widths[column]
if isinstance(cell, TableCell) and cell.colspan > 1:
# add the width of the following columns(numbers of colspan).
for next_column in range(column + 1, column + cell.colspan):
width += self._get_column_separator_width() + self._column_widths[next_column]
# Encoding fix
width += len(cell) - Helper.len(cell)
style = self.get_column_style(column)
if isinstance(cell, TableSeparator):
self._output.write(style.border_format % (style.horizontal_border_char * width))
else:
width += Helper.len(cell) - Helper.len_without_decoration(self._output.get_formatter(), cell)
content = style.cell_row_content_format % cell
self._output.write(cell_format % getattr(content, style.pad_type)(width, style.padding_char))