135 lines
2.7 KiB
C
135 lines
2.7 KiB
C
/**
|
|
* Copyright (c) 2025 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "consolevar.h"
|
|
#include "consolecmd.h"
|
|
#include "consolealias.h"
|
|
|
|
#if CONSOLE_POSIX
|
|
#include "thread/thread.h"
|
|
#include <poll.h>
|
|
#include <unistd.h>
|
|
|
|
#define CONSOLE_POSIX_POLL_RATE 75
|
|
#endif
|
|
|
|
typedef enum {
|
|
CONSOLE_EXEC_STATE_INITIAL,
|
|
CONSOLE_EXEC_STATE_PARSE_CMD,
|
|
CONSOLE_EXEC_STATE_CMD_PARSED,
|
|
|
|
CONSOLE_EXEC_STATE_FIND_ARG,
|
|
CONSOLE_EXEC_STATE_PARSE_ARG,
|
|
CONSOLE_EXEC_STATE_PARSE_ARG_QUOTED,
|
|
CONSOLE_EXEC_STATE_ARG_PARSED,
|
|
|
|
CONSOLE_EXEC_STATE_CMD_FINISHED,
|
|
CONSOLE_EXEC_STATE_FULLY_PARSED
|
|
} consoleexecstate_t;
|
|
|
|
typedef struct {
|
|
consolecmd_t commands[CONSOLE_COMMANDS_MAX];
|
|
uint32_t commandCount;
|
|
|
|
consolevar_t variables[CONSOLE_VARIABLES_MAX];
|
|
uint32_t variableCount;
|
|
|
|
char_t line[CONSOLE_HISTORY_MAX][CONSOLE_LINE_MAX];
|
|
|
|
consolecmdexec_t execBuffer[CONSOLE_EXEC_BUFFER_MAX];
|
|
uint32_t execBufferCount;
|
|
|
|
consolealias_t aliases[CONSOLE_ALIAS_MAX];
|
|
uint32_t aliasCount;
|
|
|
|
consolecmd_t *cmdGet;
|
|
consolecmd_t *cmdSet;
|
|
|
|
bool_t visible;
|
|
|
|
#if CONSOLE_POSIX
|
|
char_t inputBuffer[CONSOLE_LINE_MAX];
|
|
thread_t thread;
|
|
threadmutex_t execMutex;
|
|
#endif
|
|
} console_t;
|
|
|
|
extern console_t CONSOLE;
|
|
|
|
/**
|
|
* Initializes the console.
|
|
*/
|
|
void consoleInit();
|
|
|
|
/**
|
|
* Registers a console command.
|
|
*
|
|
* @param name The name of the command.
|
|
* @param function The function to execute when the command is called.
|
|
* @return The registered command.
|
|
*/
|
|
consolecmd_t * consoleRegCmd(const char_t *name, consolecmdfunc_t function);
|
|
|
|
/**
|
|
* Registers a console variable.
|
|
*
|
|
* @param name The name of the variable.
|
|
* @param value The initial value of the variable.
|
|
* @param event The event to register.
|
|
* @return The registered variable.
|
|
*/
|
|
consolevar_t * consoleRegVar(
|
|
const char_t *name,
|
|
const char_t *value,
|
|
consolevarchanged_t event
|
|
);
|
|
|
|
/**
|
|
* Gets a console variable by name.
|
|
*
|
|
* @param name The name of the variable.
|
|
* @return The variable, or NULL if not found.
|
|
*/
|
|
consolevar_t * consoleVarGet(const char_t *name);
|
|
|
|
/**
|
|
* Prints a message to the console.
|
|
*
|
|
* @param message The message to print.
|
|
*/
|
|
void consolePrint(
|
|
const char_t *message,
|
|
...
|
|
);
|
|
|
|
/**
|
|
* Executes a console command. This method is thread safe and can be called from
|
|
* any thread.
|
|
*
|
|
* @param line The line to execute.
|
|
*/
|
|
void consoleExec(const char_t *line);
|
|
|
|
/**
|
|
* Processes the console's pending commands.
|
|
*/
|
|
void consoleUpdate();
|
|
|
|
/**
|
|
* Disposes of the console.
|
|
*/
|
|
void consoleDispose(void);
|
|
|
|
#if CONSOLE_POSIX
|
|
/**
|
|
* Input thread handler for posix input.
|
|
*
|
|
* @param thread The thread that is running.
|
|
*/
|
|
void consoleInputThread(thread_t *thread);
|
|
#endif |