-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmdconsole.h
80 lines (63 loc) · 2.17 KB
/
cmdconsole.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
/****************************************************************************
* Copyright (c) 2012, voidnull@github
* License : BSD Clause 2 : http://bit.ly/bsd-clause-2
****************************************************************************/
#ifndef __CPP__CMDCONSOLE__H__
#define __CPP__CMDCONSOLE__H__
#include <string>
#include <map>
#include <vector>
#include "linenoise.h"
class CmdConsole {
public:
struct Completions {
linenoiseCompletions *lc;
void add(const std::string& completion) {
linenoiseAddCompletion(lc,completion.c_str());
}
};
struct CompletionCB {
static CmdConsole* console;
static void completion(const char *buf, linenoiseCompletions *lc) {
Completions completions;
completions.lc = lc;
console->complete(std::string(buf),completions);
}
};
typedef void (CmdConsole::*CmdCallBack)(std::vector<std::string>&) ;
CmdConsole();
void setPrompt(const std::string& prompt);
void setHistoryFile(const std::string& filename);
void setHistoryLength(size_t length);
void clearScreen();
virtual void complete(const std::string& line, Completions& completions);
virtual void cmdUnknown(const std::string& line);
virtual void cmdHelp(std::vector<std::string>& args);
bool splitArgs(const std::string& line, std::vector<std::string>& args);
void registerCommand(const std::string& cmd, CmdCallBack cb);
void run();
protected:
std::string prompt;
std::string historyFile;
std::map <std::string, CmdCallBack> mapCallBacks;
};
struct Color {
static std::string End;
static std::string Black;
static std::string Red;
static std::string Green;
static std::string Yellow;
static std::string Blue;
static std::string Magenta;
static std::string Cyan;
static std::string White;
static std::string BoldBlack;
static std::string BoldRed;
static std::string BoldGreen;
static std::string BoldYellow;
static std::string BoldBlue;
static std::string BoldMagenta;
static std::string BoldCyan;
static std::string BoldWhite;
};
#endif // __CPP__CMDCONSOLE__H__