| 51 | |
| 52 | |
| 53 | class ActionBar(urwid.WidgetWrap): |
| 54 | def __init__(self, master: mitmproxy.tools.console.master.ConsoleMaster) -> None: |
| 55 | self.master = master |
| 56 | self.top = urwid.WidgetWrap(urwid.Text("")) |
| 57 | self.bottom = urwid.WidgetWrap(urwid.Text("")) |
| 58 | super().__init__(urwid.Pile([self.top, self.bottom])) |
| 59 | self.show_quickhelp() |
| 60 | signals.status_message.connect(self.sig_message) |
| 61 | signals.status_prompt.connect(self.sig_prompt) |
| 62 | signals.status_prompt_onekey.connect(self.sig_prompt_onekey) |
| 63 | signals.status_prompt_command.connect(self.sig_prompt_command) |
| 64 | signals.window_refresh.connect(self.sig_update) |
| 65 | master.view.focus.sig_change.connect(self.sig_update) |
| 66 | master.view.sig_view_update.connect(self.sig_update) |
| 67 | master.options.subscribe(self.sig_options_update, ["console_quickhelp_visible"]) |
| 68 | |
| 69 | self.prompting: Callable[[str], None] | None = None |
| 70 | |
| 71 | self.onekey: set[str] | None = None |
| 72 | |
| 73 | def ensure_bottom_bar_is_visible(self) -> None: |
| 74 | pile: urwid.Pile = self._w # type: ignore[has-type] |
| 75 | current_widgets = [w for w, _ in pile.contents] |
| 76 | if current_widgets != [self.top, self.bottom]: |
| 77 | self._w = urwid.Pile([self.top, self.bottom]) |
| 78 | |
| 79 | def sig_update(self, flow=None) -> None: |
| 80 | if not self.prompting and (flow is None or flow == self.master.view.focus.flow): |
| 81 | self.show_quickhelp() |
| 82 | |
| 83 | def sig_options_update(self, options, updated) -> None: |
| 84 | self.show_quickhelp() |
| 85 | |
| 86 | def sig_message( |
| 87 | self, message: tuple[str, str] | str, expire: int | None = 1 |
| 88 | ) -> None: |
| 89 | if self.prompting: |
| 90 | return |
| 91 | # Ensure widgets are visible for messages |
| 92 | self.ensure_bottom_bar_is_visible() |
| 93 | cols, _ = self.master.ui.get_cols_rows() |
| 94 | w = urwid.Text(shorten_message(message, cols)) |
| 95 | self.top._w = w |
| 96 | self.bottom._w = urwid.Text("") |
| 97 | if expire: |
| 98 | |
| 99 | def cb(): |
| 100 | if w == self.top._w: |
| 101 | self.show_quickhelp() |
| 102 | |
| 103 | signals.call_in.send(seconds=expire, callback=cb) |
| 104 | |
| 105 | def sig_prompt( |
| 106 | self, prompt: str, text: str | None, callback: Callable[[str], None] |
| 107 | ) -> None: |
| 108 | self.ensure_bottom_bar_is_visible() |
| 109 | signals.focus.send(section="footer") |
| 110 | self.top._w = urwid.Edit(f"{prompt.strip()}: ", text or "") |
no outgoing calls
no test coverage detected
searching dependent graphs…