Console support functions. More...
#include "common.h"Go to the source code of this file.
Macros | |
| #define | QSC_CONSOLE_MAX_LINE 128ULL |
| The maximum length of a console string. | |
Enumerations | |
| enum | qsc_console_font_color { white = 0x00U , blue = 0x01U , green = 0x02U , red = 0x03U } |
| The console font color choices. More... | |
| enum | qsc_console_font_style { regular = 0x00U , bold = 0x01U , italic = 0x02U , bolditalic = 0x03U } |
| The console font style options. More... | |
Functions | |
| QSC_EXPORT_API void | qsc_consoleutils_colored_message (const char *message, qsc_console_font_color color) |
| Print a colored console message. | |
| QSC_EXPORT_API char | qsc_consoleutils_get_char (void) |
| Get a character from the console in a blocking manner. | |
| QSC_EXPORT_API size_t | qsc_consoleutils_get_formatted_line (char *line, size_t maxlen) |
| Get a formatted line of text from the console. | |
| QSC_EXPORT_API size_t | qsc_consoleutils_get_line (char *line, size_t maxlen) |
| Get a line of text from the console. | |
| QSC_EXPORT_API size_t | qsc_consoleutils_get_quoted_string (char *output, const char *input, size_t maxlen) |
| Extract a quoted string from input. | |
| QSC_EXPORT_API char | qsc_consoleutils_get_wait (void) |
| Wait for user input from the console. | |
| QSC_EXPORT_API void | qsc_consoleutils_hex_to_bin (const char *hexstr, uint8_t *output, size_t length) |
| Convert a hexadecimal string to a binary (byte) array. | |
| QSC_EXPORT_API bool | qsc_consoleutils_line_contains (const char *line, const char *token) |
| Check if a line of text contains a given token. | |
| QSC_EXPORT_API bool | qsc_consoleutils_line_equals (const char *line1, const char *line2) |
| Compare two lines of text for equivalence. | |
| QSC_EXPORT_API size_t | qsc_consoleutils_masked_password (char *output, size_t otplen) |
| Read a masked password from the console. | |
| QSC_EXPORT_API bool | qsc_consoleutils_message_confirm (const char *message) |
| Display a confirmation message and wait for a Y/N response. | |
| QSC_EXPORT_API void | qsc_consoleutils_print_array (const uint8_t *input, size_t inplen, size_t linelen) |
| Print a byte array to the console. | |
| QSC_EXPORT_API void | qsc_consoleutils_print_hex (const uint8_t *input, size_t inplen, size_t linelen) |
| Print a byte array as hexadecimal values to the console. | |
| QSC_EXPORT_API void | qsc_consoleutils_print_formatted (const char *input, size_t inplen) |
| Print a formatted string to the console, ignoring special characters. | |
| QSC_EXPORT_API void | qsc_consoleutils_print_formatted_line (const char *input, size_t inplen) |
| Print a formatted string to the console with a line break. | |
| QSC_EXPORT_API void | qsc_consoleutils_print_safe (const char *input) |
| Print a string safely to the console. | |
| QSC_EXPORT_API void | qsc_consoleutils_print_line (const char *input) |
| Print a string to the console with a trailing line break. | |
| QSC_EXPORT_API void | qsc_consoleutils_print_uint (uint32_t digit) |
| Print an unsigned 32-bit integer to the console. | |
| QSC_EXPORT_API void | qsc_consoleutils_print_ulong (uint64_t digit) |
| Print an unsigned 64-bit integer to the console. | |
| QSC_EXPORT_API void | qsc_consoleutils_print_double (double digit) |
| Print a double-precision floating point number to the console. | |
| QSC_EXPORT_API void | qsc_consoleutils_print_concatenated_line (const char **input, size_t count) |
| Print a double-precision floating point number to the console. | |
| QSC_EXPORT_API void | qsc_consoleutils_progress_counter (int32_t seconds) |
| Display a small spinning progress counter for a specified duration. | |
| QSC_EXPORT_API void | qsc_consoleutils_send_enter (void) |
| Send an "enter" (newline) command to the console. | |
| QSC_EXPORT_API void | qsc_consoleutils_set_window_buffer (size_t width, size_t height) |
| Set the vertical scroll buffer size of the console window. | |
| QSC_EXPORT_API void | qsc_consoleutils_set_window_clear (void) |
| Clear all text from the console window. | |
| QSC_EXPORT_API void | qsc_consoleutils_set_window_prompt (const char *prompt) |
| Set the console window prompt string. | |
| QSC_EXPORT_API void | qsc_consoleutils_set_window_size (size_t width, size_t height) |
| Set the size of the console window. | |
| QSC_EXPORT_API void | qsc_consoleutils_set_window_title (const char *title) |
| Set the title of the console window. | |
| QSC_EXPORT_API void | qsc_consoleutils_set_virtual_terminal (void) |
| Enable virtual terminal processing mode in the console. | |
Console support functions.
This header provides a comprehensive set of functions for console input/output operations. The functionality includes:
| QSC_EXPORT_API void qsc_consoleutils_colored_message | ( | const char * | message, |
| qsc_console_font_color | color ) |
Print a colored console message.
Changes the console text color, prints the message, then resets the color.
| message | [const char*] A pointer to the constant message string. |
| color | [qsc_console_font_color] The desired font color (from qsc_console_font_color). |
| QSC_EXPORT_API char qsc_consoleutils_get_char | ( | void | ) |
Get a character from the console in a blocking manner.
| QSC_EXPORT_API size_t qsc_consoleutils_get_formatted_line | ( | char * | line, |
| size_t | maxlen ) |
Get a formatted line of text from the console.
Reads a line of text from the console, converts it to lowercase, and trims trailing newline characters.
| line | [char*] A pointer to the character array that receives the text. |
| maxlen | [size_t] The maximum number of characters to read. |
| QSC_EXPORT_API size_t qsc_consoleutils_get_line | ( | char * | line, |
| size_t | maxlen ) |
Get a line of text from the console.
Reads a line of text from the console.
| line | [char*] A pointer to the character array that receives the text. |
| maxlen | [size_t] The maximum number of characters to read. |
| QSC_EXPORT_API size_t qsc_consoleutils_get_quoted_string | ( | char * | output, |
| const char * | input, | ||
| size_t | maxlen ) |
Extract a quoted string from input.
Searches the input for a quoted substring (using either double or single quotes) and copies it to the output array.
| output | [char*] A pointer to the destination array for the extracted string. |
| input | [const char*] A pointer to the input string. |
| maxlen | [size_t] The maximum number of characters to extract. |
| QSC_EXPORT_API char qsc_consoleutils_get_wait | ( | void | ) |
Wait for user input from the console.
Blocks until a character is input by the user.
| QSC_EXPORT_API void qsc_consoleutils_hex_to_bin | ( | const char * | hexstr, |
| uint8_t * | output, | ||
| size_t | length ) |
Convert a hexadecimal string to a binary (byte) array.
| hexstr | [const char*] A pointer to the constant hexadecimal string. |
| output | [uint8_t*] A pointer to the output byte array. |
| length | [size_t] The number of bytes to convert. |
| QSC_EXPORT_API bool qsc_consoleutils_line_contains | ( | const char * | line, |
| const char * | token ) |
Check if a line of text contains a given token.
| line | [const char*] A pointer to the constant input line. |
| token | [const char*] A pointer to the constant token string to search for. |
| QSC_EXPORT_API bool qsc_consoleutils_line_equals | ( | const char * | line1, |
| const char * | line2 ) |
Compare two lines of text for equivalence.
| line1 | [const char*] A pointer to the first constant input string. |
| line2 | [const char*] A pointer to the second constant input string. |
| QSC_EXPORT_API size_t qsc_consoleutils_masked_password | ( | char * | output, |
| size_t | otplen ) |
Read a masked password from the console.
Displays masking characters (e.g., asterisks) as the user types and stores the password.
| output | [char*] A pointer to the output character array to store the password. |
| otplen | [size_t] The maximum size of the output array. |
| QSC_EXPORT_API bool qsc_consoleutils_message_confirm | ( | const char * | message | ) |
Display a confirmation message and wait for a Y/N response.
| message | [const char*] A pointer to the confirmation dialog message. |
| QSC_EXPORT_API void qsc_consoleutils_print_array | ( | const uint8_t * | input, |
| size_t | inplen, | ||
| size_t | linelen ) |
Print a byte array to the console.
Prints the array in a formatted manner with a specified number of characters per line.
| input | [const uint8_t*] A pointer to the constant byte array. |
| inplen | [size_t] The number of bytes in the array. |
| linelen | [size_t] The number of bytes to print per line. |
| QSC_EXPORT_API void qsc_consoleutils_print_concatenated_line | ( | const char ** | input, |
| size_t | count ) |
Print a double-precision floating point number to the console.
| input | [const char**] A pointer to the constant string array. |
| count | [size_t] The number of strings in the array. |
| QSC_EXPORT_API void qsc_consoleutils_print_double | ( | double | digit | ) |
Print a double-precision floating point number to the console.
| digit | [double] The double value to print. |
| QSC_EXPORT_API void qsc_consoleutils_print_formatted | ( | const char * | input, |
| size_t | inplen ) |
Print a formatted string to the console, ignoring special characters.
| input | [const char*] A pointer to the constant string. |
| inplen | [size_t] The number of characters to print. |
| QSC_EXPORT_API void qsc_consoleutils_print_formatted_line | ( | const char * | input, |
| size_t | inplen ) |
Print a formatted string to the console with a line break.
| input | [const char*] A pointer to the constant string. |
| inplen | [size_t] The number of characters to print. |
| QSC_EXPORT_API void qsc_consoleutils_print_hex | ( | const uint8_t * | input, |
| size_t | inplen, | ||
| size_t | linelen ) |
Print a byte array as hexadecimal values to the console.
| input | [const uint8_t*] A pointer to the constant byte array. |
| inplen | [size_t] The number of bytes in the array. |
| linelen | [size_t] The number of bytes to print per line before starting a new line. |
| QSC_EXPORT_API void qsc_consoleutils_print_line | ( | const char * | input | ) |
Print a string to the console with a trailing line break.
| input | [const char*] A pointer to the constant string. |
| QSC_EXPORT_API void qsc_consoleutils_print_safe | ( | const char * | input | ) |
Print a string safely to the console.
Prints the string while ignoring any potentially unsafe characters.
| input | [const char*] A pointer to the constant string. |
| QSC_EXPORT_API void qsc_consoleutils_print_uint | ( | uint32_t | digit | ) |
Print an unsigned 32-bit integer to the console.
| digit | [uint32_t] The 32-bit unsigned integer to print. |
| QSC_EXPORT_API void qsc_consoleutils_print_ulong | ( | uint64_t | digit | ) |
Print an unsigned 64-bit integer to the console.
| digit | [uint64_t] The 64-bit unsigned integer to print. |
| QSC_EXPORT_API void qsc_consoleutils_progress_counter | ( | int32_t | seconds | ) |
Display a small spinning progress counter for a specified duration.
| seconds | [int32_t] The number of seconds to run the progress counter. |
| QSC_EXPORT_API void qsc_consoleutils_set_window_buffer | ( | size_t | width, |
| size_t | height ) |
Set the vertical scroll buffer size of the console window.
| width | [size_t] The desired buffer width. |
| height | [size_t] The desired buffer height. |
| QSC_EXPORT_API void qsc_consoleutils_set_window_prompt | ( | const char * | prompt | ) |
Set the console window prompt string.
| prompt | [const char*] A pointer to the prompt string. |
| QSC_EXPORT_API void qsc_consoleutils_set_window_size | ( | size_t | width, |
| size_t | height ) |
Set the size of the console window.
| width | [size_t] The desired window width. |
| height | [size_t] The desired window height. |
| QSC_EXPORT_API void qsc_consoleutils_set_window_title | ( | const char * | title | ) |
Set the title of the console window.
| title | [const char*] A pointer to the title string. |