aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/console/statusbar.py
diff options
context:
space:
mode:
Diffstat (limited to 'libmproxy/console/statusbar.py')
-rw-r--r--libmproxy/console/statusbar.py95
1 files changed, 81 insertions, 14 deletions
diff --git a/libmproxy/console/statusbar.py b/libmproxy/console/statusbar.py
index 7ad78f03..c1a907bd 100644
--- a/libmproxy/console/statusbar.py
+++ b/libmproxy/console/statusbar.py
@@ -1,30 +1,97 @@
-
import time
import urwid
-from . import pathedit, signals
+from . import pathedit, signals, common
from .. import utils
-
class ActionBar(urwid.WidgetWrap):
def __init__(self):
- urwid.WidgetWrap.__init__(self, urwid.Text(""))
- signals.status_message.connect(self.message)
-
- def selectable(self):
- return True
+ urwid.WidgetWrap.__init__(self, None)
+ self.clear()
+ signals.status_message.connect(self.sig_message)
+ signals.status_prompt.connect(self.sig_prompt)
+ signals.status_path_prompt.connect(self.sig_path_prompt)
+ signals.status_prompt_onekey.connect(self.sig_prompt_onekey)
+
+ self.prompting = False
+ self.onekey = False
+
+ def sig_message(self, sender, message, expire=None):
+ w = urwid.Text(message)
+ self._w = w
+ if expire:
+ def cb(*args):
+ if w == self._w:
+ self.clear()
+ signals.call_in.send(seconds=expire, callback=cb)
+
+ def sig_prompt(self, sender, prompt, text, callback, args=()):
+ signals.focus.send(self, section="footer")
+ self._w = urwid.Edit(prompt, text or "")
+ self.prompting = (callback, args)
- def path_prompt(self, prompt, text):
+ def sig_path_prompt(self, sender, prompt, text, callback, args=()):
+ signals.focus.send(self, section="footer")
self._w = pathedit.PathEdit(prompt, text)
+ self.prompting = (callback, args)
+
+ def sig_prompt_onekey(self, sender, prompt, keys, callback, args=()):
+ """
+ Keys are a set of (word, key) tuples. The appropriate key in the
+ word is highlighted.
+ """
+ signals.focus.send(self, section="footer")
+ prompt = [prompt, " ("]
+ mkup = []
+ for i, e in enumerate(keys):
+ mkup.extend(common.highlight_key(e[0], e[1]))
+ if i < len(keys)-1:
+ mkup.append(",")
+ prompt.extend(mkup)
+ prompt.append(")? ")
+ self.onekey = set(i[1] for i in keys)
+ self._w = urwid.Edit(prompt, "")
+ self.prompting = (callback, args)
- def prompt(self, prompt, text = ""):
- self._w = urwid.Edit(prompt, text or "")
+ def selectable(self):
+ return True
- def message(self, sender, message, expire=None):
- self.expire = expire
- self._w = urwid.Text(message)
+ def keypress(self, size, k):
+ if self.prompting:
+ if k == "esc":
+ self.prompt_done()
+ elif self.onekey:
+ if k == "enter":
+ self.prompt_done()
+ elif k in self.onekey:
+ self.prompt_execute(k)
+ elif k == "enter":
+ self.prompt_execute()
+ else:
+ if common.is_keypress(k):
+ self._w.keypress(size, k)
+ else:
+ return k
+
+ def clear(self):
+ self._w = urwid.Text("")
+
+ def prompt_done(self):
+ self.prompting = False
+ self.onekey = False
+ signals.status_message.send(message="")
+ signals.focus.send(self, section="body")
+
+ def prompt_execute(self, txt=None):
+ if not txt:
+ txt = self._w.get_edit_text()
+ p, args = self.prompting
+ self.prompt_done()
+ msg = p(txt, *args)
+ if msg:
+ signals.status_message.send(message=msg, expire=1)
class StatusBar(urwid.WidgetWrap):