Reorganize slightly local client creation
This commit is contained in:
parent
3552152b34
commit
0c41c14187
|
@ -66,15 +66,11 @@ void ClientManager::handle_pending_inputs() const
|
||||||
|
|
||||||
void ClientManager::remove_client(Client& client)
|
void ClientManager::remove_client(Client& client)
|
||||||
{
|
{
|
||||||
for (auto it = m_clients.begin(); it != m_clients.end(); ++it)
|
auto it = find_if(m_clients,
|
||||||
{
|
[&](const std::unique_ptr<Client>& ptr)
|
||||||
if (it->get() == &client)
|
{ return ptr.get() == &client; });
|
||||||
{
|
kak_assert(it != m_clients.end());
|
||||||
m_clients.erase(it);
|
m_clients.erase(it);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
kak_assert(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowAndSelections ClientManager::get_free_window(Buffer& buffer)
|
WindowAndSelections ClientManager::get_free_window(Buffer& buffer)
|
||||||
|
|
64
src/main.cc
64
src/main.cc
|
@ -227,24 +227,43 @@ void register_options()
|
||||||
UserInterface::Options{});
|
UserInterface::Options{});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename UI>
|
std::unique_ptr<UserInterface> create_local_ui(bool dummy_ui)
|
||||||
void create_local_client(StringView init_command, bool startup_error)
|
|
||||||
{
|
{
|
||||||
struct LocalUI : UI
|
struct DummyUI : UserInterface
|
||||||
|
{
|
||||||
|
void menu_show(ConstArrayView<String>, CharCoord, Face, Face, MenuStyle) override {}
|
||||||
|
void menu_select(int) override {}
|
||||||
|
void menu_hide() override {}
|
||||||
|
|
||||||
|
void info_show(StringView, StringView, CharCoord, Face, InfoStyle) override {}
|
||||||
|
void info_hide() override {}
|
||||||
|
|
||||||
|
void draw(const DisplayBuffer&, const Face&) override {}
|
||||||
|
void draw_status(const DisplayLine&, const DisplayLine&, const Face&) override {}
|
||||||
|
CharCoord dimensions() override { return {24,80}; }
|
||||||
|
bool is_key_available() override { return false; }
|
||||||
|
Key get_key() override { return Key::Invalid; }
|
||||||
|
void refresh() override {}
|
||||||
|
void set_input_callback(InputCallback) override {}
|
||||||
|
void set_ui_options(const Options&) override {}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dummy_ui)
|
||||||
|
return make_unique<DummyUI>();
|
||||||
|
|
||||||
|
struct LocalUI : NCursesUI
|
||||||
{
|
{
|
||||||
~LocalUI()
|
~LocalUI()
|
||||||
{
|
{
|
||||||
if (not ClientManager::instance().empty() and fork())
|
if (not ClientManager::instance().empty() and fork())
|
||||||
{
|
{
|
||||||
this->UI::~UI();
|
this->NCursesUI::~NCursesUI();
|
||||||
write_stdout("detached from terminal\n");
|
write_stdout("detached from terminal\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (std::is_same<UI, NCursesUI>::value)
|
|
||||||
{
|
|
||||||
if (not isatty(1))
|
if (not isatty(1))
|
||||||
throw runtime_error("stdout is not a tty");
|
throw runtime_error("stdout is not a tty");
|
||||||
|
|
||||||
|
@ -257,10 +276,14 @@ void create_local_client(StringView init_command, bool startup_error)
|
||||||
close(tty);
|
close(tty);
|
||||||
create_fifo_buffer("*stdin*", fd);
|
create_fifo_buffer("*stdin*", fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return make_unique<LocalUI>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void create_local_client(std::unique_ptr<UserInterface> ui, StringView init_command, bool startup_error)
|
||||||
|
{
|
||||||
static Client* client = ClientManager::instance().create_client(
|
static Client* client = ClientManager::instance().create_client(
|
||||||
make_unique<LocalUI>(), get_env_vars(), init_command);
|
std::move(ui), get_env_vars(), init_command);
|
||||||
|
|
||||||
if (startup_error)
|
if (startup_error)
|
||||||
client->print_status({
|
client->print_status({
|
||||||
|
@ -329,26 +352,6 @@ int run_client(StringView session, StringView init_command)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DummyUI : UserInterface
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void menu_show(ConstArrayView<String>, CharCoord, Face, Face, MenuStyle) override {}
|
|
||||||
void menu_select(int) override {}
|
|
||||||
void menu_hide() override {}
|
|
||||||
|
|
||||||
void info_show(StringView, StringView, CharCoord, Face, InfoStyle) override {}
|
|
||||||
void info_hide() override {}
|
|
||||||
|
|
||||||
void draw(const DisplayBuffer&, const Face&) override {}
|
|
||||||
void draw_status(const DisplayLine&, const DisplayLine&, const Face&) override {}
|
|
||||||
CharCoord dimensions() override { return {24,80}; }
|
|
||||||
bool is_key_available() override { return false; }
|
|
||||||
Key get_key() override { return Key::Invalid; }
|
|
||||||
void refresh() override {}
|
|
||||||
void set_input_callback(InputCallback) override {}
|
|
||||||
void set_ui_options(const Options&) override {}
|
|
||||||
};
|
|
||||||
|
|
||||||
int run_server(StringView session, StringView init_command,
|
int run_server(StringView session, StringView init_command,
|
||||||
bool ignore_kakrc, bool daemon, bool dummy_ui,
|
bool ignore_kakrc, bool daemon, bool dummy_ui,
|
||||||
ConstArrayView<StringView> files)
|
ConstArrayView<StringView> files)
|
||||||
|
@ -445,12 +448,7 @@ int run_server(StringView session, StringView init_command,
|
||||||
new Buffer("*scratch*", Buffer::Flags::None);
|
new Buffer("*scratch*", Buffer::Flags::None);
|
||||||
|
|
||||||
if (not daemon)
|
if (not daemon)
|
||||||
{
|
create_local_client(create_local_ui(dummy_ui), init_command, startup_error);
|
||||||
if (dummy_ui)
|
|
||||||
create_local_client<DummyUI>(init_command, startup_error);
|
|
||||||
else
|
|
||||||
create_local_client<NCursesUI>(init_command, startup_error);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (not terminate and (not client_manager.empty() or daemon))
|
while (not terminate and (not client_manager.empty() or daemon))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user