Unix 对话实用程序在对发出的事件做出反应时在 fish shell 中失败

Unix Dialog utility fails in fish shell when reacting to an emitted event

我有这个功能(已知可以正常工作)

function problem_open -e on_problem_open -d "select from existing problems"
    set matches (find $FD_PROB_HOME/ -maxdepth 1 -mindepth 1 -type d ! -name ".git")

    if test 1 -eq (count $matches)
        if test -d $matches
            set -U FD_PROB_CURRENT $matches[1]
            echo "chose option 1"
            return
        end
    end
    set -g dcmd "dialog --stdout --no-tags --menu 'select the file to edit' 20 60 20 "
    set c 1
    for option in $matches
        set l (basename "$option")
        set -g dcmd "$dcmd $c '$l'"
        set c (math $c + 1)
    end
    set choice (eval "$dcmd") 
    #clear
    if test $status -eq 0
        echo "edit option $choice"
        set -U FD_PROB_CURRENT $matches[$choice]
    end
end

当我直接调用 problem_open 时,对话框显示正常。当我通过 emit on_problem_open 间接调用函数时,对话框不显示。

知道为什么会这样吗?这是事件的预期行为吗?

我可以解决这个问题,但这将是一个棘手的问题。

您的示例在这里没问题,但一个技巧是确保该函数是手动定义的或在您的 config.fish 中定义的,而不是依赖它自动加载。 Functions stored in autoloaded files do not listen to event handlers until they are run the first time.

在与 fish 开发团队成员 Fabian Homborg (@faho) 讨论后,由于类似于 [=17] 中令人尊敬的 "contended access to screen updates in a UI thread" 问题的原因,所需的功能似乎无法使用(永远不会) =]等。不仅如此,开发团队打算在未来将事件调用移到另一个线程中,因此没有希望从事件处理程序与终端交互。

我最终做的是创建一个不同的 API,当需要用户 IO 时,它使用直接函数调用。参见函数 _define_subcommand_nonevented 的实现。