MCPcopy
hub / github.com/Textualize/rich / add_row

Method add_row

rich/table.py:422–467  ·  rich/table.py::Table.add_row

Add a row of renderables. Args: *renderables (None or renderable): Each cell in a row must be a renderable object (including str), or ``None`` for a blank cell. style (StyleType, optional): An optional style to apply to the entire row. Defaults to Non

(
        self,
        *renderables: Optional["RenderableType"],
        style: Optional[StyleType] = None,
        end_section: bool = False,
    )

Source from the content-addressed store, hash-verified

420 self.columns.append(column)
421
422 def add_row(
423 self,
424 *renderables: Optional[class="st">"RenderableType"],
425 style: Optional[StyleType] = None,
426 end_section: bool = False,
427 ) -> None:
428 class="st">"""Add a row of renderables.
429
430 Args:
431 *renderables (None or renderable): Each cell in a row must be a renderable object (including str),
432 or ``None`` for a blank cell.
433 style (StyleType, optional): An optional style to apply to the entire row. Defaults to None.
434 end_section (bool, optional): End a section and draw a line. Defaults to False.
435
436 Raises:
437 errors.NotRenderableError: If you add something that can&class="cm">#x27;t be rendered.
438 class="st">"""
439
440 def add_cell(column: Column, renderable: class="st">"RenderableType") -> None:
441 column._cells.append(renderable)
442
443 cell_renderables: List[Optional[class="st">"RenderableType"]] = list(renderables)
444
445 columns = self.columns
446 if len(cell_renderables) < len(columns):
447 cell_renderables = [
448 *cell_renderables,
449 *[None] * (len(columns) - len(cell_renderables)),
450 ]
451 for index, renderable in enumerate(cell_renderables):
452 if index == len(columns):
453 column = Column(_index=index, highlight=self.highlight)
454 for _ in self.rows:
455 add_cell(column, Text(class="st">""))
456 self.columns.append(column)
457 else:
458 column = columns[index]
459 if renderable is None:
460 add_cell(column, class="st">"")
461 elif is_renderable(renderable):
462 add_cell(column, renderable)
463 else:
464 raise errors.NotRenderableError(
465 fclass="st">"unable to render {type(renderable).__name__}; a string or other renderable object is required"
466 )
467 self.rows.append(Row(style=style, end_section=end_section))
468
469 def add_section(self) -> None:
470 class="st">""class="st">"Add a new section (draw a line after current row)."class="st">""

Callers 15

render_tablesFunction · 0.95
test_not_renderableFunction · 0.95
test_min_widthFunction · 0.95
test_get_row_styleFunction · 0.95
make_tableFunction · 0.95
test_sectionFunction · 0.95
test_rule_in_ratio_tableFunction · 0.95

Calls 5

ColumnClass · 0.85
TextClass · 0.85
is_renderableFunction · 0.85
RowClass · 0.85
appendMethod · 0.45

Tested by 13

render_tablesFunction · 0.76
test_not_renderableFunction · 0.76
test_min_widthFunction · 0.76
test_get_row_styleFunction · 0.76
make_tableFunction · 0.76
test_sectionFunction · 0.76
test_rule_in_ratio_tableFunction · 0.76