diff options
author | hut <hut@lavabit.com> | 2010-01-01 20:35:22 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-01-01 20:35:22 +0100 |
commit | 6f43de0af345c63216b03b1e2611abf98266d80a (patch) | |
tree | 57edee00e6a2ed0973c5db8ef204883032e72938 /ranger | |
parent | 0a1bc7598776c360b469a64316a1c69c0a914b5f (diff) | |
download | ranger-6f43de0af345c63216b03b1e2611abf98266d80a.tar.gz |
notify: merged into statusbar, allow to view the log in the pager
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/actions.py | 16 | ||||
-rw-r--r-- | ranger/defaults/keys.py | 18 | ||||
-rw-r--r-- | ranger/fm.py | 2 | ||||
-rw-r--r-- | ranger/fsobject/loader.py | 2 | ||||
-rw-r--r-- | ranger/gui/defaultui.py | 25 | ||||
-rw-r--r-- | ranger/gui/widgets/notify.py | 70 | ||||
-rw-r--r-- | ranger/gui/widgets/statusbar.py | 58 |
7 files changed, 78 insertions, 113 deletions
diff --git a/ranger/actions.py b/ranger/actions.py index c1ea7485..62b55b81 100644 --- a/ranger/actions.py +++ b/ranger/actions.py @@ -177,6 +177,13 @@ class Actions(EnvironmentAware, SettingsAware): lines = trimmed_lines_of_docstring(command.__doc__) pager.set_source(lines) + def display_log(self): + if not hasattr(self.ui, 'open_pager'): + return + + pager = self.ui.open_pager() + pager.set_source(self.log) + def display_file(self): if not hasattr(self.ui, 'open_embedded_pager'): return @@ -275,12 +282,9 @@ class Actions(EnvironmentAware, SettingsAware): pass def notify(self, text, duration=4, bad=False): - try: - method = self.ui.display - except AttributeError: - pass - else: - return method(text, duration=duration, bad=bad) + self.log.appendleft(text) + if hasattr(self.ui, 'notify'): + self.ui.notify(text, duration=duration, bad=bad) def mark(self, all=False, toggle=False, val=None, movedown=None): """ diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py index 5732b793..7cd92004 100644 --- a/ranger/defaults/keys.py +++ b/ranger/defaults/keys.py @@ -59,6 +59,8 @@ def initialize_commands(command_list): bind(TAB, fm.search(order='tag')) + bind(ctrl('p'), fm.display_log()) + hint('t', "show_//h//idden //p//review_files //d//irectories_first " \ "//a//uto_load_preview //c//ollapse_preview") bind('th', fm.toggle_boolean_option('show_hidden')) @@ -141,7 +143,7 @@ def initialize_commands(command_list): bind('r', fm.open_console(cmode.OPEN_QUICK)) def test(arg): - arg.fm.notify("bla") + arg.fm.notify(str(arg.n)) bind('x', test) # definitions which require their own function: @@ -234,18 +236,18 @@ def initialize_pager_commands(command_list): initialize_embedded_pager_commands(command_list) bind('q', 'i', ESC, KEY_F1, lambda arg: arg.fm.ui.close_pager()) -def initialize_embedded_pager_commands(command_list): - system_functions(command_list) - bind, hint = make_abbreviations(command_list) - bind('j', KEY_DOWN, nwrap.move(relative=1)) bind('k', KEY_DOWN, nwrap.move(relative=-1)) bind('gg', KEY_DOWN, nwrap.move(absolute=0)) bind('G', KEY_DOWN, nwrap.move(absolute=-1)) - - bind('q', 'i', ESC, lambda arg: arg.fm.ui.close_embedded_pager()) + bind('h', wdg.move_horizontal(relative=-4)) bind('l', wdg.move_horizontal(relative=4)) - bind('Q', 'ZZ', fm.exit()) + command_list.rebuild_paths() +def initialize_embedded_pager_commands(command_list): + system_functions(command_list) + bind, hint = make_abbreviations(command_list) + + bind('q', 'i', ESC, lambda arg: arg.fm.ui.close_embedded_pager()) command_list.rebuild_paths() diff --git a/ranger/fm.py b/ranger/fm.py index e70e9f3c..ebb84b70 100644 --- a/ranger/fm.py +++ b/ranger/fm.py @@ -1,4 +1,5 @@ from time import time +from collections import deque from ranger.actions import Actions from ranger.container import Bookmarks @@ -17,6 +18,7 @@ class FM(Actions): """Initialize FM.""" Actions.__init__(self) self.ui = ui + self.log = deque(maxlen=20) self.bookmarks = bookmarks self.tags = tags self.loader = Loader() diff --git a/ranger/fsobject/loader.py b/ranger/fsobject/loader.py index 3a2020fb..a67c75fb 100644 --- a/ranger/fsobject/loader.py +++ b/ranger/fsobject/loader.py @@ -106,7 +106,7 @@ class Loader(FileManagerAware): item.load_generator = None self.queue.popleft() except Exception as err: - self.fm.ui.display(str(err), bad=True) + self.fm.notify(str(err), bad=True) def has_work(self): """Is there anything to load?""" diff --git a/ranger/gui/defaultui.py b/ranger/gui/defaultui.py index ccbe2578..ca233df9 100644 --- a/ranger/gui/defaultui.py +++ b/ranger/gui/defaultui.py @@ -10,7 +10,6 @@ class DefaultUI(UI): from ranger.gui.widgets.console import Console from ranger.gui.widgets.statusbar import StatusBar from ranger.gui.widgets.taskview import TaskView - from ranger.gui.widgets.notify import Notify from ranger.gui.widgets.pager import Pager # Create a title bar @@ -27,10 +26,6 @@ class DefaultUI(UI): self.taskview.visible = False self.add_child(self.taskview) - # Create the (initially hidden) notify bar - self.notify = Notify(self.win) - self.add_child(self.notify) - # Create the status bar self.status = StatusBar(self.win, self.browser.main_column) self.add_child(self.status) @@ -50,23 +45,15 @@ class DefaultUI(UI): UI.update_size(self) y, x = self.env.termsize - notify_hei = min(max(1, y - 4), self.notify.requested_height) - - self.browser.resize(1, 0, y - 1 - notify_hei, x) - self.taskview.resize(1, 0, y - 1 - notify_hei, x) - self.pager.resize(1, 0, y - 1 - notify_hei, x) - self.notify.resize(y - notify_hei, 0, notify_hei, x) + self.browser.resize(1, 0, y - 2, x) + self.taskview.resize(1, 0, y - 2, x) + self.pager.resize(1, 0, y - 2, x) self.titlebar.resize(0, 0, 1, x) self.status.resize(y - 1, 0, 1, x) self.console.resize(y - 1, 0, 1, x) - def poke(self): - UI.poke(self) - if self.notify.requested_height != self.notify.hei: - self.update_size() - - def display(self, *a, **k): - return self.notify.display(*a, **k) + def notify(self, *a, **k): + return self.status.notify(*a, **k) def close_pager(self): if self.console.visible: @@ -122,4 +109,4 @@ class DefaultUI(UI): self.titlebar.throbber = string def hint(self, text=None): - self.status.override = text + self.status.hint = text diff --git a/ranger/gui/widgets/notify.py b/ranger/gui/widgets/notify.py deleted file mode 100644 index 8b783fdb..00000000 --- a/ranger/gui/widgets/notify.py +++ /dev/null @@ -1,70 +0,0 @@ -"""Notify is a bar which displays messages.""" - -from . import Widget -from time import time -from collections import deque - -class Notify(Widget): - requested_height = 1 - max_size = 5 - textcontainer = None - - def __init__(self, win): - Widget.__init__(self, win) - self.textcontainer = deque(maxlen=self.max_size) - - def poke(self): - for i in reversed(range(len(self.textcontainer))): - msg = self.textcontainer[i] - if msg.elapse and time() > msg.elapse: - msg.alive = False - del self.textcontainer[i] - self.requested_height = len(self.textcontainer) + 1 - - def draw(self): - import curses, socket, os - - i = 0 - for msg in self.textcontainer: - if i >= self.hei - 1: - break - - how = msg.bad and 'bad' or 'good' - self.color_at(i, 0, self.wid,\ - 'in_notify', 'background', how) - self.color('in_notify', 'message', how) - self.addstr(i, 0, msg.text) - i += 1 - - self.color_reset() - - def display(self, text, duration=4, bad=False): - msg = Message(self.textcontainer, text, duration, bad) - self.textcontainer.append(msg) - return msg - -class Message(object): - elapse = None - text = None - bad = False - alive = True - container = None - - def __init__(self, container, text, duration, bad): - self.text = text - self.bad = bad - self.container = container - self.set_duration(duration) - - def set_duration(self, n=4): - if n: - self.elapse = time() + n - else: - self.elapse = None - - def delete(self): - self.alive = False - try: - self.container.remove(self) - except ValueError: - pass diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py index 94e62d0b..af4870aa 100644 --- a/ranger/gui/widgets/statusbar.py +++ b/ranger/gui/widgets/statusbar.py @@ -13,33 +13,53 @@ from os import getuid from time import strftime, localtime from ranger.gui.bar import Bar +from ranger import log class StatusBar(Widget): __doc__ = __doc__ owners = {} groups = {} timeformat = '%Y-%m-%d %H:%M' - override = None + hint = None + msg = None old_cf = None old_mtime = None + old_hint = None result = None def __init__(self, win, column=None): Widget.__init__(self, win) self.column = column + def notify(self, text, duration=4, bad=False): + self.msg = Message(text, duration, bad) + def draw(self): """Draw the statusbar""" - # each item in the returned array looks like: - # [ list_with_color_tags, string ] - # [ ['permissions', 'allowed'], '-rwxr-xr-x' ] + log("a") - if self.override and isinstance(self.override, str): - self._draw_message() + if self.hint and isinstance(self.hint, str): + if self.old_hint != self.hint: + self.need_redraw = True + if self.need_redraw: + self._draw_hint() return + if self.old_hint and not self.hint: + self.old_hint = None + self.need_redraw = True + + if self.msg: + if self.msg.is_alive(): + log("b") + self._draw_message() + return + else: + self.msg = None + self.need_redraw = True + try: mtime = self.env.cf.stat.st_mtime except: @@ -69,12 +89,18 @@ class StatusBar(Widget): bar.shrink_by_removing(self.wid) self.result = bar.combine() - + def _draw_message(self): + self.win.erase() + self.color('in_statusbar', self.msg.bad and 'bad' or 'good') + self.addnstr(0, 0, self.msg.text, self.wid) + + def _draw_hint(self): + self.win.erase() highlight = True space_left = self.wid starting_point = self.x - for string in self.override.split('//'): + for string in self.hint.split('//'): highlight = not highlight if highlight: self.color('in_statusbar', 'text', 'highlight') @@ -82,7 +108,7 @@ class StatusBar(Widget): self.color('in_statusbar', 'text') try: - self.win.addnstr(self.y, starting_point, string, space_left) + self.addnstr(0, starting_point, string, space_left) except: break space_left -= len(string) @@ -183,3 +209,17 @@ class StatusBar(Widget): self.color(*part.lst) self.addstr(part.string) self.color_reset() + +from time import time +class Message(object): + elapse = None + text = None + bad = False + + def __init__(self, text, duration, bad): + self.text = text + self.bad = bad + self.elapse = time() + duration + + def is_alive(self): + return time() <= self.elapse |