This repository has been archived by the owner on Jul 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandLine.h
106 lines (81 loc) · 1.7 KB
/
CommandLine.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef COMMANDLINE_H
#define COMMANDLINE_H
#include <SGL/Graphics/BitmapFont.h>
#include <SGL/Graphics/Text.h>
#include <string>
#include <map>
#include <functional>
namespace engine
{
namespace gui
{
/**
Provides direct user interface to the engine
*/
class CommandLine
{
public:
typedef std::function<bool(std::vector<std::string>&)> CommandFunc;
typedef std::vector<std::string> StringList;
CommandLine();
~CommandLine();
void init();
/**
Add a command function to the command line
*/
void addCommand(const std::string& name, const CommandFunc& func);
/**
Process an incoming key even
*/
void process(int keycode);
/**
Append text to the command lien display
This does not alter the buffer, only the render text
*/
void append(const char *str);
/**
Clear the command line buffer
*/
void clear();
/**
@return thr render text object
*/
sgl::Text& getText();
/**
enable the command line
*/
void setActive(bool a);
/**
Check if the command line is active
*/
bool isActive();
private:
// render text for command line
sgl::Text _text;
// user input string
std::string _buffer;
// command map
std::map<std::string, CommandFunc> _commands;
// command enable flag
bool _isActive;
private:
/**
Execute the input command with arguments
*/
void dispatch();
/**
push a character to the buffer
*/
void push(const char *str);
/**
remove the last character
*/
void removeBack();
/**
tokenize an input string with a delimiter
*/
void tokenize(StringList& v, std::string &s, const std::string &delimiter);
};
}
}
#endif