2013-09-12 23:47:23 +02:00
|
|
|
#ifndef client_hh_INCLUDED
|
|
|
|
#define client_hh_INCLUDED
|
2012-06-06 01:15:19 +02:00
|
|
|
|
2013-09-16 20:15:13 +02:00
|
|
|
#include "display_buffer.hh"
|
2014-04-07 22:25:44 +02:00
|
|
|
#include "env_vars.hh"
|
2014-08-12 01:30:13 +02:00
|
|
|
#include "input_handler.hh"
|
|
|
|
#include "safe_ptr.hh"
|
|
|
|
#include "utils.hh"
|
2014-11-11 00:29:16 +01:00
|
|
|
#include "option_manager.hh"
|
2015-11-20 09:50:53 +01:00
|
|
|
#include "enum.hh"
|
2012-06-06 01:15:19 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2013-12-20 21:10:08 +01:00
|
|
|
class Window;
|
2016-11-29 20:53:11 +01:00
|
|
|
class UserInterface;
|
2014-11-12 22:27:07 +01:00
|
|
|
class String;
|
2014-11-25 02:00:18 +01:00
|
|
|
struct Key;
|
|
|
|
|
|
|
|
enum class EventMode;
|
2016-11-29 20:53:11 +01:00
|
|
|
enum class InfoStyle;
|
|
|
|
enum class MenuStyle;
|
|
|
|
|
2014-11-11 00:29:16 +01:00
|
|
|
class Client : public SafeCountable, public OptionManagerWatcher
|
2013-11-14 19:09:15 +01:00
|
|
|
{
|
|
|
|
public:
|
2017-08-23 08:22:23 +02:00
|
|
|
using OnExitCallback = std::function<void (int status)>;
|
|
|
|
|
2013-12-20 21:10:08 +01:00
|
|
|
Client(std::unique_ptr<UserInterface>&& ui,
|
|
|
|
std::unique_ptr<Window>&& window,
|
2014-04-07 22:25:44 +02:00
|
|
|
SelectionList selections,
|
2017-08-28 08:12:15 +02:00
|
|
|
int pid, EnvVarMap env_vars,
|
2017-08-23 08:22:23 +02:00
|
|
|
String name,
|
|
|
|
OnExitCallback on_exit);
|
2017-05-22 11:31:56 +02:00
|
|
|
~Client();
|
2013-11-14 19:09:15 +01:00
|
|
|
|
2014-11-11 00:29:16 +01:00
|
|
|
Client(Client&&) = delete;
|
|
|
|
|
2016-11-30 10:47:38 +01:00
|
|
|
bool process_pending_inputs();
|
2013-11-14 19:09:15 +01:00
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
void menu_show(Vector<DisplayLine> choices, BufferCoord anchor, MenuStyle style);
|
2016-02-27 18:23:13 +01:00
|
|
|
void menu_select(int selected);
|
|
|
|
void menu_hide();
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
void info_show(String title, String content, BufferCoord anchor, InfoStyle style);
|
2017-01-04 12:24:07 +01:00
|
|
|
void info_hide(bool even_modal = false);
|
2016-02-27 18:23:13 +01:00
|
|
|
|
2016-10-29 12:25:58 +02:00
|
|
|
void print_status(DisplayLine status_line, bool immediate = false);
|
2013-09-16 20:15:13 +02:00
|
|
|
|
2016-11-29 20:53:11 +01:00
|
|
|
DisplayCoord dimensions() const;
|
2016-02-27 18:23:13 +01:00
|
|
|
|
2015-08-23 14:29:24 +02:00
|
|
|
void force_redraw();
|
2016-03-08 00:11:59 +01:00
|
|
|
void redraw_ifn();
|
2013-09-16 20:15:13 +02:00
|
|
|
|
2015-02-12 15:55:02 +01:00
|
|
|
void check_if_buffer_needs_reloading();
|
2013-10-15 19:51:31 +02:00
|
|
|
|
2013-11-14 19:09:15 +01:00
|
|
|
Context& context() { return m_input_handler.context(); }
|
|
|
|
const Context& context() const { return m_input_handler.context(); }
|
|
|
|
|
2014-08-12 20:24:09 +02:00
|
|
|
InputHandler& input_handler() { return m_input_handler; }
|
|
|
|
const InputHandler& input_handler() const { return m_input_handler; }
|
|
|
|
|
2013-12-20 21:10:08 +01:00
|
|
|
void change_buffer(Buffer& buffer);
|
2013-10-10 22:34:19 +02:00
|
|
|
|
2015-03-10 20:33:46 +01:00
|
|
|
StringView get_env_var(StringView name) const;
|
2014-04-07 22:25:44 +02:00
|
|
|
|
2015-11-07 19:24:08 +01:00
|
|
|
Buffer* last_buffer() const { return m_last_buffer.get(); }
|
|
|
|
void set_last_buffer(Buffer* last_buffer) { m_last_buffer = last_buffer; }
|
|
|
|
|
2017-08-23 08:22:23 +02:00
|
|
|
void exit(int status) { m_on_exit(status); }
|
|
|
|
|
2017-08-28 08:12:15 +02:00
|
|
|
int pid() const { return m_pid; }
|
|
|
|
|
2013-12-20 21:10:08 +01:00
|
|
|
private:
|
2014-11-11 00:29:16 +01:00
|
|
|
void on_option_changed(const Option& option) override;
|
|
|
|
|
2015-02-12 15:55:02 +01:00
|
|
|
void on_buffer_reload_key(Key key);
|
|
|
|
void close_buffer_reload_dialog();
|
|
|
|
void reload_buffer();
|
|
|
|
|
2014-11-29 21:14:52 +01:00
|
|
|
Optional<Key> get_next_key(EventMode mode);
|
|
|
|
|
2013-10-10 22:34:19 +02:00
|
|
|
DisplayLine generate_mode_line() const;
|
|
|
|
|
2013-09-12 23:39:34 +02:00
|
|
|
std::unique_ptr<UserInterface> m_ui;
|
2013-12-20 21:10:08 +01:00
|
|
|
std::unique_ptr<Window> m_window;
|
|
|
|
|
2017-08-28 08:12:15 +02:00
|
|
|
const int m_pid;
|
|
|
|
|
2017-08-23 08:22:23 +02:00
|
|
|
OnExitCallback m_on_exit;
|
|
|
|
|
2014-04-07 22:25:44 +02:00
|
|
|
EnvVarMap m_env_vars;
|
|
|
|
|
2013-12-20 21:10:08 +01:00
|
|
|
InputHandler m_input_handler;
|
2013-02-18 14:07:30 +01:00
|
|
|
|
2013-09-16 20:15:13 +02:00
|
|
|
DisplayLine m_status_line;
|
2014-07-07 21:13:08 +02:00
|
|
|
DisplayLine m_mode_line;
|
2014-11-25 02:00:18 +01:00
|
|
|
|
2016-03-08 00:11:59 +01:00
|
|
|
enum PendingUI : int
|
|
|
|
{
|
|
|
|
MenuShow = 1 << 0,
|
|
|
|
MenuSelect = 1 << 1,
|
|
|
|
MenuHide = 1 << 2,
|
|
|
|
InfoShow = 1 << 3,
|
|
|
|
InfoHide = 1 << 4,
|
|
|
|
StatusLine = 1 << 5,
|
|
|
|
Draw = 1 << 6,
|
|
|
|
Refresh = 1 << 7,
|
|
|
|
};
|
|
|
|
int m_ui_pending = 0;
|
|
|
|
|
2016-02-27 18:23:13 +01:00
|
|
|
struct Menu
|
|
|
|
{
|
|
|
|
Vector<DisplayLine> items;
|
2016-09-22 21:36:26 +02:00
|
|
|
BufferCoord anchor;
|
2017-06-16 11:19:08 +02:00
|
|
|
Optional<DisplayCoord> ui_anchor;
|
2016-02-27 18:23:13 +01:00
|
|
|
MenuStyle style;
|
|
|
|
int selected;
|
2017-01-30 00:37:42 +01:00
|
|
|
} m_menu{};
|
2016-02-27 18:23:13 +01:00
|
|
|
|
|
|
|
struct Info
|
|
|
|
{
|
|
|
|
String title;
|
|
|
|
String content;
|
2016-09-22 21:36:26 +02:00
|
|
|
BufferCoord anchor;
|
2017-06-16 11:19:08 +02:00
|
|
|
Optional<DisplayCoord> ui_anchor;
|
2016-02-27 18:23:13 +01:00
|
|
|
InfoStyle style;
|
2017-01-30 00:37:42 +01:00
|
|
|
} m_info{};
|
2016-02-27 18:23:13 +01:00
|
|
|
|
2015-01-14 20:16:32 +01:00
|
|
|
Vector<Key, MemoryDomain::Client> m_pending_keys;
|
2015-02-12 15:55:02 +01:00
|
|
|
|
|
|
|
bool m_buffer_reload_dialog_opened = false;
|
2015-11-07 19:24:08 +01:00
|
|
|
|
|
|
|
SafePtr<Buffer> m_last_buffer;
|
2012-06-06 01:15:19 +02:00
|
|
|
};
|
|
|
|
|
2015-11-20 09:50:53 +01:00
|
|
|
enum class Autoreload
|
|
|
|
{
|
|
|
|
Yes,
|
|
|
|
No,
|
|
|
|
Ask
|
|
|
|
};
|
|
|
|
|
2017-08-12 17:11:58 +02:00
|
|
|
constexpr auto enum_desc(Meta::Type<Autoreload>)
|
2015-11-20 09:50:53 +01:00
|
|
|
{
|
2017-08-18 03:15:18 +02:00
|
|
|
return make_array<EnumDesc<Autoreload>, 5>({
|
2015-11-20 09:50:53 +01:00
|
|
|
{ Autoreload::Yes, "yes" },
|
|
|
|
{ Autoreload::No, "no" },
|
|
|
|
{ Autoreload::Ask, "ask" },
|
|
|
|
{ Autoreload::Yes, "true" },
|
|
|
|
{ Autoreload::No, "false" }
|
2017-08-12 17:11:58 +02:00
|
|
|
});
|
2015-11-20 09:50:53 +01:00
|
|
|
}
|
|
|
|
|
2012-06-06 01:15:19 +02:00
|
|
|
}
|
|
|
|
|
2013-09-12 23:47:23 +02:00
|
|
|
#endif // client_hh_INCLUDED
|