read: Actually only fire fish_read, not fish_prompt event

Fixes #8797.
This commit is contained in:
Fabian Homborg 2022-03-16 20:14:59 +01:00
parent 4e2ce0af4e
commit 534646f9d3
4 changed files with 20 additions and 2 deletions

View File

@ -224,6 +224,7 @@ static int read_interactive(parser_t &parser, wcstring &buff, int nchars, bool s
conf.left_prompt_cmd = prompt;
conf.right_prompt_cmd = right_prompt;
conf.event = L"fish_read";
conf.in = in;
@ -233,7 +234,6 @@ static int read_interactive(parser_t &parser, wcstring &buff, int nchars, bool s
commandline_set_buffer(commandline, std::wcslen(commandline));
scoped_push<bool> interactive{&parser.libdata().is_interactive, true};
event_fire_generic(parser, L"fish_read");
auto mline = reader_readline(nchars);
interactive.restore();
if (mline) {

View File

@ -2799,6 +2799,7 @@ static int read_i(parser_t &parser) {
conf.syntax_check_ok = true;
conf.autosuggest_ok = check_autosuggestion_enabled(parser.vars());
conf.expand_abbrev_ok = true;
conf.event = L"fish_prompt";
if (parser.is_breakpoint() && function_exists(DEBUG_PROMPT_FUNCTION_NAME, parser)) {
conf.left_prompt_cmd = DEBUG_PROMPT_FUNCTION_NAME;
@ -4009,7 +4010,9 @@ maybe_t<wcstring> reader_data_t::readline(int nchars_or_0) {
}
first_prompt = false;
event_fire_generic(parser(), L"fish_prompt");
if (!conf.event.empty()) {
event_fire_generic(parser(), conf.event.c_str());
}
exec_prompt();
/// A helper that kicks off syntax highlighting, autosuggestion computing, and repaints.

View File

@ -196,6 +196,9 @@ struct reader_config_t {
/// Right prompt command, typically fish_right_prompt.
wcstring right_prompt_cmd{};
/// Name of the event to trigger once we're set up.
wcstring event{};
/// Whether tab completion is OK.
bool complete_ok{false};

View File

@ -144,3 +144,15 @@ expect_read_prompt()
send("jkl\n")
expect_str("ghi then jkl\r\n")
expect_prompt()
# Long line so we don't have to count prompts
sendline("""set -g fish_prompt_fired 0; function dontfire --on-event fish_prompt; set -g fish_prompt_fired (math $fish_prompt_fired + 1); end; function dofire --on-event fish_read; set -g fish_read_fired 1; end""")
expect_prompt()
sendline("read foo")
expect_read_prompt()
sendline("text")
expect_prompt()
# Once for right after setting the listener, another for after the read.
print_var_contents("fish_prompt_fired", "2")
print_var_contents("fish_read_fired", "1")