Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commands/thread/open-attachment: add command #1505

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
commands/global/shellescape: add on_exit callback
Completing the already existing on_success for callbacks that should be
executed even after a non-zero exit code.
  • Loading branch information
pacien committed May 9, 2020
commit 911bd81d47b3c8246a8dfe5f113a01eda9f3cce0
10 changes: 9 additions & 1 deletion alot/commands/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ class ExternalCommand(Command):
repeatable = True

def __init__(self, cmd, stdin=None, shell=False, spawn=False,
refocus=True, thread=False, on_success=None, **kwargs):
refocus=True, thread=False, on_success=None, on_exit=None,
**kwargs):
"""
:param cmd: the command to call
:type cmd: list or str
Expand All @@ -206,6 +207,8 @@ def __init__(self, cmd, stdin=None, shell=False, spawn=False,
:type refocus: bool
:param on_success: code to execute after command successfully exited
:type on_success: callable
:param on_exit: code to execute after command exited
:type on_exit: callable
"""
logging.debug({'spawn': spawn})
# make sure cmd is a list of str
Expand Down Expand Up @@ -238,6 +241,7 @@ def __init__(self, cmd, stdin=None, shell=False, spawn=False,
self.refocus = refocus
self.in_thread = thread
self.on_success = on_success
self.on_exit = on_exit
Command.__init__(self, **kwargs)

async def apply(self, ui):
Expand Down Expand Up @@ -308,6 +312,10 @@ async def apply(self, ui):
proc.returncode,
ret or "No stderr output")
ui.notify(msg, priority='error')

if self.on_exit is not None:
self.on_exit()

if self.refocus and callerbuffer in ui.buffers:
logging.info('refocussing')
ui.buffer_focus(callerbuffer)
Expand Down