QSC Post Quantum Cryptographic Library 1.0.0.6c (A6)
A post quantum secure library written in Ansi C
 
Loading...
Searching...
No Matches
consoleutils.h File Reference

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.
 

Detailed Description

Console support functions.

This header provides a comprehensive set of functions for console input/output operations. The functionality includes:

  • Printing messages with customizable colors and styles.
  • Reading individual characters and complete lines from the console.
  • Formatting and printing arrays, hexadecimal data, and numerical values.
  • Managing console window properties such as buffer size, window dimensions, title, and prompt.
  • Enabling virtual terminal processing to support advanced text formatting.
Example Usage:
#include "consoleutils.h"
// Print a colored message.
qsc_consoleutils_colored_message("Welcome to QRCS Console!", blue);
// Read a formatted line from the console.
// Set the console window title.
Console support functions.
#define QSC_CONSOLE_MAX_LINE
The maximum length of a console string.
Definition consoleutils.h:85
QSC_EXPORT_API size_t qsc_consoleutils_get_formatted_line(char *line, size_t maxlen)
Get a formatted line of text from the console.
Definition consoleutils.c:148
@ blue
Definition consoleutils.h:94
QSC_EXPORT_API void qsc_consoleutils_set_window_title(const char *title)
Set the title of the console window.
Definition consoleutils.c:693
QSC_EXPORT_API void qsc_consoleutils_colored_message(const char *message, qsc_console_font_color color)
Print a colored console message.
Definition consoleutils.c:63

Reference Links:

Enumeration Type Documentation

◆ qsc_console_font_color

The console font color choices.

Enumerator
white 

White

blue 

Blue

green 

Green

red 

Red

◆ qsc_console_font_style

The console font style options.

Enumerator
regular 

Regular

bold 

Bold

italic 

Italic

bolditalic 

Bold and Italic

Function Documentation

◆ qsc_consoleutils_colored_message()

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.

Parameters
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_consoleutils_get_char()

QSC_EXPORT_API char qsc_consoleutils_get_char ( void )

Get a character from the console in a blocking manner.

Returns
Returns [char] the character read from console input.

◆ qsc_consoleutils_get_formatted_line()

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.

Parameters
line[char*] A pointer to the character array that receives the text.
maxlen[size_t] The maximum number of characters to read.
Returns
[size_t] Returns the number of characters read.

◆ qsc_consoleutils_get_line()

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.

Parameters
line[char*] A pointer to the character array that receives the text.
maxlen[size_t] The maximum number of characters to read.
Returns
[size_t] Returns the number of characters read.

◆ qsc_consoleutils_get_quoted_string()

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.

Parameters
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.
Returns
[size_t] Returns the number of characters in the quoted string.

◆ qsc_consoleutils_get_wait()

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.

Returns
[char] Returns the character read from console input.

◆ qsc_consoleutils_hex_to_bin()

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.

Parameters
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_consoleutils_line_contains()

QSC_EXPORT_API bool qsc_consoleutils_line_contains ( const char * line,
const char * token )

Check if a line of text contains a given token.

Parameters
line[const char*] A pointer to the constant input line.
token[const char*] A pointer to the constant token string to search for.
Returns
[bool] Returns true if the token is found; otherwise, false.

◆ qsc_consoleutils_line_equals()

QSC_EXPORT_API bool qsc_consoleutils_line_equals ( const char * line1,
const char * line2 )

Compare two lines of text for equivalence.

Parameters
line1[const char*] A pointer to the first constant input string.
line2[const char*] A pointer to the second constant input string.
Returns
[bool] Returns true if the strings are equal; otherwise, false.

◆ qsc_consoleutils_masked_password()

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.

Parameters
output[char*] A pointer to the output character array to store the password.
otplen[size_t] The maximum size of the output array.
Returns
[size_t] Returns the number of characters in the password.

◆ qsc_consoleutils_message_confirm()

QSC_EXPORT_API bool qsc_consoleutils_message_confirm ( const char * message)

Display a confirmation message and wait for a Y/N response.

Parameters
message[const char*] A pointer to the confirmation dialog message.
Returns
[bool] Returns true if the user confirms (Y/y), otherwise false.

◆ qsc_consoleutils_print_array()

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.

Parameters
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_consoleutils_print_concatenated_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.

Parameters
input[const char**] A pointer to the constant string array.
count[size_t] The number of strings in the array.

◆ qsc_consoleutils_print_double()

QSC_EXPORT_API void qsc_consoleutils_print_double ( double digit)

Print a double-precision floating point number to the console.

Parameters
digit[double] The double value to print.

◆ qsc_consoleutils_print_formatted()

QSC_EXPORT_API void qsc_consoleutils_print_formatted ( const char * input,
size_t inplen )

Print a formatted string to the console, ignoring special characters.

Parameters
input[const char*] A pointer to the constant string.
inplen[size_t] The number of characters to print.

◆ qsc_consoleutils_print_formatted_line()

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.

Parameters
input[const char*] A pointer to the constant string.
inplen[size_t] The number of characters to print.

◆ qsc_consoleutils_print_hex()

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.

Parameters
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_consoleutils_print_line()

QSC_EXPORT_API void qsc_consoleutils_print_line ( const char * input)

Print a string to the console with a trailing line break.

Parameters
input[const char*] A pointer to the constant string.

◆ qsc_consoleutils_print_safe()

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.

Parameters
input[const char*] A pointer to the constant string.

◆ qsc_consoleutils_print_uint()

QSC_EXPORT_API void qsc_consoleutils_print_uint ( uint32_t digit)

Print an unsigned 32-bit integer to the console.

Parameters
digit[uint32_t] The 32-bit unsigned integer to print.

◆ qsc_consoleutils_print_ulong()

QSC_EXPORT_API void qsc_consoleutils_print_ulong ( uint64_t digit)

Print an unsigned 64-bit integer to the console.

Parameters
digit[uint64_t] The 64-bit unsigned integer to print.

◆ qsc_consoleutils_progress_counter()

QSC_EXPORT_API void qsc_consoleutils_progress_counter ( int32_t seconds)

Display a small spinning progress counter for a specified duration.

Parameters
seconds[int32_t] The number of seconds to run the progress counter.

◆ qsc_consoleutils_set_window_buffer()

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.

Parameters
width[size_t] The desired buffer width.
height[size_t] The desired buffer height.

◆ qsc_consoleutils_set_window_prompt()

QSC_EXPORT_API void qsc_consoleutils_set_window_prompt ( const char * prompt)

Set the console window prompt string.

Parameters
prompt[const char*] A pointer to the prompt string.

◆ qsc_consoleutils_set_window_size()

QSC_EXPORT_API void qsc_consoleutils_set_window_size ( size_t width,
size_t height )

Set the size of the console window.

Parameters
width[size_t] The desired window width.
height[size_t] The desired window height.

◆ qsc_consoleutils_set_window_title()

QSC_EXPORT_API void qsc_consoleutils_set_window_title ( const char * title)

Set the title of the console window.

Parameters
title[const char*] A pointer to the title string.