verious refactoring
This commit is contained in:
parent
f8abbfbb44
commit
1ab486b0d8
|
@ -678,9 +678,7 @@ void exec_keys(const KeyList& keys, Context& context)
|
||||||
|
|
||||||
scoped_edition edition(context.editor());
|
scoped_edition edition(context.editor());
|
||||||
|
|
||||||
Context new_context(batch_client);
|
Context new_context(batch_client, context.editor(), batch_ui);
|
||||||
new_context.change_editor(context.editor());
|
|
||||||
new_context.change_ui(batch_ui);
|
|
||||||
while (batch_ui.has_key_left())
|
while (batch_ui.has_key_left())
|
||||||
batch_client.handle_next_input(new_context);
|
batch_client.handle_next_input(new_context);
|
||||||
context.change_editor(new_context.editor());
|
context.change_editor(new_context.editor());
|
||||||
|
|
|
@ -20,8 +20,8 @@ struct Context
|
||||||
explicit Context(Editor& editor)
|
explicit Context(Editor& editor)
|
||||||
: m_editor(&editor) {}
|
: m_editor(&editor) {}
|
||||||
|
|
||||||
explicit Context(Client& client)
|
Context(Client& client, Editor& editor, UserInterface& ui)
|
||||||
: m_client(&client) {}
|
: m_client(&client), m_editor(&editor), m_ui(&ui) {}
|
||||||
|
|
||||||
// to allow func(Context(Editor(...)))
|
// to allow func(Context(Editor(...)))
|
||||||
// make sure the context will not survive the next ';'
|
// make sure the context will not survive the next ';'
|
||||||
|
@ -29,6 +29,7 @@ struct Context
|
||||||
: m_editor(&editor) {}
|
: m_editor(&editor) {}
|
||||||
|
|
||||||
Context(const Context&) = delete;
|
Context(const Context&) = delete;
|
||||||
|
Context(Context&&) = default;
|
||||||
Context& operator=(const Context&) = delete;
|
Context& operator=(const Context&) = delete;
|
||||||
|
|
||||||
Buffer& buffer() const
|
Buffer& buffer() const
|
||||||
|
|
38
src/main.cc
38
src/main.cc
|
@ -18,6 +18,7 @@
|
||||||
#include "context.hh"
|
#include "context.hh"
|
||||||
#include "ncurses.hh"
|
#include "ncurses.hh"
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
|
#include "file.hh"
|
||||||
#include "color_registry.hh"
|
#include "color_registry.hh"
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
|
@ -502,9 +503,6 @@ int main(int argc, char* argv[])
|
||||||
Client client;
|
Client client;
|
||||||
NCursesUI ui;
|
NCursesUI ui;
|
||||||
|
|
||||||
Context context(client);
|
|
||||||
context.change_ui(ui);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Context initialisation_context;
|
Context initialisation_context;
|
||||||
|
@ -513,40 +511,40 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
catch (Kakoune::runtime_error& error)
|
catch (Kakoune::runtime_error& error)
|
||||||
{
|
{
|
||||||
context.print_status(error.description());
|
ui.print_status(error.description(), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
write_debug("*** This is the debug buffer, where debug info will be written ***\n");
|
write_debug("*** This is the debug buffer, where debug info will be written ***\n");
|
||||||
write_debug("utf-8 test: é á ï");
|
write_debug("utf-8 test: é á ï");
|
||||||
|
|
||||||
|
Buffer* buffer = nullptr;
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
{
|
{
|
||||||
String cmd = "edit ";
|
buffer = create_buffer_from_file(argv[1]);
|
||||||
for (int i = 1; i < argc; ++i)
|
if (not buffer)
|
||||||
cmd += String(" ") + argv[i];
|
{
|
||||||
command_manager.execute(cmd, context);
|
ui.print_status("new file "_str + argv[1], -1);
|
||||||
|
buffer = new Buffer(argv[1], Buffer::Type::NewFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
buffer = new Buffer("*scratch*", Buffer::Type::Scratch);
|
||||||
auto buffer = new Buffer("*scratch*", Buffer::Type::Scratch);
|
|
||||||
context.change_editor(*buffer->get_or_create_window());
|
|
||||||
}
|
|
||||||
|
|
||||||
event_manager.watch(0, [&](int) { client.handle_next_input(context); });
|
Context context(client, *buffer->get_or_create_window(), ui);
|
||||||
|
event_manager.watch(0, [&](int) {
|
||||||
context.draw_ifn();
|
|
||||||
while(not quit_requested)
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
event_manager.handle_next_events();
|
client.handle_next_input(context);
|
||||||
}
|
}
|
||||||
catch (Kakoune::runtime_error& error)
|
catch (Kakoune::runtime_error& error)
|
||||||
{
|
{
|
||||||
context.print_status(error.description());
|
context.print_status(error.description());
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
context.draw_ifn();
|
||||||
|
while(not quit_requested)
|
||||||
|
event_manager.handle_next_events();
|
||||||
}
|
}
|
||||||
catch (Kakoune::exception& error)
|
catch (Kakoune::exception& error)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user