1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-22 11:01:48 +03:00
kakoune/src/client.hh

158 lines
3.5 KiB
C++
Raw Normal View History

2013-09-13 01:47:23 +04:00
#ifndef client_hh_INCLUDED
#define client_hh_INCLUDED
#include "display_buffer.hh"
#include "env_vars.hh"
#include "input_handler.hh"
#include "safe_ptr.hh"
#include "utils.hh"
#include "option_manager.hh"
#include "enum.hh"
namespace Kakoune
{
class Window;
2016-11-29 22:53:11 +03:00
class UserInterface;
2014-11-13 00:27:07 +03:00
class String;
struct Key;
enum class EventMode;
2016-11-29 22:53:11 +03:00
enum class InfoStyle;
enum class MenuStyle;
class Client : public SafeCountable, public OptionManagerWatcher
2013-11-14 22:09:15 +04:00
{
public:
using OnExitCallback = std::function<void (int status)>;
Client(std::unique_ptr<UserInterface>&& ui,
std::unique_ptr<Window>&& window,
SelectionList selections,
int pid, EnvVarMap env_vars,
String name,
OnExitCallback on_exit);
~Client();
2013-11-14 22:09:15 +04:00
Client(Client&&) = delete;
bool process_pending_inputs();
2013-11-14 22:09:15 +04:00
void menu_show(Vector<DisplayLine> choices, BufferCoord anchor, MenuStyle style);
void menu_select(int selected);
void menu_hide();
void info_show(String title, String content, BufferCoord anchor, InfoStyle style);
void info_hide(bool even_modal = false);
void print_status(DisplayLine status_line, bool immediate = false);
2016-11-29 22:53:11 +03:00
DisplayCoord dimensions() const;
void force_redraw();
void redraw_ifn();
void check_if_buffer_needs_reloading();
2013-11-14 22:09:15 +04:00
Context& context() { return m_input_handler.context(); }
const Context& context() const { return m_input_handler.context(); }
InputHandler& input_handler() { return m_input_handler; }
const InputHandler& input_handler() const { return m_input_handler; }
void change_buffer(Buffer& buffer);
StringView get_env_var(StringView name) const;
Buffer* last_buffer() const { return m_last_buffer.get(); }
void set_last_buffer(Buffer* last_buffer) { m_last_buffer = last_buffer; }
void exit(int status) { m_on_exit(status); }
int pid() const { return m_pid; }
private:
void on_option_changed(const Option& option) override;
void on_buffer_reload_key(Key key);
void close_buffer_reload_dialog();
void reload_buffer();
Optional<Key> get_next_key(EventMode mode);
DisplayLine generate_mode_line() const;
std::unique_ptr<UserInterface> m_ui;
std::unique_ptr<Window> m_window;
const int m_pid;
OnExitCallback m_on_exit;
EnvVarMap m_env_vars;
InputHandler m_input_handler;
DisplayLine m_status_line;
DisplayLine m_mode_line;
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;
struct Menu
{
Vector<DisplayLine> items;
BufferCoord anchor;
Optional<DisplayCoord> ui_anchor;
MenuStyle style;
int selected;
2017-01-30 02:37:42 +03:00
} m_menu{};
struct Info
{
String title;
String content;
BufferCoord anchor;
Optional<DisplayCoord> ui_anchor;
InfoStyle style;
2017-01-30 02:37:42 +03:00
} m_info{};
2015-01-14 22:16:32 +03:00
Vector<Key, MemoryDomain::Client> m_pending_keys;
bool m_buffer_reload_dialog_opened = false;
SafePtr<Buffer> m_last_buffer;
};
enum class Autoreload
{
Yes,
No,
Ask
};
constexpr auto enum_desc(Meta::Type<Autoreload>)
{
return make_array<EnumDesc<Autoreload>, 5>({
{ Autoreload::Yes, "yes" },
{ Autoreload::No, "no" },
{ Autoreload::Ask, "ask" },
{ Autoreload::Yes, "true" },
{ Autoreload::No, "false" }
});
}
}
2013-09-13 01:47:23 +04:00
#endif // client_hh_INCLUDED