Beispiel #1
0
    async def g():
        stdout = process.stdout
        stderr = process.stderr
        streams = []
        if isinstance(stdout, asyncio.streams.StreamReader):
            streams.append(stream_reader_generator(stdout))
        if isinstance(stderr, asyncio.streams.StreamReader):
            streams.append(stream_reader_generator(stderr))
        if master:
            assert slave
            reader_pipe = io.open(master, "rb", 0)
            reader = asyncio.StreamReader()
            reader_protocol = asyncio.StreamReaderProtocol(reader)
            await asyncio.get_running_loop().connect_read_pipe(
                lambda: reader_protocol, reader_pipe)
            streams.extend([stream_reader_generator(reader), exit_stream()])

        assert streams
        stream = combine.merge(*streams)
        async with stream.stream() as s:
            async for data in s:
                yield data
        exit_code = process.returncode if slave else await process.wait()
        status = C("✗", color=theme.X_COLOR) if exit_code else C(
            "✓", color=theme.V_COLOR)
        yield BoxActions([
            UpdateMetadata({"exit_code": exit_code}),
            SetTitle(C("[", status, f"] {title}")),
        ])
Beispiel #2
0
    def _update_title_line(self, index):
        screen_y, location = self.get_title_line(index)
        if location != ViewLocation.IN_VIEW:
            return

        holder = self.get_holder(index)
        iterator = holder.iterator
        box_state = holder.state
        suffix = ""
        if self.verbose:
            wrap = box_state.wrap
            auto_scroll = box_state.auto_scroll
            collapsed = box_state.collapsed
            input_mode = box_state.input_mode
            buffer_line = box_state.buffer_start_line
            box_height = box_state.box_height
            state = [
                "W" if wrap else "-",
                "-" if auto_scroll else "S",
                "C" if collapsed else "-",
                "I" if input_mode else "-",
            ]
            state = f"{''.join(state)} [{buffer_line},{box_height}]"
            suffix = f" [{state}]"
        suffix_len = len(suffix)
        title = iterator.title
        if not isinstance(title, C):
            title = C(title)
        title_len = len(title)
        hr_space = 4
        _ellipsis = "..."
        if hr_space + title_len + suffix_len > self.cols:
            title = title[:self.cols - suffix_len - len(_ellipsis) - hr_space]
            title += _ellipsis
        text = C(" ", title, suffix, " ", color=(NONE, NONE))

        logger.debug(
            f"s{index}:\t{screen_y}\t{location}\t[{self.lines},{self.cols}]")

        if index == self.current_focused_box:
            hline_color = ansi.theme.TITLE_FOCUS
        elif box_state.stream_done:
            hline_color = ansi.theme.TITLE_STREAM_DONE
        else:
            hline_color = ansi.theme.TITLE_NORMAL
        ansi.title(
            row=screen_y,
            text=text,
            hline_color=hline_color,
            cols=self.cols,
        )
Beispiel #3
0
 async def load(self, export_dir):
     viewer = self.viewer
     async with aiofiles.open(os.path.join(export_dir,
                                           "metadata.json")) as f:
         metadata = json.loads(await f.read())
     viewer.initial_add([
         Descriptor(
             obj=f"file://{export_dir}/{box['filename']}",
             title=C.from_dict(box["title"]) if isinstance(
                 box["title"], dict) else box["title"],
             box_height=box["box_height"],
             collapsed=box["collapsed"],
             wrap=box["wrap"],
         ) for box in metadata["boxes"]
     ])
     view = metadata["view"]
     viewer.maximized = view["maximized"]
     viewer.collaped_all = view["collapsed"]
     viewer.wrapped_all = view["wrapped"]
Beispiel #4
0
    def _update_status_bar(self):
        if self.help.show:
            return

        focused = self.focused
        index = focused.index
        iterator = self.get_iterator(index)
        title = iterator.title
        box_state = focused.state
        wrap = box_state.wrap
        auto_scroll = box_state.auto_scroll
        input_mode = box_state.input_mode

        modes = []
        if not auto_scroll:
            modes.append("SCROLL")
        if self.maximized:
            modes.append("MAXIMIZED")
        if wrap:
            modes.append("WRAP")
        if input_mode:
            modes.append("INPUT")
        mode = "|".join(modes)
        mode_paren = f"({mode})" if mode else ""

        pending_keys = self.input_reader.pending
        pending_name_parts = []
        while pending_keys:
            cur_offset = len(pending_keys)
            name = None
            while not name and cur_offset:
                name = keys.seq_to_name(pending_keys[:cur_offset],
                                        fallback=False)
                if not name:
                    cur_offset -= 1
            pending_name_parts.append(name)
            pending_keys = pending_keys[cur_offset:]

        pending_text = "".join(pending_name_parts)
        if pending_text:
            pending_text = f"{pending_text} "

        prefix = f"[{index + 1}] "
        prefix_len = len(prefix)

        if not isinstance(title, C):
            title = C(title)
        title_len = len(title)
        mode_len = len(mode_paren)
        pending_len = len(pending_text)
        space_between = self.cols - title_len - mode_len - pending_len - prefix_len
        if space_between < 0:
            _ellipsis = "... "
            title = title[:(self.cols - mode_len - pending_len - prefix_len) -
                          len(_ellipsis)]
            title += _ellipsis
            space_between = 0
        if self.output_saved:
            color = ansi.theme.STATUS_SAVE
        elif input_mode:
            color = ansi.theme.STATUS_INPUT
        elif not auto_scroll:
            color = ansi.theme.STATUS_SCROLL
        else:
            color = ansi.theme.STATUS_NORMAL
        text = C(prefix,
                 title,
                 " " * space_between,
                 pending_text,
                 mode_paren,
                 color=color)

        ansi.status_bar(
            row=self.get_status_bar_line(),
            text=text,
        )