59 lines
2.6 KiB
C++
59 lines
2.6 KiB
C++
#include "cli.hpp"
|
|
#include "commands.hpp"
|
|
#include "config.hpp"
|
|
#include <iostream>
|
|
#include <cstdlib>
|
|
#include <string>
|
|
#include <cstring>
|
|
#include "libs/linenoise.h"
|
|
|
|
static const char* asciiArt =
|
|
" (`-') _ (`-') <-.(`-') (`-') _ (`-') (`-').->\n"
|
|
" _ ( OO).-/<-.(OO ) __( OO) ( OO).-/<-.(OO ) .-> ( OO)_ \n"
|
|
" \\-,-----.(,------.,------,)'-'---.\\ (,------.,------,),--.(,--. (_)--\\_) \n"
|
|
" | .--./ | .---'| /`. '| .-. (/ | .---'| /`. '| | |(`-')/ _ / \n"
|
|
" /_) (`-')(| '--. | |_.' || '-' `.)(| '--. | |_.' || | |(OO )\\_..`--. \n"
|
|
" || |OO ) | .--' | . .'| /`'. | | .--' | . .'| | | | \\.-._) \\\n"
|
|
"(_' '--'\\ | `---.| |\\ \\ | '--' / | `---.| |\\ \\ \\ '-'(_ .'\\ /\n"
|
|
" `-----' `------'`--' '--'`------' `------'`--' '--' `-----' `-----'\n";
|
|
|
|
static void completionCallback(const char *input, linenoiseCompletions *lc) {
|
|
if(strncmp(input,"nick ",5)==0) linenoiseAddCompletion(lc,"nick set ");
|
|
else if(strncmp(input,"nick g",6)==0) linenoiseAddCompletion(lc,"nick generatekey");
|
|
else if(strncmp(input,"web s",5)==0) linenoiseAddCompletion(lc,"web start");
|
|
else if(strncmp(input,"web c",5)==0) linenoiseAddCompletion(lc,"web connect pm 127.0.0.1");
|
|
else if(strncmp(input,"web s",5)==0) linenoiseAddCompletion(lc,"web stop");
|
|
else if(strncmp(input,"sound f",7)==0) linenoiseAddCompletion(lc,"sound find");
|
|
else if(strncmp(input,"sound l",7)==0) linenoiseAddCompletion(lc,"sound lose");
|
|
else if(strncmp(input,"cerber ma",9)==0) linenoiseAddCompletion(lc,"cerber maketea <text> [key]");
|
|
else if(strncmp(input,"cerber dr",9)==0) linenoiseAddCompletion(lc,"cerber drinktea <hex> [key]");
|
|
else if(strncmp(input,"exit",4)==0) linenoiseAddCompletion(lc,"exit");
|
|
}
|
|
|
|
void runCLI(AppConfig &config) {
|
|
linenoiseHistoryLoad("history.txt");
|
|
linenoiseSetCompletionCallback(completionCallback);
|
|
|
|
std::cout << asciiArt << "\n"
|
|
<< CLR_CYAN << "Cerberus BFSK:\n"
|
|
<< " nick set <usernick>\n"
|
|
<< " nick generatekey\n"
|
|
<< " web start/connect/stop\n"
|
|
<< " sound find/lose\n"
|
|
<< " cerber maketea <text> [hexKey]\n"
|
|
<< " cerber drinktea <hex> [hexKey]\n"
|
|
<< " exit\n"
|
|
<< CLR_RESET;
|
|
|
|
while(true){
|
|
char* line = linenoise(">_ ");
|
|
if(!line) break;
|
|
std::string input(line);
|
|
free(line);
|
|
if(!input.empty()){
|
|
linenoiseHistoryAdd(input.c_str());
|
|
linenoiseHistorySave("history.txt");
|
|
processCommand(input, config);
|
|
}
|
|
}
|
|
} |