fish-shell/src/operation_context.cpp
ridiculousfish 0f7bba5f0e Introduce operation_context_t
This commit recognizes an existing pattern: many operations need some
combination of a set of variables, a way to detect cancellation, and
sometimes a parser. For example, tab completion needs a parser to execute
custom completions, the variable set, should cancel on SIGINT. Background
autosuggestions don't need a parser, but they do need the variables and
should cancel if the user types something new. Etc.

This introduces a new triple operation_context_t that wraps these concepts
up. This simplifies many method signatures and argument passing.
2020-01-16 15:21:28 -08:00

24 lines
738 B
C++

// Utilities for io redirection.
#include "config.h" // IWYU pragma: keep
#include "operation_context.h"
#include "env.h"
bool no_cancel() { return false; }
operation_context_t::operation_context_t(std::shared_ptr<parser_t> parser,
const environment_t &vars, cancel_checker_t cancel_checker)
: parser(std::move(parser)), vars(vars), cancel_checker(std::move(cancel_checker)) {}
operation_context_t operation_context_t::empty() {
static const null_environment_t nullenv{};
return operation_context_t{nullenv};
}
operation_context_t operation_context_t::globals() {
return operation_context_t{env_stack_t::globals()};
}
operation_context_t::~operation_context_t() = default;