pazz / alot

Terminal-based Mail User Agent
GNU General Public License v3.0
696 stars 164 forks source link

async ui.prompt in hooks won't work #1366

Open teto opened 5 years ago

teto commented 5 years ago

Describe the bug I am trying to add a hook that prompts the user for a path but no prompt happens/nothing happens yet the binding is called (similar to https://github.com/pazz/alot/wiki/Contrib-Hooks#attach-gpg-keys)

Software Versions

To Reproduce Steps to reproduce the behaviour:

  1. set hooksfile to point at https://github.com/teto/home/blob/master/config/alot/apply_patch.py

  2. add a binding (dunno how to trigger the call otherwise) a = call hooks.apply_patch(ui)

  3. open a thread and trigger the binding.

  4. See error (binding is called, but I am not asked for a path/seems like nothing happens)

Error Log

DEBUG:ui:cmdline: 'call hooks.apply_patch(ui)'
DEBUG:ui:thread command string: "call hooks.apply_patch(ui)"
DEBUG:__init__:mode:thread got commandline "call hooks.apply_patch(ui)"
DEBUG:__init__:ARGS: ['call', 'hooks.apply_patch(ui)']
DEBUG:__init__:cmd parms {'command': 'hooks.apply_patch(ui)'}
DEBUG:ui:Got key (['a'], [97])
DEBUG:ui:cmdline: 'call hooks.apply_patch(ui)'
DEBUG:ui:thread command string: "call hooks.apply_patch(ui)"
DEBUG:__init__:mode:thread got commandline "call hooks.apply_patch(ui)"
DEBUG:__init__:ARGS: ['call', 'hooks.apply_patch(ui)']
DEBUG:__init__:cmd parms {'command': 'hooks.apply_patch(ui)'}
DEBUG:ui:Got key (['q'], [113])
pazz commented 5 years ago

Your log looks just as expected and it seems from the log that your hook actually got called. The log does not contain any errors, so what is your problem exactly?

One thing you might want to check is that your hooks-file (which does not have the default name!) actually gets interpreted on startup.

teto commented 5 years ago

The hook file is loaded correctly (btw having a ui popup when it doesn't would be nice). My problem is I would expect a prompt to show up and ask me for a path since I have ui.prompt in my code. Right now nothing happens. I can keep typing in alot without any issue.

teto commented 5 years ago

Also I forgot but I tried to test locally with master but it seems that the iscoroutine check always returns false https://github.com/pazz/alot/blob/1e346cac12fdce13a6fe1aec790ebb5ee1c5651e/alot/commands/globals.py#L408-L409 even if the command is "hooks.apply_patch(ui)" with apply_patch defined as:

async def apply_patch(ui):
    fromaddress = yield ui.prompt('Git repository')

what I do is the same as in the attach_keys contrib hooks on the wiki. Does that one work for you ?