Files
CpCtrl/main.cpp

83 lines
2.1 KiB
C++
Raw Normal View History

2025-06-12 15:28:37 +08:00
#include <iostream>
#include "GlobalDefs.h"
#include "ComCtrl.h"
#include "Noncanonical.h"
using namespace std;
// 全局命令存储
std::vector<std::string> historyList{};
Send Sender;
int main() {
// 设置非规范终端模式
set_noncanonical_mode();
if (!Sender.isRunning()) {
return 0;
}
cout << "CP Ctrl Console (v1.0)\nType 'exit' to quit" << endl;
cout << "Type 'help' for available commands" << endl;
while (true) {
string input = readLine("> ");
if (input.empty()) continue;
// 处理输入
vector<string> args;
string token;
for (char c: input) {
if (isspace(c)) {
if (!token.empty()) {
args.push_back(token);
token.clear();
}
}
else {
token += c;
}
}
if (!token.empty()) args.push_back(token);
if (args.empty()) continue;
string command = toLower(args[0]);
if (command == "exit") {
cout << "Exiting..." << endl;
break;
}
else if (command == "setant") {
setantCommand(args);
}
else if (command == "seteph") {
setephCommand(args);
}
else if (command == "query") {
queryCommand(args);
}
else if (command == "list") {
listCommand();
}
else if (command == "help") {
cout << "Available commands:\n"
<< " setant <key> <value> - SetAnt key-value pair\n"
<< " seteph <key> <value> - SetEph key-value pair\n"
<< " query <type> <key> - query type-key value\n"
<< " list - history\n"
<< " exit - Exit program\n"
<< " help - Show this help\n\n"
<< "Tab completion available for commands and keys" << endl;
}
else {
cout << "Invalid command: " << command << endl;
cout << "Type 'help' for available commands" << endl;
}
}
return 0;
}