summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-10-10 21:34:19 +0100
committerMaxime Coste <frrrwww@gmail.com>2013-10-11 00:17:21 +0100
commitc478a97a2f043325dffa9612f69a8df22c81d6a6 (patch)
tree0b68a8a52c1dfbd00c61c156466f0d7155c76843 /src
parent74fe8b5e8d9ff7497b2ef98b296268b38c12b24c (diff)
Let InputModes describe themselves for status line display
Diffstat (limited to 'src')
-rw-r--r--src/client.cc54
-rw-r--r--src/client.hh7
2 files changed, 45 insertions, 16 deletions
diff --git a/src/client.cc b/src/client.cc
index 69fa0302..f2f1ef64 100644
--- a/src/client.cc
+++ b/src/client.cc
@@ -29,6 +29,8 @@ public:
virtual void on_replaced() {}
Context& context() const { return m_client.context(); }
+ virtual String description() const = 0;
+
using Insertion = Client::Insertion;
Insertion& last_insert() { return m_client.m_last_insert; }
@@ -75,6 +77,12 @@ public:
m_idle_timer.set_next_date(Clock::now() + idle_timeout);
}
+ String description() const override
+ {
+ return to_string(context().editor().selections().size()) +
+ (m_count != 0 ? " sel; param=" + to_string(m_count) : " sel");
+ }
+
private:
int m_count = 0;
Timer m_idle_timer;
@@ -248,6 +256,12 @@ public:
}
}
+ String description() const override
+ {
+ return "menu";
+ }
+
+
private:
MenuCallback m_callback;
@@ -444,6 +458,12 @@ public:
}
}
+ String description() const override
+ {
+ return "prompt";
+ }
+
+
private:
void display() const
{
@@ -477,7 +497,12 @@ public:
{
reset_normal_mode();
m_callback(key, context());
- }
+ }
+
+ String description() const override
+ {
+ return "enter key";
+ }
private:
KeyCallback m_callback;
@@ -894,6 +919,11 @@ public:
if (moved)
context().hooks().run_hook("InsertMove", key_to_str(key), context());
}
+
+ String description() const override
+ {
+ return "insert";
+ }
private:
enum class Mode { Default, Complete, InsertReg };
Mode m_mode = Mode::Default;
@@ -1025,25 +1055,21 @@ void Client::print_status(DisplayLine status_line)
m_context.window().forget_timestamp();
}
-static DisplayLine generate_mode_line(Client& client)
+DisplayLine Client::generate_mode_line() const
{
- auto& context = client.context();
- auto pos = context.editor().main_selection().last();
- auto col = context.buffer()[pos.line].char_count_to(pos.column);
+ auto pos = context().editor().main_selection().last();
+ auto col = context().buffer()[pos.line].char_count_to(pos.column);
std::ostringstream oss;
- oss << context.buffer().display_name()
+ oss << context().buffer().display_name()
<< " " << (int)pos.line+1 << ":" << (int)col+1;
- if (context.buffer().is_modified())
+ if (context().buffer().is_modified())
oss << " [+]";
- if (context.client().is_recording())
+ if (is_recording())
oss << " [recording]";
- if (context.buffer().flags() & Buffer::Flags::New)
+ if (context().buffer().flags() & Buffer::Flags::New)
oss << " [new file]";
- oss << " [" << context.editor().selections().size() << " sel]";
- if (context.editor().is_editing())
- oss << " [insert]";
- oss << " - " << client.name();
+ oss << " [" << m_mode->description() << "]" << " - " << name();
return { oss.str(), get_color("StatusLine") };
}
@@ -1058,7 +1084,7 @@ void Client::redraw_ifn()
m_context.window().update_display_buffer();;
m_context.ui().draw(m_context.window().display_buffer(),
- m_status_line, generate_mode_line(*this));
+ m_status_line, generate_mode_line());
}
}
diff --git a/src/client.hh b/src/client.hh
index a72e207c..b7cbe745 100644
--- a/src/client.hh
+++ b/src/client.hh
@@ -76,6 +76,7 @@ public:
void stop_recording();
Context& context() { return m_context; }
+ const Context& context() const { return m_context; }
const String& name() const { return m_name; }
void set_name(String name) { m_name = std::move(name); }
@@ -85,14 +86,16 @@ public:
UserInterface& ui() const { return *m_ui; }
private:
+ void change_input_mode(InputMode* new_mode);
+
+ DisplayLine generate_mode_line() const;
+
Context m_context;
friend class InputMode;
std::unique_ptr<UserInterface> m_ui;
std::unique_ptr<InputMode> m_mode;
std::vector<std::unique_ptr<InputMode>> m_mode_trash;
- void change_input_mode(InputMode* new_mode);
-
String m_name;
DisplayLine m_status_line;