diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/config/config | 12 | ||||
-rw-r--r-- | examples/data/plugins/bind.py | 3 | ||||
-rw-r--r-- | examples/data/plugins/history.py | 129 |
3 files changed, 142 insertions, 2 deletions
diff --git a/examples/config/config b/examples/config/config index a2ecdb8..4934469 100644 --- a/examples/config/config +++ b/examples/config/config @@ -190,7 +190,17 @@ set ebind = @mode_bind global,-insert @ebind <Ctrl>a = event SET_CURSOR_POS 0 @ebind <Ctrl>e = event SET_CURSOR_POS -1 -# --- Mouse bindings --------------------------------------------------------- +@ebind <Up> = event HISTORY_PREV +@ebind <Down> = event HISTORY_NEXT +@ebind <Ctrl>r<s:>_ = event HISTORY_SEARCH %s +# Keycmd injection/append examples. +#@ebind <Ctrl>su = event INJECT_KEYCMD \@uri +#@ebind <Ctrl>st = event INJECT_KEYCMD \@title +#@ebind <Ctrl>du = event APPEND_KEYCMD \@uri +#@ebind <Ctrl>dt = event APPEND_KEYCMD \@title + + +# === Mouse bindings ========================================================= # Middle click open in new window @bind <Button2> = sh 'if [ "$1" ]; then echo "event REQ_NEW_WINDOW $1" > "$UZBL_FIFO"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"; fi' '\@SELECTED_URI' diff --git a/examples/data/plugins/bind.py b/examples/data/plugins/bind.py index 5b13476..bf693b3 100644 --- a/examples/data/plugins/bind.py +++ b/examples/data/plugins/bind.py @@ -421,7 +421,8 @@ def match_and_exec(uzbl, bind, depth, keylet, bindlet): if not has_args or on_exec: del uzbl.config['mode'] bindlet.reset() - uzbl.clear_current() + # cleared by keycmd_exec_current, why is this here? breaks history + #uzbl.clear_current() return True diff --git a/examples/data/plugins/history.py b/examples/data/plugins/history.py new file mode 100644 index 0000000..78a94ce --- /dev/null +++ b/examples/data/plugins/history.py @@ -0,0 +1,129 @@ +import random + +shared_history = {'':[]} + +class History(object): + def __init__(self, uzbl): + self.uzbl = uzbl + self._temporary = [] + self.prompt = '' + self.cursor = None + self.__temp_tail = False + self.search_key = None + + def prev(self): + if self.cursor is None: + self.cursor = len(self) - 1 + else: + self.cursor -= 1 + + if self.search_key: + while self.cursor >= 0 and self.search_key not in self[self.cursor]: + self.cursor -= 1 + + if self.cursor < 0 or len(self) == 0: + self.cursor = -1 + return random.choice(end_messages) + + return self[self.cursor] + + def next(self): + if self.cursor is None: + return '' + + self.cursor += 1 + + if self.search_key: + while self.cursor < len(self) and self.search_key not in self[self.cursor]: + self.cursor += 1 + + if self.cursor >= len(shared_history[self.prompt]): + self.cursor = None + self.search_key = None + + if self._temporary: + print 'popping temporary' + return self._temporary.pop() + return '' + + return self[self.cursor] + + def change_prompt(self, prompt): + self.prompt = prompt + self._temporary = [] + self.__temp_tail = False + if prompt not in shared_history: + shared_history[prompt] = [] + + def search(self, key): + self.search_key = key + self.cursor = None + + def add(self, cmd): + if self._temporary: + self._temporary.pop() + + shared_history[self.prompt].append(cmd) + self.cursor = None + self.search_key = None + + def add_temporary(self, cmd): + assert not self._temporary + + self._temporary.append(cmd) + self.cursor = len(self) - 1 + + print 'adding temporary', self + + def __getitem__(self, i): + if i < len(shared_history[self.prompt]): + return shared_history[self.prompt][i] + return self._temporary[i-len(shared_history)+1] + + def __len__(self): + return len(shared_history[self.prompt]) + len(self._temporary) + + def __str__(self): + return "(History %s, %s)" % (self.cursor, self.prompt) + +def keycmd_exec(uzbl, keylet): + cmd = keylet.get_keycmd() + if cmd: + uzbl.history.add(cmd) + +def history_prev(uzbl, _x): + cmd = uzbl.keylet.get_keycmd() + if uzbl.history.cursor is None and cmd: + uzbl.history.add_temporary(cmd) + + uzbl.set_keycmd(uzbl.history.prev()) + uzbl.logger.debug('PREV %s' % uzbl.history) + +def history_next(uzbl, _x): + cmd = uzbl.keylet.get_keycmd() + + uzbl.set_keycmd(uzbl.history.next()) + uzbl.logger.debug('NEXT %s' % uzbl.history) + +def history_search(uzbl, key): + uzbl.history.search(key) + uzbl.logger.debug('SEARCH %s %s' % (key, uzbl.history)) + +end_messages = ('Look behind you, A three-headed monkey!', 'error #4: static from nylon underwear.', 'error #5: static from plastic slide rules.', 'error #6: global warming.', 'error #9: doppler effect.', 'error #16: somebody was calculating pi on the server.', 'error #19: floating point processor overflow.', 'error #21: POSIX compliance problem.', 'error #25: Decreasing electron flux.', 'error #26: first Saturday after first full moon in Winter.', 'error #64: CPU needs recalibration.', 'error #116: the real ttys became pseudo ttys and vice-versa.', 'error #229: wrong polarity of neutron flow.', 'error #330: quantum decoherence.', 'error #388: Bad user karma.', 'error #407: Route flapping at the NAP.', 'error #435: Internet shut down due to maintenance.') + +# plugin init hook +def init(uzbl): + connect_dict(uzbl, { + 'KEYCMD_EXEC': keycmd_exec, + 'HISTORY_PREV': history_prev, + 'HISTORY_NEXT': history_next, + 'HISTORY_SEARCH': history_search + }) + + export_dict(uzbl, { + 'history' : History(uzbl) + }) + +# plugin after hook +def after(uzbl): + uzbl.on_set('keycmd_prompt', lambda uzbl, k, v: uzbl.history.change_prompt(v)) |