From 09cf5acb23bb8f543fc4d81652bdfc4545978008 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 5 Mar 2013 19:03:42 +0100 Subject: [PATCH] Add support for boolean options --- src/input_handler.cc | 2 +- src/main.cc | 2 +- src/option_manager.cc | 19 +++++++++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/input_handler.cc b/src/input_handler.cc index 16454499..b4fe225b 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -377,7 +377,7 @@ public: DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char }; context().ui().menu_show(candidates, menu_pos, MenuStyle::Prompt); - bool use_common_prefix = context().options()["complete_prefix"].get(); + bool use_common_prefix = context().options()["complete_prefix"].get(); String prefix = use_common_prefix ? common_prefix(candidates) : String(); if (m_completions.end - m_completions.start > prefix.length()) prefix = line.substr(m_completions.start, diff --git a/src/main.cc b/src/main.cc index 2e8692bd..3dff00f2 100644 --- a/src/main.cc +++ b/src/main.cc @@ -176,7 +176,7 @@ void do_search(Context& context) RegisterManager::instance()['/'] = ex; context.push_jump(); } - else if (ex.empty() or not context.options()["incsearch"].get()) + else if (ex.empty() or not context.options()["incsearch"].get()) return; context.editor().select(std::bind(select_next_match, _1, ex), mode); diff --git a/src/option_manager.cc b/src/option_manager.cc index f08a23e9..477deab6 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -54,6 +54,21 @@ template class TypedOption; template const int& Option::get() const; template void Option::set(const int&); +// TypedOption specializations; +template<> String TypedOption::get_as_string() const { return m_value ? "true" : "false"; } +template<> void TypedOption::set_from_string(const String& str) +{ + if (str == "true" or str == "yes") + m_value = true; + else if (str == "false" or str == "no") + m_value = false; + else + throw runtime_error("boolean values are either true, yes, false or no"); +} +template class TypedOption; +template const bool& Option::get() const; +template void Option::set(const bool&); + OptionManager::OptionManager(OptionManager& parent) : m_parent(&parent) { @@ -164,8 +179,8 @@ GlobalOptions::GlobalOptions() declare_option("eolformat", "lf"); declare_option("BOM", "no"); declare_option("shell", "sh"); - declare_option("complete_prefix", 1); - declare_option("incsearch", 1); + declare_option("complete_prefix", true); + declare_option("incsearch", true); declare_option("ignored_files", R"(^(\..*|.*\.(o|so|a)))$)"); declare_option("filetype", ""); }