def main():
    term = urwid.Terminal(None)

    mainframe = urwid.LineBox(
        urwid.Pile([
            ('weight', 70, term),
            ('fixed', 1, urwid.Filler(urwid.Edit('focus test edit: '))),
        ]),
    )

    def set_title(widget, title):
        mainframe.set_title(title)

    def quit(*args, **kwargs):
        raise urwid.ExitMainLoop()

    def handle_key(key):
        if key in ('q', 'Q'):
            quit()

    urwid.connect_signal(term, 'title', set_title)
    urwid.connect_signal(term, 'closed', quit)

    loop = urwid.MainLoop(
        mainframe,
        handle_mouse=False,
        unhandled_input=handle_key)

    term.main_loop = loop
    loop.run()
Пример #2
0
    def __init__(self, app, parent):
        self.app = app
        self.parent = parent
        editor_cmd = self.app.config["textui"]["editor"]

        # The "editor" alias is unavailable on Darwin,
        # so we replace it with nano.
        if platform.system() == "Darwin" and editor_cmd == "editor":
            editor_cmd = "nano"

        self.term = urwid.Terminal(
            (editor_cmd, self.app.configpath),
            encoding='utf-8',
            main_loop=self.app.ui.loop,
        )

        def quit_term(*args, **kwargs):
            self.parent.widget = self.parent.config_explainer
            self.app.ui.main_display.update_active_sub_display()
            self.app.ui.main_display.show_config(None)
            self.app.ui.main_display.request_redraw()

        urwid.connect_signal(self.term, 'closed', quit_term)

        urwid.WidgetWrap.__init__(self, self.term)
Пример #3
0
    def __init__(self, py_script):
        title = TEXT_MAIN_CAPTION
        self.done = False
        self.term = urwid.Terminal([sys.executable, '-u', py_script])
        self.status_bar = urwid.Text(TEXT_OPERATION_IS_PROGRESS)
        self.view = urwid.LineBox(urwid.Frame(self.term,
                                              footer=self.status_bar),
                                  title=title)

        urwid.WidgetPlaceholder.__init__(self, self.view)
Пример #4
0
    def __init__(self, cmd, app):
        self._app = app
        self._ow = app.root.original_widget

        btn = urwid.Button("Close")
        w = urwid.AttrMap(btn, "term_close_button", "term_close_button_focus")
        urwid.connect_signal(btn, "click", self.exit)

        footer = urwid.GridFlow([w], 9, 1, 1, "center")

        self.cmd = cmd

        self.header = urwid.Text(
            ("term_header", f"Running: {self.cmd}" + " " * 200), wrap="clip")

        cmd2 = f"bash -c '{cmd}'"
        term = urwid.Terminal(shlex.split(cmd2), main_loop=app.loop)
        self._term = term
        self.frame = urwid.Frame(term, self.header, footer, focus_part="body")
        self._w = self.frame
        urwid.connect_signal(term, "closed", self.done)
Пример #5
0
def render_code(token, body, stack, loop):
    lang = token["lang"] or ""

    numbered_term_match = re.match(r'terminal(\d+)', lang)
    if lang != "terminal-ex" and numbered_term_match is None:
        raise IgnoredByContrib

    if numbered_term_match is not None:
        term_data = TerminalExSchema().load({
            "command":
            token["text"].strip(),
            "rows":
            int(numbered_term_match.group(1)),
            "init_codeblock":
            False,
        })

    else:
        term_data = TerminalExSchema().loads(token["text"])

        if term_data["init_text"] is not None and term_data[
                "init_wait"] is not None:
            orig_command = term_data["command"]
            term_data["command"] = " ".join([
                shlex.quote(x) for x in [
                    "expect", "-c", ";".join([
                        'spawn -noecho {}'.format(term_data["command"]),
                        'expect {{{}}}'.format(term_data["init_wait"]),
                        'send {{{}}}'.format(term_data["init_text"]),
                        'interact',
                        'exit',
                    ])
                ]
            ])

    term = urwid.Terminal(
        shlex.split(term_data["command"].strip()),
        main_loop=loop,
        encoding="utf8",
    )
    CREATED_TERMS.append(term)

    line_box = urwid.LineBox(urwid.BoxAdapter(term, height=term_data["rows"]))
    line_box.no_cache = ["render"]

    res = []

    if term_data["init_codeblock"] is True:
        fake_token = {
            "text": term_data["init_text"],
            "lang": term_data["init_codeblock_lang"],
        }
        res += lookatme.render.markdown_block.render_code(
            fake_token, body, stack, loop)

    res += [
        urwid.Divider(),
        line_box,
        urwid.Divider(),
    ]

    return res
Пример #6
0
        cow_text = p.communicate(dummy_box.encode("utf-8"))[0]
        assert p.returncode == 0
        return cow_text.splitlines()

    def render(self, size, focus=False):
        lines = self._cow_lines(self._inner_size(size))
        return urwid.TextCanvas(lines, maxcol=size[0])

    def sizing(self):
        return frozenset(['box'])


if __name__ == '__main__':

    def exit_loop(*args, **kwargs):
        raise urwid.ExitMainLoop()

    cowsay = Cowsay(urwid.SolidFill(' '))
    background = urwid.SolidFill(' ')
    placement = urwid.Overlay(cowsay,
                              background,
                              align='center',
                              width=('relative', 75),
                              valign='bottom',
                              height=('relative', 75))
    loop = urwid.MainLoop(placement)
    terminal = urwid.Terminal(None, main_loop=loop)
    urwid.connect_signal(terminal, 'closed', exit_loop)
    cowsay.top_w = terminal
    loop.run()
Пример #7
0
 def __init__(self, app):
     self._app = app
     self._w = urwid.Terminal(shlex.split("conky"),
                              main_loop=self._app.loop)
Пример #8
0
 def __init__(self, app):
     self.app = app
     self.log_term = urwid.Terminal(("tail", "-fn50", self.app.logfilepath),
                                    encoding='utf-8',
                                    escape_sequence="up")
     urwid.WidgetWrap.__init__(self, self.log_term)