Rename UI to Client

This commit is contained in:
Maxime Coste 2012-06-28 14:11:43 +02:00
parent 286462a2f6
commit 9b6b6b6b17
7 changed files with 71 additions and 73 deletions

35
src/client.cc Normal file
View File

@ -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<Window*>(&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);
}
}

View File

@ -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

View File

@ -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,12 +709,12 @@ 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(); }
@ -722,13 +722,13 @@ public:
private:
const KeyList& m_keys;
size_t m_pos;
UI* m_previous_ui;
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';

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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<Window*>(&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);
}
}