fish-shell/src/builtin_emit.cpp
ridiculousfish ff55249447 Make events per-parser
This makes the following changes:

1. Events in background threads are executed in those threads, instead of
being silently dropped

2. Blocked events are now per-parser instead of global

3. Events are posted in builtin_set instead of within the environment stack

The last one means that we no longer support event handlers for implicit
sets like (example) argv. Instead only the `set` builtin (and also `cd`)
post variable-change events.

Events from universal variable changes are still not fully rationalized.
2019-06-03 02:48:35 -07:00

37 lines
1.1 KiB
C++

// Implementation of the emit builtin.
#include "config.h" // IWYU pragma: keep
#include "builtin.h"
#include "builtin_emit.h"
#include "common.h"
#include "event.h"
#include "fallback.h" // IWYU pragma: keep
#include "io.h"
#include "wutil.h" // IWYU pragma: keep
/// Implementation of the builtin emit command, used to create events.
int builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
help_only_cmd_opts_t opts;
int optind;
int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {
builtin_print_help(parser, streams, cmd, streams.out);
return STATUS_CMD_OK;
}
if (!argv[optind]) {
streams.err.append_format(L"%ls: expected event name\n", cmd);
return STATUS_INVALID_ARGS;
}
const wchar_t *eventname = argv[optind];
wcstring_list_t args(argv + optind + 1, argv + argc);
event_fire_generic(parser, eventname, &args);
return STATUS_CMD_OK;
}