From ec63e9b899af1361e0da48d9031f77eccb87d3ea Mon Sep 17 00:00:00 2001 From: William Erik Baxter Date: Thu, 22 Nov 2012 16:19:30 -0500 Subject: Implement move commands in globals.py. Add --redraw for bclose. --- alot/commands/globals.py | 22 ++++++++++++++++++++-- alot/ui.py | 19 +++++++------------ docs/source/usage/modes/global.rst | 1 + 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 1cf78ca4..22bbae69 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -338,11 +338,13 @@ class CallCommand(Command): @registerCommand(MODE, 'bclose', arguments=[ + (['--redraw'], {'action': BooleanAction, 'help':'redraw current buffer \ + after command has finished'}), (['--force'], {'action': 'store_true', 'help': 'never ask for confirmation'})]) class BufferCloseCommand(Command): """close a buffer""" - def __init__(self, buffer=None, force=False, **kwargs): + def __init__(self, buffer=None, force=False, redraw=True, **kwargs): """ :param buffer: the buffer to close or None for current :type buffer: `alot.buffers.Buffer` @@ -351,6 +353,7 @@ class BufferCloseCommand(Command): """ self.buffer = buffer self.force = force + self.redraw = redraw Command.__init__(self, **kwargs) @inlineCallbacks @@ -374,7 +377,7 @@ class BufferCloseCommand(Command): logging.info('not closing last remaining buffer as ' 'global.quit_on_last_bclose is set to False') else: - ui.buffer_close(self.buffer) + ui.buffer_close(self.buffer,self.redraw) @registerCommand(MODE, 'bprevious', forced={'offset': -1}, @@ -779,6 +782,21 @@ class ComposeCommand(Command): refocus=False) ui.apply_command(cmd) +@registerCommand(MODE, 'move', help='move focus in current buffer', + arguments = [(['movement'], {'nargs':argparse.REMAINDER, + 'help':'up, down, page up, page down'})] +) +class MoveCommand(Command): + """move in widget""" + def __init__(self, movement=None, **kwargs): + if movement is None: + self.movement = '' + else: + self.movement = ' '.join(movement) + Command.__init__(self, **kwargs) + + def apply(self, ui): + ui.mainloop.process_input([self.movement]) class CommandSequenceCommand(Command): """Meta-Command that just applies a sequence of given Commands in order""" diff --git a/alot/ui.py b/alot/ui.py index f492c2bd..68f9bf15 100644 --- a/alot/ui.py +++ b/alot/ui.py @@ -130,12 +130,7 @@ class UI(object): clear() logging.debug("cmdline: '%s'" % cmdline) # move keys are always passed - if cmdline.startswith('move '): - movecmd = cmdline[5:].rstrip() - logging.debug("GOT MOVE: '%s'" % movecmd) - if movecmd in ['up', 'down', 'page up', 'page down']: - return [movecmd] - elif not self._locked: + if cmdline.startswith('move ') or not self._locked: try: self.apply_commandline(cmdline) except CommandParseError, e: @@ -275,7 +270,7 @@ class UI(object): self.buffers.append(buf) self.buffer_focus(buf) - def buffer_close(self, buf): + def buffer_close(self, buf, redraw=True): """ closes given :class:`~alot.buffers.Buffer`. @@ -292,7 +287,7 @@ class UI(object): buffers.remove(buf) offset = settings.get('bufferclose_focus_offset') nextbuffer = buffers[(index + offset) % len(buffers)] - self.buffer_focus(nextbuffer) + self.buffer_focus(nextbuffer, redraw) buf.cleanup() else: string = 'closing buffer %d:%s' @@ -300,7 +295,7 @@ class UI(object): buffers.remove(buf) buf.cleanup() - def buffer_focus(self, buf): + def buffer_focus(self, buf, redraw=True): """focus given :class:`~alot.buffers.Buffer`.""" if buf not in self.buffers: logging.error('tried to focus unknown buffer') @@ -310,7 +305,7 @@ class UI(object): self.mode = buf.modename if isinstance(self.current_buffer, BufferlistBuffer): self.current_buffer.rebuild() - self.update() + self.update(redraw) def get_deep_focus(self, startfrom=None): """return the bottom most focussed widget of the widget tree""" @@ -465,7 +460,7 @@ class UI(object): self.mainloop.set_alarm_in(timeout, clear) return msgs[0] - def update(self): + def update(self, redraw=True): """redraw interface""" # get the main urwid.Frame widget mainframe = self.root_widget.original_widget @@ -486,7 +481,7 @@ class UI(object): else: mainframe.set_footer(None) # force a screen redraw - if self.mainloop.screen.started: + if self.mainloop.screen.started and redraw: self.mainloop.draw_screen() def build_statusbar(self): diff --git a/docs/source/usage/modes/global.rst b/docs/source/usage/modes/global.rst index d5ca2ca1..9835b5af 100644 --- a/docs/source/usage/modes/global.rst +++ b/docs/source/usage/modes/global.rst @@ -13,6 +13,7 @@ The following commands are available globally optional arguments :---force: never ask for confirmation. + :---redraw: redraw display after closing current buffer. .. _cmd.global.bprevious: -- cgit v1.2.3