From 827a77539af80d7ffa314d13c4cc4e7927709a55 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 10 Sep 2014 19:06:53 +0100 Subject: [PATCH] Add some color to mode specific mode line info --- src/client.cc | 4 ++-- src/input_handler.cc | 33 +++++++++++++++++++-------------- src/input_handler.hh | 3 ++- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/client.cc b/src/client.cc index d40791b5..aad37a36 100644 --- a/src/client.cc +++ b/src/client.cc @@ -53,7 +53,6 @@ DisplayLine Client::generate_mode_line() const DisplayLine status; Face info_face = get_face("Information"); Face status_face = get_face("StatusLine"); - Face prompt_face = get_face("Prompt"); status.push_back({ context().buffer().display_name(), status_face }); status.push_back({ " " + to_string((int)pos.line+1) + ":" + to_string((int)col+1) + " ", status_face }); @@ -68,7 +67,8 @@ DisplayLine Client::generate_mode_line() const if (context().buffer().flags() & Buffer::Flags::Fifo) status.push_back({ "[fifo]", info_face }); status.push_back({ " ", status_face }); - status.push_back({ m_input_handler.mode_string(), prompt_face }); + for (auto& atom : m_input_handler.mode_line()) + status.push_back(std::move(atom)); status.push_back({ " - " + context().name() + "@[" + Server::instance().session() + "]", status_face }); return status; diff --git a/src/input_handler.cc b/src/input_handler.cc index 97858e49..b0aff794 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -30,7 +30,7 @@ public: virtual void on_disabled() {} Context& context() const { return m_input_handler.context(); } - virtual String description() const = 0; + virtual DisplayLine mode_line() const = 0; virtual KeymapMode keymap_mode() const = 0; @@ -128,10 +128,15 @@ public: m_idle_timer.set_next_date(Clock::now() + idle_timeout); } - String description() const override + DisplayLine mode_line() const override { - return to_string(context().selections().size()) + - (m_count != 0 ? " sel; param=" + to_string(m_count) : " sel"); + AtomList atoms = { { to_string(context().selections().size()) + " sel", Face(Colors::Blue) } }; + if (m_count != 0) + { + atoms.push_back({ "; param=", Face(Colors::Yellow) }); + atoms.push_back({ to_string(m_count), Face(Colors::Green) }); + } + return atoms; } KeymapMode keymap_mode() const override { return KeymapMode::Normal; } @@ -407,9 +412,9 @@ public: } } - String description() const override + DisplayLine mode_line() const override { - return "menu"; + return { "menu", Face(Colors::Yellow) }; } KeymapMode keymap_mode() const override { return KeymapMode::Menu; } @@ -657,9 +662,9 @@ public: } } - String description() const override + DisplayLine mode_line() const override { - return "prompt"; + return { "prompt", Face(Colors::Yellow) }; } KeymapMode keymap_mode() const override { return KeymapMode::Prompt; } @@ -734,9 +739,9 @@ public: m_callback(key, context()); } - String description() const override + DisplayLine mode_line() const override { - return "enter key"; + return { "enter key", Face(Colors::Yellow) }; } KeymapMode keymap_mode() const override { return KeymapMode::None; } @@ -879,9 +884,9 @@ public: context().hooks().run_hook("InsertMove", key_to_str(key), context()); } - String description() const override + DisplayLine mode_line() const override { - return "insert"; + return { "insert", Face(Colors::Green) }; } KeymapMode keymap_mode() const override { return KeymapMode::Insert; } @@ -1130,9 +1135,9 @@ void InputHandler::reset_normal_mode() change_input_mode(new InputModes::Normal(*this)); } -String InputHandler::mode_string() const +DisplayLine InputHandler::mode_line() const { - return m_mode->description(); + return m_mode->mode_line(); } void InputHandler::clear_mode_trash() diff --git a/src/input_handler.hh b/src/input_handler.hh index dd027910..5515de2a 100644 --- a/src/input_handler.hh +++ b/src/input_handler.hh @@ -31,6 +31,7 @@ using PromptCallback = std::function; class InputMode; +class DisplayLine; enum class InsertMode : unsigned; class InputHandler : public SafeCountable @@ -76,7 +77,7 @@ public: Context& context() { return m_context; } const Context& context() const { return m_context; } - String mode_string() const; + DisplayLine mode_line() const; void clear_mode_trash(); private: Context m_context;