Write text to the underlying stream, prefixing the start of each line. Args: text (str): The text to write. Returns: int: The number of characters of the original text written.
(self, text: str)
| 175 | self._at_line_start = True |
| 176 | |
| 177 | def write(self, text: str) -> int: |
| 178 | """ |
| 179 | Write text to the underlying stream, prefixing the start of each line. |
| 180 | |
| 181 | Args: |
| 182 | text (str): The text to write. |
| 183 | |
| 184 | Returns: |
| 185 | int: The number of characters of the original text written. |
| 186 | """ |
| 187 | if not text: |
| 188 | return 0 |
| 189 | |
| 190 | chunks: list[str] = [] |
| 191 | for char in text: |
| 192 | if self._at_line_start and char != "\n": |
| 193 | chunks.append(self._prefix) |
| 194 | self._at_line_start = False |
| 195 | chunks.append(char) |
| 196 | if char == "\n": |
| 197 | self._at_line_start = True |
| 198 | |
| 199 | self._stream.write("".join(chunks)) |
| 200 | return len(text) |
| 201 | |
| 202 | def __getattr__(self, name: str) -> Any: |
| 203 | """ |
no outgoing calls