-
Notifications
You must be signed in to change notification settings - Fork 0
/
vty_keyfunction.h
78 lines (72 loc) · 2.21 KB
/
vty_keyfunction.h
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
#pragma once
#include <string.h>
#include <stdint.h>
#include <stddef.h>
#include <slankdev/exception.h>
#include <vty_client.h>
class key_func {
public:
uint8_t code[256];
const size_t len;
key_func(const void* d, size_t l) : len(l)
{
if (sizeof(code) < l) throw slankdev::exception("length is too big");
memcpy(code, d, l);
}
virtual ~key_func() {}
virtual void function(vty_client*) = 0;
virtual bool match(const void* d, size_t l)
{
return (len == l) && (memcmp(code, d, l) == 0);
}
};
struct KF_return : public key_func {
KF_return(const void* c, size_t l) : key_func(c, l) {}
void function(vty_client* sh) { sh->exec_command(); }
};
struct KF_backspace : public key_func {
KF_backspace(const void* c, size_t l) : key_func(c, l) {}
void function(vty_client* sh) { sh->ibuf.cursor_backspace(); }
};
struct KF_right : public key_func {
KF_right(const void* c, size_t l) : key_func(c, l) {}
void function(vty_client* sh) { sh->ibuf.cursor_right(); }
};
struct KF_left : public key_func {
KF_left(const void* c, size_t l) : key_func(c, l) {}
void function(vty_client* sh) { sh->ibuf.cursor_left(); }
};
struct KF_hist_search_deep : public key_func {
KF_hist_search_deep(const void* c, size_t l) : key_func(c, l) {}
void function(vty_client* sh)
{
sh->ibuf.clear();
sh->ibuf.input_str(sh->history.deep_get());
sh->refresh_prompt();
}
};
struct KF_hist_search_shallow : public key_func {
KF_hist_search_shallow(const void* c, size_t l) : key_func(c, l) {}
void function(vty_client* sh)
{
sh->ibuf.clear();
sh->ibuf.input_str(sh->history.shallow_get());
sh->refresh_prompt();
}
};
struct KF_cursor_top : public key_func {
KF_cursor_top(const void* c, size_t l) : key_func(c, l) {}
void function(vty_client* sh) { sh->ibuf.cursor_top(); }
};
struct KF_cursor_end : public key_func {
KF_cursor_end(const void* c, size_t l) : key_func(c, l) {}
void function(vty_client* sh) { sh->ibuf.cursor_end(); }
};
struct KF_completion : public key_func {
KF_completion(const void* c, size_t l) : key_func(c, l) {}
void function(vty_client* sh);
};
struct KF_help : public key_func {
KF_help(const void* c, size_t l) : key_func(c, l) {}
void function(vty_client* sh);
};