WallShell
An easy-to-use, highly portable, CLI using C99.
|
Main source file for WallShell. More...
Functions | |
void | ws_setStream (ws_stream type, FILE *stream) |
Sets the stream to the provided one. More... | |
void | ws_initializeDefaultStreams () |
Initialize all streams to their defaults. More... | |
void | ws_resetConsoleState () |
Resets the console state. More... | |
void | ws_setAsciiDeleteAsBackspace (bool b) |
Some consoles send backspace as ASCII delete (0x7f) instead of '\b'. More... | |
void | ws_setForegroundDefault (ws_fg_color_t c) |
Set the default foreground color. More... | |
void | ws_setBackgroundDefault (ws_bg_color_t c) |
Set the default background color. More... | |
void | ws_setDefaultColors (ws_color_t c) |
Set the default colors to the provided ones. More... | |
ws_color_t | ws_getCurrentColors () |
Get the current console colors. More... | |
ws_color_t | ws_getDefaultColors () |
Get the current default colors. More... | |
ws_error_t | ws_setConsoleColors (ws_color_t colors) |
Set the background and foreground colors to the provided ones. More... | |
ws_error_t | ws_setForegroundColor (ws_fg_color_t color) |
Sets the foreground color to the provided color. More... | |
ws_error_t | ws_setBackgroundColor (ws_bg_color_t color) |
Sets the background color to the provided color. More... | |
void | ws_lockMutex (ws_mutex_t *mut) |
Locks the provided mutex. More... | |
void | ws_unlockMutex (ws_mutex_t *mut) |
Unlocks the provided mutex. More... | |
ws_mutex_t * | ws_createMutex () |
Create a mutex. More... | |
void | ws_destroyMutex (ws_mutex_t *mut) |
Destroys the provided mutex. More... | |
ws_thread_id_t | ws_getThreadID () |
Gets the threadID of the calling thread. More... | |
void | ws_sleep (size_t ms) |
Sleep function wrapper. More... | |
bool | ws_getAtomicBool (ws_atomic_bool_t *ab) |
Gets the value stored by the atomic bool. More... | |
void | ws_setAtomicBool (ws_atomic_bool_t *ab, bool b) |
Sets the value of the provided atomic bool. More... | |
ws_atomic_bool_t * | ws_createAtomicBool (bool b) |
Creates an atomic bool. More... | |
void | ws_destroyAtomicBool (ws_atomic_bool_t *ab) |
Destroys the provided atomic bool. More... | |
void | ws_setThreadName (char *name) |
Sets the name of the calling thread. More... | |
void | ws_removeThreadName (const char *name) |
Removes the name of the provided thread. More... | |
void | ws_printThreadID () |
Prints the threadID of the calling thread. | |
void | ws_doPrintThreadID (bool b) |
Set print threadID, which prints the threadID of function calling ws_logger . More... | |
void | ws_vlogger (ws_logtype_t type, const char *format, va_list args) |
Logger function for WallShell. More... | |
void | ws_logger (ws_logtype_t type, const char *format,...) |
Logger function for WallShell. More... | |
void | ws_setLoggerColors (ws_logtype_t type, ws_fg_color_t fg, ws_bg_color_t bg) |
Set the logger colors for the specified log type. More... | |
ws_error_t | ws_registerCommand (const ws_command_t c) |
Register the command to the command handler. More... | |
void | ws_deregisterCommand (const ws_command_t c) |
Deregister the provided command. More... | |
void | ws_stopTerminal () |
Stops the currently running terminal. More... | |
void | ws_moveCursor_n (ws_cursor_t direction, size_t n) |
Move the cursor n times in the provided direction. More... | |
void | ws_moveCursor (ws_cursor_t direction) |
Moves the cursor once in the provided direction. More... | |
ws_error_t | ws_executeCommand (char *commandBuf) |
Execute a command with the provided buffer. More... | |
void | ws_setConsolePrefix (const char *newPrefix) |
Set the prefix to the provided one. More... | |
void | ws_cleanAll () |
Cleans everything. More... | |
ws_error_t | ws_terminalMain () |
Main function for the terminal. More... | |
bool | ws_compareCommands (const ws_command_t c1, const ws_command_t c2) |
Operator overloading isn't available in C. More... | |
void | ws_setConsoleLocale () |
Sets the console locale. More... | |
void | ws_printGeneralHelp (ws_help_entry_general_t *entry) |
help More... | |
void | ws_printSpecificHelp (ws_help_entry_specific_t *entry) |
Prints the specific help entry. More... | |
bool | ws_promptUser (const char *format,...) |
Prompts the user yes/no using the given prompt. More... | |
Main source file for WallShell.
C99 compliant command handler. Meant to be easily portable and highly configurable.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
void ws_cleanAll | ( | ) |
Cleans everything.
Resets everything to it's default state, frees all allocations, etc. Ideally you should call this before you exit, but the system garbage collector should clean it up. Don't rely on the system gc for critical applications.
bool ws_compareCommands | ( | const ws_command_t | c1, |
const ws_command_t | c2 | ||
) |
Operator overloading isn't available in C.
Compare two commands using this.
c1 | Command to compare. |
c2 | Command to compare. |
ws_atomic_bool_t* ws_createAtomicBool | ( | bool | b | ) |
Creates an atomic bool.
b | Initial value held by the bool. |
ws_mutex_t* ws_createMutex | ( | ) |
Create a mutex.
void ws_deregisterCommand | ( | const ws_command_t | c | ) |
Deregister the provided command.
c | Command to be deregistered. If it doesn't exist (not already registered), nothing happens. |
void ws_destroyAtomicBool | ( | ws_atomic_bool_t * | ab | ) |
Destroys the provided atomic bool.
ab | Atomic bool to destroy. |
void ws_destroyMutex | ( | ws_mutex_t * | mut | ) |
Destroys the provided mutex.
mut | mutex to be destroyed. |
void ws_doPrintThreadID | ( | bool | b | ) |
Set print threadID, which prints the threadID of function calling ws_logger
.
Defaults to on.
b | True to turn on, false to turn off. |
ws_error_t ws_executeCommand | ( | char * | commandBuf | ) |
Execute a command with the provided buffer.
commandBuf | Buffer containing the command to execute, including any flags, parameters, etc. |
bool ws_getAtomicBool | ( | ws_atomic_bool_t * | ab | ) |
Gets the value stored by the atomic bool.
ab | Atomic bool object pointer. |
ws_color_t ws_getCurrentColors | ( | ) |
Get the current console colors.
ws_color_t ws_getDefaultColors | ( | ) |
Get the current default colors.
ws_thread_id_t ws_getThreadID | ( | ) |
Gets the threadID of the calling thread.
void ws_initializeDefaultStreams | ( | ) |
Initialize all streams to their defaults.
All default to their std-versions. (stdout, stderr, stdin)
void ws_lockMutex | ( | ws_mutex_t * | mut | ) |
Locks the provided mutex.
mut | Mutex to be locked. |
void ws_logger | ( | ws_logtype_t | type, |
const char * | format, | ||
... | |||
) |
Logger function for WallShell.
Printf like formatting, automatically adds a newline.
type | Type of logging. |
format | Printf style formatting string. |
... | Printf style formatting arguments. |
void ws_moveCursor | ( | ws_cursor_t | direction | ) |
Moves the cursor once in the provided direction.
direction | Direction to move, using ws_cursor_t. |
void ws_moveCursor_n | ( | ws_cursor_t | direction, |
size_t | n | ||
) |
Move the cursor n times in the provided direction.
direction | Direction to move the cursor, using ws_cursor_t. |
n | Amount of times to move in that direction. |
void ws_printGeneralHelp | ( | ws_help_entry_general_t * | entry | ) |
void ws_printSpecificHelp | ( | ws_help_entry_specific_t * | entry | ) |
bool ws_promptUser | ( | const char * | format, |
... | |||
) |
Prompts the user yes/no using the given prompt.
format | Printf style formatting string. |
... | Printf style arguments. |
ws_error_t ws_registerCommand | ( | const ws_command_t | c | ) |
Register the command to the command handler.
c | Command to be registered. |
void ws_removeThreadName | ( | const char * | name | ) |
Removes the name of the provided thread.
name | Name of the thread. |
void ws_resetConsoleState | ( | ) |
Resets the console state.
This is called automatically by ws_cleanAll().
void ws_setAsciiDeleteAsBackspace | ( | bool | b | ) |
Some consoles send backspace as ASCII delete (0x7f) instead of '\b'.
If your system does this, set this to true. This only needs to be done if CUSTOM_WS_SETUP is defined. For POSIX this is typically true, for Windows this is false.
b | Bool to set backspace_as_ascii_delete to. |
void ws_setAtomicBool | ( | ws_atomic_bool_t * | ab, |
bool | b | ||
) |
Sets the value of the provided atomic bool.
ab | Atomic bool object. |
b | Value to set the bool to. |
ws_error_t ws_setBackgroundColor | ( | ws_bg_color_t | color | ) |
Sets the background color to the provided color.
color | Color to set the background to. |
void ws_setBackgroundDefault | ( | ws_bg_color_t | c | ) |
Set the default background color.
c | Color to set the default to. |
ws_error_t ws_setConsoleColors | ( | ws_color_t | colors | ) |
Set the background and foreground colors to the provided ones.
colors | Colors to set the background and foreground to. |
void ws_setConsoleLocale | ( | ) |
Sets the console locale.
This is only required on Windows systems, as terminals default to ASCII.
The built in SET_TERMINAL_LOCALE sets the Windows terminal to UTF8. Can be potentially be used on unix systems to configure locale, although this isn't done by default. If the system you are implementing requires locale configuration, redefine SET_TERMINAL_LOCALE to the needed configuration.
void ws_setConsolePrefix | ( | const char * | newPrefix | ) |
Set the prefix to the provided one.
The prefix is what is displayed at the start of a command line. It is possible to use this function to imitate a bash like user@name:path$
, or any other combination.
newPrefix |
void ws_setDefaultColors | ( | ws_color_t | c | ) |
Set the default colors to the provided ones.
c | Colors to set the defaults to. |
ws_error_t ws_setForegroundColor | ( | ws_fg_color_t | color | ) |
Sets the foreground color to the provided color.
color | Color to set the foreground to. |
void ws_setForegroundDefault | ( | ws_fg_color_t | c | ) |
Set the default foreground color.
c | Color to set the default to. |
void ws_setLoggerColors | ( | ws_logtype_t | type, |
ws_fg_color_t | fg, | ||
ws_bg_color_t | bg | ||
) |
Set the logger colors for the specified log type.
type | Type of logging. |
fg | Foreground color. |
bg | Background color. |
void ws_setStream | ( | ws_stream | type, |
FILE * | stream | ||
) |
Sets the stream to the provided one.
type | Type of stream to change. |
stream | Stream you wish to change it to. |
void ws_setThreadName | ( | char * | name | ) |
Sets the name of the calling thread.
This will only be printed if threadID is true.
name | Name of the thread. |
void ws_sleep | ( | size_t | ms | ) |
Sleep function wrapper.
ms | Sleep time in milliseconds. |
void ws_stopTerminal | ( | ) |
Stops the currently running terminal.
Only supported in threaded applications.
ws_error_t ws_terminalMain | ( | ) |
Main function for the terminal.
Call after any configuration.
void ws_unlockMutex | ( | ws_mutex_t * | mut | ) |
Unlocks the provided mutex.
mut | Mutex to be unlocked. |
void ws_vlogger | ( | ws_logtype_t | type, |
const char * | format, | ||
va_list | args | ||
) |
Logger function for WallShell.
vprintf like formatting, automatically adds a newline.
type | Type of logging. |
format | printf style formatting string. |
args | va_list of arguments. |