コード例 #1
0
 def send_above_prompt(self, formatted_text):
     """
     Send text to the client.
     This is asynchronous, returns a `Future`.
     """
     formatted_text = to_formatted_text(formatted_text)
     return self._run_in_terminal(lambda: self.send(formatted_text))
コード例 #2
0
def print_formatted_text(output, formatted_text, style, color_depth=None):
    """
    Print a list of (style_str, text) tuples in the given style to the output.
    """
    assert isinstance(output, Output)
    assert isinstance(style, BaseStyle)
    assert color_depth is None or color_depth in ColorDepth._ALL

    fragments = to_formatted_text(formatted_text)
    color_depth = color_depth or ColorDepth.default()

    # Reset first.
    output.reset_attributes()
    output.enable_autowrap()

    # Print all (style_str, text) tuples.
    attrs_for_style_string = _StyleStringToAttrsCache(
        style.get_attrs_for_style_str)

    for style_str, text in fragments:
        attrs = attrs_for_style_string[style_str]

        if attrs:
            output.set_attributes(attrs, color_depth)
        else:
            output.reset_attributes()

        # Assume that the output is raw, and insert a carriage return before
        # every newline. (Also important when the front-end is a telnet client.)
        assert '\r' not in text
        output.write(text.replace('\n', '\r\n'))

    # Reset again.
    output.reset_attributes()
    output.flush()
コード例 #3
0
 def send(self, formatted_text):
     """
     Send text to the client.
     """
     formatted_text = to_formatted_text(formatted_text)
     print_formatted_text(self.vt100_output, formatted_text, self.style
                          or DummyStyle())
コード例 #4
0
ファイル: base.py プロジェクト: zezo010/IoT-IDS
    def _get_text_fragments(self):
        result = []
        for i, value in enumerate(self.values):
            checked = (value[0] == self.current_value)
            selected = (i == self._selected_index)

            style = ''
            if checked:
                style += ' class:radio-checked'
            if selected:
                style += ' class:radio-selected'

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

            if selected:
                result.append(('[SetCursorPosition]', ''))

            if checked:
                result.append((style, '*'))
            else:
                result.append((style, ' '))

            result.append((style, ')'))
            result.append(('class:radio', ' '))
            result.extend(to_formatted_text(value[1], style='class:radio'))
            result.append(('', '\n'))

        result.pop()  # Remove last newline.
        return result
コード例 #5
0
ファイル: processors.py プロジェクト: zezo010/IoT-IDS
 def apply_transformation(self, ti):
     # Insert fragments after the last line.
     if ti.lineno == ti.document.line_count - 1:
         # Get fragments.
         fragments_after = to_formatted_text(self.text, self.style)
         return Transformation(fragments=ti.fragments + fragments_after)
     else:
         return Transformation(fragments=ti.fragments)
コード例 #6
0
ファイル: margins.py プロジェクト: zezo010/IoT-IDS
    def create_margin(self, window_render_info, width, height):
        get_continuation = self.get_continuation
        result = []

        # First line.
        result.extend(to_formatted_text(self.get_prompt()))

        # Next lines.
        if get_continuation:
            last_y = None

            for y in window_render_info.displayed_lines[1:]:
                result.append(('', '\n'))
                result.extend(
                    to_formatted_text(get_continuation(width, y, y == last_y)))
                last_y = y

        return result
コード例 #7
0
ファイル: base.py プロジェクト: zezo010/IoT-IDS
 def get_width():
     if width is None:
         text_fragments = to_formatted_text(self.text)
         text = fragment_list_to_text(text_fragments)
         if text:
             longest_line = max(
                 get_cwidth(line) for line in text.splitlines())
         else:
             return D(preferred=0)
         return D(preferred=longest_line)
     else:
         return width
コード例 #8
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
コード例 #9
0
ファイル: processors.py プロジェクト: zezo010/IoT-IDS
    def apply_transformation(self, ti):
        if ti.lineno == 0:
            # Get fragments.
            fragments_before = to_formatted_text(self.text, self.style)
            fragments = fragments_before + ti.fragments

            shift_position = fragment_list_len(fragments_before)
            source_to_display = lambda i: i + shift_position
            display_to_source = lambda i: i - shift_position
        else:
            fragments = ti.fragments
            source_to_display = None
            display_to_source = None

        return Transformation(fragments, source_to_display=source_to_display,
                              display_to_source=display_to_source)
コード例 #10
0
ファイル: base.py プロジェクト: zezo010/IoT-IDS
    def create_content(self, width, height):
        items = []
        for pr in self.progress_bar.counters:
            try:
                text = self.formatter.format(self.progress_bar, pr, width)
            except BaseException:
                traceback.print_exc()
                text = 'ERROR'

            items.append(to_formatted_text(text))

        def get_line(i):
            return items[i]

        return UIContent(get_line=get_line,
                         line_count=len(items),
                         show_cursor=False)
コード例 #11
0
ファイル: prompt.py プロジェクト: zezo010/IoT-IDS
    def _get_continuation(self, width, line_number, is_soft_wrap):
        """
        Insert the prompt continuation.

        :param width: The width that's available for the continuation (don't
            exceed this).
        :param line_number:
        :param is_soft_wrap: True when we got a soft wrap here instead of a
            hard line ending.
        """
        prompt_continuation = self.prompt_continuation

        if callable(prompt_continuation):
            prompt_continuation = prompt_continuation(width, line_number,
                                                      is_soft_wrap)

        return to_formatted_text(prompt_continuation,
                                 style='class:prompt-continuation')
コード例 #12
0
ファイル: prompt.py プロジェクト: zezo010/IoT-IDS
 def _get_prompt(self):
     return to_formatted_text(self.message, style='class:prompt')
コード例 #13
0
 def _add_suffix(self, label):
     label = to_formatted_text(label, style='class:label')
     return label + [('', self.suffix)]
コード例 #14
0
 def __init__(self, text, style=''):
     self.text = to_formatted_text(text, style=style)