Allow turning off autosuggestions

This adds a variable, $fish_autosuggestion_enabled.

When set to 0, it will turn off autosuggestions/highlighting.
Setting it to anything else will enable it (which also
means this remains enabled by default).
This commit is contained in:
Fabian Homborg 2021-10-21 16:54:24 +02:00
parent d81f817f70
commit 86b8cc2097
3 changed files with 25 additions and 1 deletions

View file

@ -235,6 +235,14 @@ static void handle_fish_history_change(const env_stack_t &vars) {
reader_change_history(history_session_id(vars));
}
static void handle_autosuggestion_change(const env_stack_t &vars) {
bool enabled = true;
if (auto val = vars.get(L"fish_autosuggestion_enabled")) {
if (val->as_string() == L"0") enabled = false;
}
reader_set_autosuggestion_enabled(enabled);
}
static void handle_function_path_change(const env_stack_t &vars) {
UNUSED(vars);
function_invalidate_path();
@ -340,6 +348,7 @@ static std::unique_ptr<const var_dispatch_table_t> create_dispatch_table() {
var_dispatch_table->add(L"fish_function_path", handle_function_path_change);
var_dispatch_table->add(L"fish_read_limit", handle_read_limit_change);
var_dispatch_table->add(L"fish_history", handle_fish_history_change);
var_dispatch_table->add(L"fish_autosuggestion_enabled", handle_autosuggestion_change);
var_dispatch_table->add(L"TZ", handle_tz_change);
var_dispatch_table->add(L"fish_use_posix_spawn", handle_fish_use_posix_spawn_change);
var_dispatch_table->add(L"fish_trace", handle_fish_trace);

View file

@ -603,7 +603,7 @@ struct layout_data_t {
class reader_data_t : public std::enable_shared_from_this<reader_data_t> {
public:
/// Configuration for the reader.
const reader_config_t conf;
reader_config_t conf;
/// The parser being used.
std::shared_ptr<parser_t> parser_ref;
/// String containing the whole current commandline.
@ -2612,6 +2612,18 @@ void reader_change_history(const wcstring &name) {
}
}
void reader_set_autosuggestion_enabled(bool enable) {
// We don't need to _change_ if we're not initialized yet.
reader_data_t *data = current_data_or_null();
if (data) {
if (data->conf.autosuggest_ok != enable) {
data->conf.autosuggest_ok = enable;
data->force_exec_prompt_and_repaint = true;
data->inputter.queue_char(readline_cmd_t::repaint);
}
}
}
/// Add a new reader to the reader stack.
/// \return a shared pointer to it.
static std::shared_ptr<reader_data_t> reader_push_ret(parser_t &parser,

View file

@ -149,6 +149,9 @@ void restore_term_mode();
/// Change the history file for the current command reading context.
void reader_change_history(const wcstring &name);
/// Enable or disable autosuggestions.
void reader_set_autosuggestion_enabled(bool enable);
/// Write the title to the titlebar. This function is called just before a new application starts
/// executing and just after it finishes.
///