Rename UI to Client
This commit is contained in:
parent
286462a2f6
commit
9b6b6b6b17
35
src/client.cc
Normal file
35
src/client.cc
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef ui_hh_INCLUDED
|
#ifndef client_hh_INCLUDED
|
||||||
#define ui_hh_INCLUDED
|
#define client_hh_INCLUDED
|
||||||
|
|
||||||
#include "keys.hh"
|
#include "keys.hh"
|
||||||
#include "completion.hh"
|
#include "completion.hh"
|
||||||
|
@ -11,10 +11,10 @@ class Editor;
|
||||||
class Window;
|
class Window;
|
||||||
class String;
|
class String;
|
||||||
|
|
||||||
class UI
|
class Client
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~UI() {}
|
virtual ~Client() {}
|
||||||
|
|
||||||
virtual void draw_window(Window& window) = 0;
|
virtual void draw_window(Window& window) = 0;
|
||||||
virtual void print_status(const String& status) = 0;
|
virtual void print_status(const String& status) = 0;
|
||||||
|
@ -24,7 +24,7 @@ public:
|
||||||
|
|
||||||
struct prompt_aborted {};
|
struct prompt_aborted {};
|
||||||
|
|
||||||
extern UI* current_ui;
|
extern Client* current_client;
|
||||||
|
|
||||||
void draw_editor_ifn(Editor& editor);
|
void draw_editor_ifn(Editor& editor);
|
||||||
String prompt(const String& text, Completer completer = complete_nothing);
|
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
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include "buffer.hh"
|
#include "buffer.hh"
|
||||||
#include "window.hh"
|
#include "window.hh"
|
||||||
#include "file.hh"
|
#include "file.hh"
|
||||||
#include "ui.hh"
|
#include "client.hh"
|
||||||
#include "regex.hh"
|
#include "regex.hh"
|
||||||
#include "highlighter_registry.hh"
|
#include "highlighter_registry.hh"
|
||||||
#include "filter_registry.hh"
|
#include "filter_registry.hh"
|
||||||
|
@ -671,19 +671,19 @@ private:
|
||||||
char m_name;
|
char m_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BatchUI : public UI
|
class BatchClient : public Client
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BatchUI(const KeyList& keys)
|
BatchClient(const KeyList& keys)
|
||||||
: m_keys(keys), m_pos(0)
|
: m_keys(keys), m_pos(0)
|
||||||
{
|
{
|
||||||
m_previous_ui = current_ui;
|
m_previous_client = current_client;
|
||||||
current_ui = this;
|
current_client = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
~BatchUI()
|
~BatchClient()
|
||||||
{
|
{
|
||||||
current_ui = m_previous_ui;
|
current_client = m_previous_client;
|
||||||
}
|
}
|
||||||
|
|
||||||
String prompt(const String&, Completer)
|
String prompt(const String&, Completer)
|
||||||
|
@ -709,26 +709,26 @@ public:
|
||||||
|
|
||||||
void print_status(const String& status)
|
void print_status(const String& status)
|
||||||
{
|
{
|
||||||
m_previous_ui->print_status(status);
|
m_previous_client->print_status(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_window(Window& window)
|
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(); }
|
bool has_key_left() const { return m_pos < m_keys.size(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const KeyList& m_keys;
|
const KeyList& m_keys;
|
||||||
size_t m_pos;
|
size_t m_pos;
|
||||||
UI* m_previous_ui;
|
Client* m_previous_client;
|
||||||
};
|
};
|
||||||
|
|
||||||
void exec_keys(const KeyList& keys,
|
void exec_keys(const KeyList& keys,
|
||||||
const Context& context)
|
const Context& context)
|
||||||
{
|
{
|
||||||
BatchUI batch_ui(keys);
|
BatchClient batch_client(keys);
|
||||||
|
|
||||||
RegisterRestorer quote('"');
|
RegisterRestorer quote('"');
|
||||||
RegisterRestorer slash('/');
|
RegisterRestorer slash('/');
|
||||||
|
@ -740,9 +740,9 @@ void exec_keys(const KeyList& keys,
|
||||||
scoped_edition edition(editor);
|
scoped_edition edition(editor);
|
||||||
|
|
||||||
int count = 0;
|
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))
|
if (key.modifiers == Key::Modifiers::None and isdigit(key.key))
|
||||||
count = count * 10 + key.key - '0';
|
count = count * 10 + key.key - '0';
|
||||||
|
|
|
@ -31,7 +31,6 @@ namespace Kakoune
|
||||||
Context main_context;
|
Context main_context;
|
||||||
bool quit_requested = false;
|
bool quit_requested = false;
|
||||||
|
|
||||||
|
|
||||||
struct InsertSequence
|
struct InsertSequence
|
||||||
{
|
{
|
||||||
IncrementalInserter::Mode mode;
|
IncrementalInserter::Mode mode;
|
||||||
|
@ -447,8 +446,8 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NCursesUI ui;
|
NCursesClient client;
|
||||||
current_ui = &ui;
|
current_client = &client;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -471,7 +470,7 @@ int main(int argc, char* argv[])
|
||||||
main_context = Context(*buffer->get_or_create_window());
|
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;
|
int count = 0;
|
||||||
while(not quit_requested)
|
while(not quit_requested)
|
||||||
{
|
{
|
||||||
|
@ -486,7 +485,7 @@ int main(int argc, char* argv[])
|
||||||
if (it != keymap.end())
|
if (it != keymap.end())
|
||||||
{
|
{
|
||||||
it->second(main_context.window(), count);
|
it->second(main_context.window(), count);
|
||||||
current_ui->draw_window(main_context.window());
|
current_client->draw_window(main_context.window());
|
||||||
}
|
}
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
NCursesUI::NCursesUI()
|
NCursesClient::NCursesClient()
|
||||||
{
|
{
|
||||||
// setlocale(LC_ALL, "");
|
// setlocale(LC_ALL, "");
|
||||||
initscr();
|
initscr();
|
||||||
|
@ -26,7 +26,7 @@ NCursesUI::NCursesUI()
|
||||||
ESCDELAY=25;
|
ESCDELAY=25;
|
||||||
}
|
}
|
||||||
|
|
||||||
NCursesUI::~NCursesUI()
|
NCursesClient::~NCursesClient()
|
||||||
{
|
{
|
||||||
endwin();
|
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;
|
int max_x,max_y;
|
||||||
getmaxyx(stdscr, max_y, max_x);
|
getmaxyx(stdscr, max_y, max_x);
|
||||||
|
@ -160,7 +160,7 @@ void NCursesUI::draw_window(Window& window)
|
||||||
last_status_length = status_line.length();
|
last_status_length = status_line.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
Key NCursesUI::get_key()
|
Key NCursesClient::get_key()
|
||||||
{
|
{
|
||||||
char c = getch();
|
char c = getch();
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ Key NCursesUI::get_key()
|
||||||
return Key(modifiers, c);
|
return Key(modifiers, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
String NCursesUI::prompt(const String& text, Completer completer)
|
String NCursesClient::prompt(const String& text, Completer completer)
|
||||||
{
|
{
|
||||||
curs_set(2);
|
curs_set(2);
|
||||||
auto restore_cursor = on_scope_end([]() { curs_set(0); });
|
auto restore_cursor = on_scope_end([]() { curs_set(0); });
|
||||||
|
@ -321,7 +321,7 @@ String NCursesUI::prompt(const String& text, Completer completer)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NCursesUI::print_status(const String& status)
|
void NCursesClient::print_status(const String& status)
|
||||||
{
|
{
|
||||||
int x,y;
|
int x,y;
|
||||||
getmaxyx(stdscr, y, x);
|
getmaxyx(stdscr, y, x);
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
#ifndef ncurses_hh_INCLUDED
|
#ifndef ncurses_hh_INCLUDED
|
||||||
#define ncurses_hh_INCLUDED
|
#define ncurses_hh_INCLUDED
|
||||||
|
|
||||||
#include "ui.hh"
|
#include "client.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
class NCursesUI : public UI
|
class NCursesClient : public Client
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NCursesUI();
|
NCursesClient();
|
||||||
~NCursesUI();
|
~NCursesClient();
|
||||||
|
|
||||||
NCursesUI(const NCursesUI&) = delete;
|
NCursesClient(const NCursesClient&) = delete;
|
||||||
NCursesUI& operator=(const NCursesUI&) = delete;
|
NCursesClient& operator=(const NCursesClient&) = delete;
|
||||||
|
|
||||||
void draw_window(Window& window);
|
void draw_window(Window& window);
|
||||||
void print_status(const String& status);
|
void print_status(const String& status);
|
||||||
|
|
35
src/ui.cc
35
src/ui.cc
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user