diff --git a/src/client.cc b/src/client.cc new file mode 100644 index 00000000..d1950985 --- /dev/null +++ b/src/client.cc @@ -0,0 +1,35 @@ +#include "client.hh" + +#include "window.hh" + +namespace Kakoune +{ + +Client* current_client = nullptr; + +void draw_editor_ifn(Editor& editor) +{ + Window* window = dynamic_cast(&editor); + if (current_client and window) + current_client->draw_window(*window); +} + +String prompt(const String& text, Completer completer) +{ + assert(current_client); + return current_client->prompt(text, completer); +} + +Key get_key() +{ + assert(current_client); + return current_client->get_key(); +} + +void print_status(const String& status) +{ + assert(current_client); + return current_client->print_status(status); +} + +} diff --git a/src/ui.hh b/src/client.hh similarity index 78% rename from src/ui.hh rename to src/client.hh index d7ca510a..b41de55b 100644 --- a/src/ui.hh +++ b/src/client.hh @@ -1,5 +1,5 @@ -#ifndef ui_hh_INCLUDED -#define ui_hh_INCLUDED +#ifndef client_hh_INCLUDED +#define client_hh_INCLUDED #include "keys.hh" #include "completion.hh" @@ -11,10 +11,10 @@ class Editor; class Window; class String; -class UI +class Client { public: - virtual ~UI() {} + virtual ~Client() {} virtual void draw_window(Window& window) = 0; virtual void print_status(const String& status) = 0; @@ -24,7 +24,7 @@ public: struct prompt_aborted {}; -extern UI* current_ui; +extern Client* current_client; void draw_editor_ifn(Editor& editor); String prompt(const String& text, Completer completer = complete_nothing); @@ -33,5 +33,4 @@ void print_status(const String& status); } -#endif // ui_hh_INCLUDED - +#endif // client_hh_INCLUDED diff --git a/src/commands.cc b/src/commands.cc index c31b99c3..0d42b060 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -7,7 +7,7 @@ #include "buffer.hh" #include "window.hh" #include "file.hh" -#include "ui.hh" +#include "client.hh" #include "regex.hh" #include "highlighter_registry.hh" #include "filter_registry.hh" @@ -671,19 +671,19 @@ private: char m_name; }; -class BatchUI : public UI +class BatchClient : public Client { public: - BatchUI(const KeyList& keys) + BatchClient(const KeyList& keys) : m_keys(keys), m_pos(0) { - m_previous_ui = current_ui; - current_ui = this; + m_previous_client = current_client; + current_client = this; } - ~BatchUI() + ~BatchClient() { - current_ui = m_previous_ui; + current_client = m_previous_client; } String prompt(const String&, Completer) @@ -709,26 +709,26 @@ public: void print_status(const String& status) { - m_previous_ui->print_status(status); + m_previous_client->print_status(status); } void draw_window(Window& window) { - m_previous_ui->draw_window(window); + m_previous_client->draw_window(window); } bool has_key_left() const { return m_pos < m_keys.size(); } private: const KeyList& m_keys; - size_t m_pos; - UI* m_previous_ui; + size_t m_pos; + Client* m_previous_client; }; void exec_keys(const KeyList& keys, const Context& context) { - BatchUI batch_ui(keys); + BatchClient batch_client(keys); RegisterRestorer quote('"'); RegisterRestorer slash('/'); @@ -740,9 +740,9 @@ void exec_keys(const KeyList& keys, scoped_edition edition(editor); int count = 0; - while (batch_ui.has_key_left()) + while (batch_client.has_key_left()) { - Key key = batch_ui.get_key(); + Key key = batch_client.get_key(); if (key.modifiers == Key::Modifiers::None and isdigit(key.key)) count = count * 10 + key.key - '0'; diff --git a/src/main.cc b/src/main.cc index aa084566..9a9c2008 100644 --- a/src/main.cc +++ b/src/main.cc @@ -31,7 +31,6 @@ namespace Kakoune Context main_context; bool quit_requested = false; - struct InsertSequence { IncrementalInserter::Mode mode; @@ -447,8 +446,8 @@ int main(int argc, char* argv[]) try { - NCursesUI ui; - current_ui = &ui; + NCursesClient client; + current_client = &client; try { @@ -471,7 +470,7 @@ int main(int argc, char* argv[]) main_context = Context(*buffer->get_or_create_window()); } - current_ui->draw_window(main_context.window()); + current_client->draw_window(main_context.window()); int count = 0; while(not quit_requested) { @@ -486,7 +485,7 @@ int main(int argc, char* argv[]) if (it != keymap.end()) { it->second(main_context.window(), count); - current_ui->draw_window(main_context.window()); + current_client->draw_window(main_context.window()); } count = 0; } diff --git a/src/ncurses.cc b/src/ncurses.cc index 791b72b4..0daaabe9 100644 --- a/src/ncurses.cc +++ b/src/ncurses.cc @@ -11,7 +11,7 @@ namespace Kakoune { -NCursesUI::NCursesUI() +NCursesClient::NCursesClient() { // setlocale(LC_ALL, ""); initscr(); @@ -26,7 +26,7 @@ NCursesUI::NCursesUI() ESCDELAY=25; } -NCursesUI::~NCursesUI() +NCursesClient::~NCursesClient() { endwin(); } @@ -87,7 +87,7 @@ static void set_color(Color fg_color, Color bg_color) } } -void NCursesUI::draw_window(Window& window) +void NCursesClient::draw_window(Window& window) { int max_x,max_y; getmaxyx(stdscr, max_y, max_x); @@ -160,7 +160,7 @@ void NCursesUI::draw_window(Window& window) last_status_length = status_line.length(); } -Key NCursesUI::get_key() +Key NCursesClient::get_key() { char c = getch(); @@ -184,7 +184,7 @@ Key NCursesUI::get_key() return Key(modifiers, c); } -String NCursesUI::prompt(const String& text, Completer completer) +String NCursesClient::prompt(const String& text, Completer completer) { curs_set(2); auto restore_cursor = on_scope_end([]() { curs_set(0); }); @@ -321,7 +321,7 @@ String NCursesUI::prompt(const String& text, Completer completer) return result; } -void NCursesUI::print_status(const String& status) +void NCursesClient::print_status(const String& status) { int x,y; getmaxyx(stdscr, y, x); diff --git a/src/ncurses.hh b/src/ncurses.hh index 640b0fd5..8583240b 100644 --- a/src/ncurses.hh +++ b/src/ncurses.hh @@ -1,19 +1,19 @@ #ifndef ncurses_hh_INCLUDED #define ncurses_hh_INCLUDED -#include "ui.hh" +#include "client.hh" namespace Kakoune { -class NCursesUI : public UI +class NCursesClient : public Client { public: - NCursesUI(); - ~NCursesUI(); + NCursesClient(); + ~NCursesClient(); - NCursesUI(const NCursesUI&) = delete; - NCursesUI& operator=(const NCursesUI&) = delete; + NCursesClient(const NCursesClient&) = delete; + NCursesClient& operator=(const NCursesClient&) = delete; void draw_window(Window& window); void print_status(const String& status); diff --git a/src/ui.cc b/src/ui.cc deleted file mode 100644 index 319c9a35..00000000 --- a/src/ui.cc +++ /dev/null @@ -1,35 +0,0 @@ -#include "ui.hh" - -#include "window.hh" - -namespace Kakoune -{ - -UI* current_ui = nullptr; - -void draw_editor_ifn(Editor& editor) -{ - Window* window = dynamic_cast(&editor); - if (current_ui and window) - current_ui->draw_window(*window); -} - -String prompt(const String& text, Completer completer) -{ - assert(current_ui); - return current_ui->prompt(text, completer); -} - -Key get_key() -{ - assert(current_ui); - return current_ui->get_key(); -} - -void print_status(const String& status) -{ - assert(current_ui); - return current_ui->print_status(status); -} - -}