Ejemplo n.º 1
0
 def read_chunk(self) -> StyleAndTextTuples:
     " Read data from input. Return a list of token/text tuples. "
     try:
         return explode_text_fragments(next(self.generator))
     except StopIteration:
         self._eof = True
         return []
Ejemplo n.º 2
0
 def read_chunk(self):
     " Read data from input. Return a list of token/text tuples. "
     try:
         return explode_text_fragments(next(self.generator))
     except StopIteration:
         self._eof = True
         return []
Ejemplo n.º 3
0
def _trim_formatted_text(formatted_text: StyleAndTextTuples,
                         max_width: int) -> Tuple[StyleAndTextTuples, int]:
    """
    Trim the text to `max_width`, append dots when the text is too long.
    Returns (text, width) tuple.
    """
    width = fragment_list_width(formatted_text)

    # When the text is too wide, trim it.
    if width > max_width:
        result = []  # Text fragments.
        remaining_width = max_width - 3

        for style_and_ch in explode_text_fragments(formatted_text):
            ch_width = get_cwidth(style_and_ch[1])

            if ch_width <= remaining_width:
                result.append(style_and_ch)
                remaining_width -= ch_width
            else:
                break

        result.append(("", "..."))

        return result, max_width - remaining_width
    else:
        return formatted_text, width
Ejemplo n.º 4
0
    def apply_transformation(self, transformation_input):
        (
            buffer_control,
            document,
            lineno,
            source_to_display,
            fragments,
            _,
            _,
        ) = transformation_input.unpack()

        if self.selected_entries and not get_app().is_done:
            # For each search match, replace the style string.
            line_text = fragment_list_to_text(fragments)
            fragments = explode_text_fragments(fragments)

            pattern = "|".join(re.escape(key) for key in self.selected_entries)
            matches = re.finditer(pattern, line_text, flags=re.RegexFlag(0))

            for match in matches:
                for i in range(match.start(), match.end()):
                    old_fragment, text, *_ = fragments[i]
                    fragments[i] = (
                        old_fragment + self.match_fragment,
                        fragments[i][1],
                    )

        return Transformation(fragments)
def _trim_formatted_text(formatted_text, max_width):
    """
    Trim the text to `max_width`, append dots when the text is too long.
    Returns (text, width) tuple.
    """
    width = fragment_list_width(formatted_text)

    # When the text is too wide, trim it.
    if width > max_width:
        result = []  # Text fragments.
        remaining_width = max_width - 3

        for style_and_ch in explode_text_fragments(formatted_text):
            ch_width = get_cwidth(style_and_ch[1])

            if ch_width <= remaining_width:
                result.append(style_and_ch)
                remaining_width -= ch_width
            else:
                break

        result.append(('', '...'))

        return result, max_width - remaining_width
    else:
        return formatted_text, width
Ejemplo n.º 6
0
 def first_input_line():
     result = []
     for fragment, char in reversed(explode_text_fragments(get_prompt_text())):
         if char == '\n':
             break
         else:
             result.insert(0, (fragment, char))
     return result
 def first_input_line():
     result = []
     for fragment, char in reversed(explode_text_fragments(get_prompt_text())):
         if char == '\n':
             break
         else:
             result.insert(0, (fragment, char))
     return result
 def before():
     result = []
     found_nl = False
     for fragment, char in reversed(explode_text_fragments(get_prompt_text())):
         if found_nl:
             result.insert(0, (fragment, char))
         elif char == '\n':
             found_nl = True
     return result
Ejemplo n.º 9
0
 def before():
     result = []
     found_nl = False
     for fragment, char in reversed(explode_text_fragments(get_prompt_text())):
         if found_nl:
             result.insert(0, (fragment, char))
         elif char == '\n':
             found_nl = True
     return result
Ejemplo n.º 10
0
 def first_input_line() -> StyleAndTextTuples:
     result: StyleAndTextTuples = []
     for fragment, char, *_ in reversed(
             explode_text_fragments(get_prompt_text())):
         if char == '\n':
             break
         else:
             result.insert(0, (fragment, char))
     return result
Ejemplo n.º 11
0
 def before() -> StyleAndTextTuples:
     result: StyleAndTextTuples = []
     found_nl = False
     for fragment, char, *_ in reversed(
             explode_text_fragments(get_prompt_text())):
         if found_nl:
             result.insert(0, (fragment, char))
         elif char == '\n':
             found_nl = True
     return result
Ejemplo n.º 12
0
    def format(self, progress_bar, progress, width):
        label = self._add_suffix(progress.label)
        cwidth = fragment_list_width(label)

        if cwidth > width:
            # It doesn't fit -> scroll task name.
            label = explode_text_fragments(label)
            max_scroll = cwidth - width
            current_scroll = int(time.time() * 3 % max_scroll)
            label = label[current_scroll:]

        return label
    def format(self, progress_bar, progress, width):
        label = self._add_suffix(progress.label)
        cwidth = fragment_list_width(label)

        if cwidth > width:
            # It doesn't fit -> scroll task name.
            label = explode_text_fragments(label)
            max_scroll = cwidth - width
            current_scroll = int(time.time() * 3 % max_scroll)
            label = label[current_scroll:]

        return label
Ejemplo n.º 14
0
    def format(self, progress_bar, progress, width):
        # Get formatted text from nested formatter, and explode it in
        # text/style tuples.
        result = self.formatter.format(progress_bar, progress, width)
        result = explode_text_fragments(to_formatted_text(result))

        # Insert colors.
        result2 = []
        shift = int(time.time() * 3) % len(self.colors)

        for i, (style, text) in enumerate(result):
            result2.append((style + ' ' + self.colors[(i + shift) % len(self.colors)], text))
        return result2
Ejemplo n.º 15
0
    def apply_transformation(self, transformation_input):
        fragments = transformation_input.fragments

        if self.editor_buffer.report_errors:
            for error in self.editor_buffer.report_errors:
                if error.lineno == transformation_input.lineno:
                    fragments = explode_text_fragments(fragments)
                    for i in range(error.start_column, error.end_column):
                        if i < len(fragments):
                            fragments[i] = ('class:flakeserror',
                                            fragments[i][1])

        return Transformation(fragments)
    def format(self, progress_bar, progress, width):
        # Get formatted text from nested formatter, and explode it in
        # text/style tuples.
        result = self.formatter.format(progress_bar, progress, width)
        result = explode_text_fragments(to_formatted_text(result))

        # Insert colors.
        result2 = []
        shift = int(time.time() * 3) % len(self.colors)

        for i, (style, text) in enumerate(result):
            result2.append((style + ' ' + self.colors[(i + shift) % len(self.colors)], text))
        return result2
Ejemplo n.º 17
0
    def format(self, progress_bar: 'ProgressBar',
               progress: 'ProgressBarCounter', width: int) -> AnyFormattedText:

        label = self._add_suffix(progress.label)
        cwidth = fragment_list_width(label)

        if cwidth > width:
            # It doesn't fit -> scroll task name.
            label = explode_text_fragments(label)
            max_scroll = cwidth - width
            current_scroll = int(time.time() * 3 % max_scroll)
            label = label[current_scroll:]

        return label
Ejemplo n.º 18
0
    def format(self, progress_bar: 'ProgressBar',
               progress: 'ProgressBarCounter', width: int) -> AnyFormattedText:

        # Get formatted text from nested formatter, and explode it in
        # text/style tuples.
        result = self.formatter.format(progress_bar, progress, width)
        result = explode_text_fragments(to_formatted_text(result))

        # Insert colors.
        result2: StyleAndTextTuples = []
        shift = int(time.time() * 3) % len(self.colors)

        for i, (style, text, *_) in enumerate(result):
            result2.append(
                (style + ' ' + self.colors[(i + shift) % len(self.colors)],
                 text))
        return result2
Ejemplo n.º 19
0
 def read_chunk(self):
     if self._read:
         return []
     else:
         self._read = True
         return explode_text_fragments([('', self.text)])
Ejemplo n.º 20
0
 def read_chunk(self):
     if self._read:
         return []
     else:
         self._read = True
         return explode_text_fragments(self.formatted_text)
Ejemplo n.º 21
0
 def read_chunk(self):
     if self._read:
         return []
     else:
         self._read = True
         return explode_text_fragments([('', self.text)])
Ejemplo n.º 22
0
 def read_chunk(self):
     if self._read:
         return []
     else:
         self._read = True
         return explode_text_fragments(self.formatted_text)
Ejemplo n.º 23
0
 def read_chunk(self) -> StyleAndTextTuples:
     if self._read:
         return []
     else:
         self._read = True
         return explode_text_fragments(self.formatted_text)