Use a dummy UI when running tests, so that we do not need a tty
This commit is contained in:
parent
4188335b51
commit
7eaa6976b9
43
src/main.cc
43
src/main.cc
|
@ -227,15 +227,16 @@ void register_options()
|
||||||
UserInterface::Options());
|
UserInterface::Options());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename UI>
|
||||||
void create_local_client(StringView init_command)
|
void create_local_client(StringView init_command)
|
||||||
{
|
{
|
||||||
class LocalNCursesUI : public NCursesUI
|
struct LocalUI : UI
|
||||||
{
|
{
|
||||||
~LocalNCursesUI()
|
~LocalUI()
|
||||||
{
|
{
|
||||||
if (not ClientManager::instance().empty() and fork())
|
if (not ClientManager::instance().empty() and fork())
|
||||||
{
|
{
|
||||||
this->NCursesUI::~NCursesUI();
|
this->UI::~UI();
|
||||||
puts("detached from terminal\n");
|
puts("detached from terminal\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
@ -255,9 +256,8 @@ void create_local_client(StringView init_command)
|
||||||
create_fifo_buffer("*stdin*", fd);
|
create_fifo_buffer("*stdin*", fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
UserInterface* ui = new LocalNCursesUI{};
|
|
||||||
static Client* client = ClientManager::instance().create_client(
|
static Client* client = ClientManager::instance().create_client(
|
||||||
std::unique_ptr<UserInterface>{ui}, get_env_vars(), init_command);
|
make_unique<LocalUI>(), get_env_vars(), init_command);
|
||||||
signal(SIGHUP, [](int) {
|
signal(SIGHUP, [](int) {
|
||||||
if (client)
|
if (client)
|
||||||
ClientManager::instance().remove_client(*client);
|
ClientManager::instance().remove_client(*client);
|
||||||
|
@ -313,8 +313,28 @@ 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 DisplayLine&, const DisplayLine&) 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, ConstArrayView<StringView> files)
|
bool ignore_kakrc, bool daemon, bool dummy_ui,
|
||||||
|
ConstArrayView<StringView> files)
|
||||||
{
|
{
|
||||||
static bool terminate = false;
|
static bool terminate = false;
|
||||||
if (daemon)
|
if (daemon)
|
||||||
|
@ -396,7 +416,12 @@ 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(init_command);
|
{
|
||||||
|
if (dummy_ui)
|
||||||
|
create_local_client<DummyUI>(init_command);
|
||||||
|
else
|
||||||
|
create_local_client<NCursesUI>(init_command);
|
||||||
|
}
|
||||||
|
|
||||||
while (not terminate and (not client_manager.empty() or daemon))
|
while (not terminate and (not client_manager.empty() or daemon))
|
||||||
{
|
{
|
||||||
|
@ -524,7 +549,8 @@ int main(int argc, char* argv[])
|
||||||
{ "d", { false, "run as a headless session (requires -s)" } },
|
{ "d", { false, "run as a headless session (requires -s)" } },
|
||||||
{ "p", { true, "just send stdin as commands to the given session" } },
|
{ "p", { true, "just send stdin as commands to the given session" } },
|
||||||
{ "f", { true, "act as a filter, executing given keys on given files" } },
|
{ "f", { true, "act as a filter, executing given keys on given files" } },
|
||||||
{ "q", { false, "in filter mode, be quiet about errors applying keys" } } }
|
{ "q", { false, "in filter mode, be quiet about errors applying keys" } },
|
||||||
|
{ "u", { false, "use a dummy user interface, for testing purposes" } } }
|
||||||
};
|
};
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -579,6 +605,7 @@ int main(int argc, char* argv[])
|
||||||
return run_server(session, init_command,
|
return run_server(session, init_command,
|
||||||
(bool)parser.get_switch("n"),
|
(bool)parser.get_switch("n"),
|
||||||
(bool)parser.get_switch("d"),
|
(bool)parser.get_switch("d"),
|
||||||
|
(bool)parser.get_switch("u"),
|
||||||
files);
|
files);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
test/run
2
test/run
|
@ -41,7 +41,7 @@ main() {
|
||||||
write out
|
write out
|
||||||
quit!
|
quit!
|
||||||
"
|
"
|
||||||
${test}/../src/kak out -n -e "$kak_commands"
|
${test}/../src/kak out -n -u -e "$kak_commands"
|
||||||
for expect in $test_files; do
|
for expect in $test_files; do
|
||||||
if cmp -s $test/$dir/$expect $expect; then
|
if cmp -s $test/$dir/$expect $expect; then
|
||||||
echo "$indent$name" | colorize green normal
|
echo "$indent$name" | colorize green normal
|
||||||
|
|
Loading…
Reference in New Issue
Block a user