BEEP-8 Helper Lib 1.0.0
Loading...
Searching...
No Matches
shell.h File Reference

This module provides a simple command line interface (CLI) for running specific commands within a program. More...

#include <memory>
#include <stdio.h>
#include <cobj.h>
#include <cstr.h>
#include <vector>
#include <string>

Go to the source code of this file.

Classes

class  CShellCmd
 
class  CShellObj
 

Detailed Description

This module provides a simple command line interface (CLI) for running specific commands within a program.

The shell module allows users to execute commands in a CLI environment, useful for debugging and tool development. Users can register new commands, execute them, display help for commands, maintain a history of commands, and run shell scripts.

This module is designed for use in tool and debug environments. It is not intended for use in actual games, as there is no serial console in such scenarios. The primary purpose of this module is for debugging, and its usage is optional.

Example usage:

#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include "shell.h"
// Custom command class
class CMyShellCmd : public CShellCmd {
public:
CMyShellCmd() : CShellCmd("mycmd") {}
int vOnMain(const std::vector<str16>& tokens) override {
if (ShowHelp(tokens, "Usage: mycmd [options]\n")) {
return 0;
}
// Command execution logic here
std::cout << "My Command Executed with tokens: ";
for (const auto& token : tokens) {
std::cout << token.c_str() << " ";
}
std::cout << std::endl;
return 0;
}
};
int main() {
CShellObj shell;
// Register custom command
shell.Register(new CMyShellCmd());
// Execute shell script
auto script = std::make_shared<std::string>("mycmd arg1 arg2\nhelp\nclear\n");
shell.ExecShellScript(script);
// Simulate command input
std::vector<u32> inputs = {'m', 'y', 'c', 'm', 'd', ' ', 'a', 'r', 'g', '1', ' ', 'a', 'r', 'g', '2', B8_HIF_KB_CODE_ENTER};
for (u32 input : inputs) {
shell.Input(input);
}
return 0;
}
Definition shell.h:66
bool ShowHelp(const std::vector< str16 > &tokens, const char *help)
Displays help information for the command.
Definition shell.cpp:242
Definition shell.h:103
void ExecShellScript(std::shared_ptr< std::string > script_)
Executes a shell script.
Definition shell.cpp:89
void Input(u32 keycode_)
Processes an input keycode.
Definition shell.cpp:104
void Register(CShellCmd *cmd_)
Registers a new command with the shell.
Definition shell.cpp:226
This module provides a simple command line interface (CLI) for running specific commands within a pro...