57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
#include "cli.hpp"
|
|
#include "commands.hpp"
|
|
#include "config.hpp"
|
|
|
|
#include <iostream>
|
|
#include <cstdlib>
|
|
#include <string>
|
|
|
|
#include "libs/linenoise.h"
|
|
|
|
static void completionCallback(const char *input, linenoiseCompletions *completions) {
|
|
if (strncmp(input, "ni", 2) == 0) {
|
|
linenoiseAddCompletion(completions, "nick set ");
|
|
linenoiseAddCompletion(completions, "nick generatekey");
|
|
}
|
|
else if (strncmp(input, "web", 3) == 0) {
|
|
linenoiseAddCompletion(completions, "web start");
|
|
linenoiseAddCompletion(completions, "web connect pm 127.0.0.1");
|
|
linenoiseAddCompletion(completions, "web stop");
|
|
}
|
|
else if (strncmp(input, "sound", 5) == 0) {
|
|
linenoiseAddCompletion(completions, "sound find");
|
|
linenoiseAddCompletion(completions, "sound lose");
|
|
}
|
|
}
|
|
|
|
void runCLI(AppConfig &config) {
|
|
linenoiseHistoryLoad("history.txt");
|
|
|
|
linenoiseSetCompletionCallback(completionCallback);
|
|
|
|
std::cout << CLR_CYAN "Cerberus BFSK Demo (linenoise + color)\n"
|
|
<< "Доступные команды:\n"
|
|
<< " nick set <usernick>\n"
|
|
<< " nick generatekey\n"
|
|
<< " web start / web connect pm|server <ip> / web stop\n"
|
|
<< " sound find / sound lose\n"
|
|
<< " exit\n\n" CLR_RESET;
|
|
|
|
while (true) {
|
|
char *line = linenoise(CLR_BOLD ">_ " CLR_RESET);
|
|
if (!line) {
|
|
std::cout << "\n[cli] EOF/Ctrl+C - выходим.\n";
|
|
break;
|
|
}
|
|
std::string input(line);
|
|
free(line);
|
|
|
|
if (!input.empty()) {
|
|
linenoiseHistoryAdd(input.c_str());
|
|
linenoiseHistorySave("history.txt");
|
|
|
|
processCommand(input, config);
|
|
}
|
|
}
|
|
}
|