summaryrefslogtreecommitdiff
path: root/src/user_interface.hh
blob: 643f0d1d05ca027cf454cb19688ad807fef23981 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef user_interface_hh_INCLUDED
#define user_interface_hh_INCLUDED

#include "array_view.hh"
#include "hash_map.hh"

#include <functional>

namespace Kakoune
{

class String;
class DisplayBuffer;
class DisplayLine;
using DisplayLineList = Vector<DisplayLine, MemoryDomain::Display>;
struct DisplayCoord;
struct Face;
struct Key;

enum class MenuStyle
{
    Prompt,
    Search,
    Inline
};

enum class InfoStyle
{
    Prompt,
    Inline,
    InlineAbove,
    InlineBelow,
    MenuDoc,
    Modal
};

enum class EventMode;

enum class CursorMode
{
    Prompt,
    Buffer,
};

using OnKeyCallback = std::function<void(Key key)>;
using OnPasteCallback = std::function<void(StringView content)>;

class UserInterface
{
public:
    virtual ~UserInterface() = default;

    virtual bool is_ok() const = 0;

    virtual void menu_show(ConstArrayView<DisplayLine> choices,
                           DisplayCoord anchor, Face fg, Face bg,
                           MenuStyle style) = 0;
    virtual void menu_select(int selected) = 0;
    virtual void menu_hide() = 0;

    virtual void info_show(const DisplayLine& title,
                           const DisplayLineList& content,
                           DisplayCoord anchor, Face face,
                           InfoStyle style) = 0;
    virtual void info_hide() = 0;

    virtual void draw(const DisplayBuffer& display_buffer,
                      const Face& default_face,
                      const Face& padding_face) = 0;

    virtual void draw_status(const DisplayLine& status_line,
                             const DisplayLine& mode_line,
                             const Face& default_face) = 0;

    virtual DisplayCoord dimensions() = 0;

    virtual void set_cursor(CursorMode mode, DisplayCoord coord) = 0;

    virtual void refresh(bool force) = 0;

    virtual void set_on_key(OnKeyCallback callback) = 0;
    virtual void set_on_paste(OnPasteCallback callback) = 0;

    using Options = HashMap<String, String, MemoryDomain::Options>;
    virtual void set_ui_options(const Options& options) = 0;
};

}

#endif // user_interface_hh_INCLUDED