Let InputModes describe themselves for status line display
This commit is contained in:
parent
74fe8b5e8d
commit
c478a97a2f
|
@ -29,6 +29,8 @@ public:
|
||||||
virtual void on_replaced() {}
|
virtual void on_replaced() {}
|
||||||
Context& context() const { return m_client.context(); }
|
Context& context() const { return m_client.context(); }
|
||||||
|
|
||||||
|
virtual String description() const = 0;
|
||||||
|
|
||||||
using Insertion = Client::Insertion;
|
using Insertion = Client::Insertion;
|
||||||
Insertion& last_insert() { return m_client.m_last_insert; }
|
Insertion& last_insert() { return m_client.m_last_insert; }
|
||||||
|
|
||||||
|
@ -75,6 +77,12 @@ public:
|
||||||
m_idle_timer.set_next_date(Clock::now() + idle_timeout);
|
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:
|
private:
|
||||||
int m_count = 0;
|
int m_count = 0;
|
||||||
Timer m_idle_timer;
|
Timer m_idle_timer;
|
||||||
|
@ -248,6 +256,12 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String description() const override
|
||||||
|
{
|
||||||
|
return "menu";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MenuCallback m_callback;
|
MenuCallback m_callback;
|
||||||
|
|
||||||
|
@ -444,6 +458,12 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String description() const override
|
||||||
|
{
|
||||||
|
return "prompt";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void display() const
|
void display() const
|
||||||
{
|
{
|
||||||
|
@ -477,7 +497,12 @@ public:
|
||||||
{
|
{
|
||||||
reset_normal_mode();
|
reset_normal_mode();
|
||||||
m_callback(key, context());
|
m_callback(key, context());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String description() const override
|
||||||
|
{
|
||||||
|
return "enter key";
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KeyCallback m_callback;
|
KeyCallback m_callback;
|
||||||
|
@ -894,6 +919,11 @@ public:
|
||||||
if (moved)
|
if (moved)
|
||||||
context().hooks().run_hook("InsertMove", key_to_str(key), context());
|
context().hooks().run_hook("InsertMove", key_to_str(key), context());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String description() const override
|
||||||
|
{
|
||||||
|
return "insert";
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
enum class Mode { Default, Complete, InsertReg };
|
enum class Mode { Default, Complete, InsertReg };
|
||||||
Mode m_mode = Mode::Default;
|
Mode m_mode = Mode::Default;
|
||||||
|
@ -1025,25 +1055,21 @@ void Client::print_status(DisplayLine status_line)
|
||||||
m_context.window().forget_timestamp();
|
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 pos = context.editor().main_selection().last();
|
auto col = context().buffer()[pos.line].char_count_to(pos.column);
|
||||||
auto col = context.buffer()[pos.line].char_count_to(pos.column);
|
|
||||||
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << context.buffer().display_name()
|
oss << context().buffer().display_name()
|
||||||
<< " " << (int)pos.line+1 << ":" << (int)col+1;
|
<< " " << (int)pos.line+1 << ":" << (int)col+1;
|
||||||
if (context.buffer().is_modified())
|
if (context().buffer().is_modified())
|
||||||
oss << " [+]";
|
oss << " [+]";
|
||||||
if (context.client().is_recording())
|
if (is_recording())
|
||||||
oss << " [recording]";
|
oss << " [recording]";
|
||||||
if (context.buffer().flags() & Buffer::Flags::New)
|
if (context().buffer().flags() & Buffer::Flags::New)
|
||||||
oss << " [new file]";
|
oss << " [new file]";
|
||||||
oss << " [" << context.editor().selections().size() << " sel]";
|
oss << " [" << m_mode->description() << "]" << " - " << name();
|
||||||
if (context.editor().is_editing())
|
|
||||||
oss << " [insert]";
|
|
||||||
oss << " - " << client.name();
|
|
||||||
return { oss.str(), get_color("StatusLine") };
|
return { oss.str(), get_color("StatusLine") };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1058,7 +1084,7 @@ void Client::redraw_ifn()
|
||||||
m_context.window().update_display_buffer();;
|
m_context.window().update_display_buffer();;
|
||||||
|
|
||||||
m_context.ui().draw(m_context.window().display_buffer(),
|
m_context.ui().draw(m_context.window().display_buffer(),
|
||||||
m_status_line, generate_mode_line(*this));
|
m_status_line, generate_mode_line());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,7 @@ public:
|
||||||
void stop_recording();
|
void stop_recording();
|
||||||
|
|
||||||
Context& context() { return m_context; }
|
Context& context() { return m_context; }
|
||||||
|
const Context& context() const { return m_context; }
|
||||||
const String& name() const { return m_name; }
|
const String& name() const { return m_name; }
|
||||||
void set_name(String name) { m_name = std::move(name); }
|
void set_name(String name) { m_name = std::move(name); }
|
||||||
|
|
||||||
|
@ -85,14 +86,16 @@ public:
|
||||||
|
|
||||||
UserInterface& ui() const { return *m_ui; }
|
UserInterface& ui() const { return *m_ui; }
|
||||||
private:
|
private:
|
||||||
|
void change_input_mode(InputMode* new_mode);
|
||||||
|
|
||||||
|
DisplayLine generate_mode_line() const;
|
||||||
|
|
||||||
Context m_context;
|
Context m_context;
|
||||||
friend class InputMode;
|
friend class InputMode;
|
||||||
std::unique_ptr<UserInterface> m_ui;
|
std::unique_ptr<UserInterface> m_ui;
|
||||||
std::unique_ptr<InputMode> m_mode;
|
std::unique_ptr<InputMode> m_mode;
|
||||||
std::vector<std::unique_ptr<InputMode>> m_mode_trash;
|
std::vector<std::unique_ptr<InputMode>> m_mode_trash;
|
||||||
|
|
||||||
void change_input_mode(InputMode* new_mode);
|
|
||||||
|
|
||||||
String m_name;
|
String m_name;
|
||||||
DisplayLine m_status_line;
|
DisplayLine m_status_line;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user