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

Class StyleStack

rich/style.py:765–796  ·  view source on GitHub ↗

A stack of styles.

Source from the content-addressed store, hash-verified

763
764
765class StyleStack:
766 """A stack of styles."""
767
768 __slots__ = ["_stack"]
769
770 def __init__(self, default_style: "Style") -> None:
771 self._stack: List[Style] = [default_style]
772
773 def __repr__(self) -> str:
774 return f"<stylestack {self._stack!r}>"
775
776 @property
777 def current(self) -> Style:
778 """Get the Style at the top of the stack."""
779 return self._stack[-1]
780
781 def push(self, style: Style) -> None:
782 """Push a new style on to the stack.
783
784 Args:
785 style (Style): New style to combine with current style.
786 """
787 self._stack.append(self._stack[-1] + style)
788
789 def pop(self) -> Style:
790 """Pop last style and discard.
791
792 Returns:
793 Style: New current style (also available as stack.current)
794 """
795 self._stack.pop()
796 return self._stack[-1]

Callers 3

test_style_stackFunction · 0.90
__rich_console__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by 1

test_style_stackFunction · 0.72