Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
_textwrap.py52 linesDownload Raw Back to click
1from __future__ import annotations2 3import collections.abc as cabc4import textwrap5from contextlib import contextmanager6 7 8class TextWrapper(textwrap.TextWrapper):9    def _handle_long_word(10        self,11        reversed_chunks: list[str],12        cur_line: list[str],13        cur_len: int,14        width: int,15    ) -> None:16        space_left = max(width - cur_len, 1)17 18        if self.break_long_words:19            last = reversed_chunks[-1]20            cut = last[:space_left]21            res = last[space_left:]22            cur_line.append(cut)23            reversed_chunks[-1] = res24        elif not cur_line:25            cur_line.append(reversed_chunks.pop())26 27    @contextmanager28    def extra_indent(self, indent: str) -> cabc.Iterator[None]:29        old_initial_indent = self.initial_indent30        old_subsequent_indent = self.subsequent_indent31        self.initial_indent += indent32        self.subsequent_indent += indent33 34        try:35            yield36        finally:37            self.initial_indent = old_initial_indent38            self.subsequent_indent = old_subsequent_indent39 40    def indent_only(self, text: str) -> str:41        rv = []42 43        for idx, line in enumerate(text.splitlines()):44            indent = self.initial_indent45 46            if idx > 0:47                indent = self.subsequent_indent48 49            rv.append(f"{indent}{line}")50 51        return "\n".join(rv)52 
codekingpro/portable-devtools · Team Ai