Text with color / style. Args: text (str, optional): Default unstyled text. Defaults to "". style (Union[str, Style], optional): Base style for text. Defaults to "". justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None. ove
| 116 | |
| 117 | |
| 118 | class Text(JupyterMixin): |
| 119 | """Text with color / style. |
| 120 | |
| 121 | Args: |
| 122 | text (str, optional): Default unstyled text. Defaults to "". |
| 123 | style (Union[str, Style], optional): Base style for text. Defaults to "". |
| 124 | justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None. |
| 125 | overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None. |
| 126 | no_wrap (bool, optional): Disable text wrapping, or None for default. Defaults to None. |
| 127 | end (str, optional): Character to end text with. Defaults to "\\\\n". |
| 128 | tab_size (int): Number of spaces per tab, or ``None`` to use ``console.tab_size``. Defaults to None. |
| 129 | spans (List[Span], optional). A list of predefined style spans. Defaults to None. |
| 130 | """ |
| 131 | |
| 132 | __slots__ = [ |
| 133 | "_text", |
| 134 | "style", |
| 135 | "justify", |
| 136 | "overflow", |
| 137 | "no_wrap", |
| 138 | "end", |
| 139 | "tab_size", |
| 140 | "_spans", |
| 141 | "_length", |
| 142 | ] |
| 143 | |
| 144 | def __init__( |
| 145 | self, |
| 146 | text: str = "", |
| 147 | style: Union[str, Style] = "", |
| 148 | *, |
| 149 | justify: Optional["JustifyMethod"] = None, |
| 150 | overflow: Optional["OverflowMethod"] = None, |
| 151 | no_wrap: Optional[bool] = None, |
| 152 | end: str = "\n", |
| 153 | tab_size: Optional[int] = None, |
| 154 | spans: Optional[List[Span]] = None, |
| 155 | ) -> None: |
| 156 | sanitized_text = strip_control_codes(text) |
| 157 | self._text = [sanitized_text] |
| 158 | self.style = style |
| 159 | self.justify: Optional["JustifyMethod"] = justify |
| 160 | self.overflow: Optional["OverflowMethod"] = overflow |
| 161 | self.no_wrap = no_wrap |
| 162 | self.end = end |
| 163 | self.tab_size = tab_size |
| 164 | self._spans: List[Span] = spans or [] |
| 165 | self._length: int = len(sanitized_text) |
| 166 | |
| 167 | def __len__(self) -> int: |
| 168 | return self._length |
| 169 | |
| 170 | def __bool__(self) -> bool: |
| 171 | return bool(self._length) |
| 172 | |
| 173 | def __str__(self) -> str: |
| 174 | return self.plain |
| 175 |
no outgoing calls