diff --git a/include/cute_airlib.h b/include/cute_airlib.h index cefbed4..0732e21 100644 --- a/include/cute_airlib.h +++ b/include/cute_airlib.h @@ -12,6 +12,7 @@ #define KMAG "\e[35m" #define KCYN "\e[36m" #define KWHT "\e[37m" +#define KHOL "\033[90m%s\033[0m" #include #include @@ -63,6 +64,34 @@ void richText(char *text, char *color, unsigned int bold, unsigned int italic, u printf("\n"); } +void placeholder(char *text, char *output, size_t output_size) { + int ch, index = 0; + + // Display the placeholder text in light gray using KHOL + printf(KHOL, text); + fflush(stdout); + + // Move cursor back to the beginning of the line to type over the placeholder + printf("\033[1000D"); // Move cursor far left + + // Read characters one by one + while ((ch = getchar()) != '\n' && ch != EOF) { + // If the user starts typing, clear the placeholder + if (index == 0) { + // Clear the placeholder by overwriting with spaces + printf("\033[1000D\033[0K"); // Move to start of line and clear it + fflush(stdout); + } + + // Add character to the output buffer + if (index < output_size - 1) { + output[index++] = ch; + } + } + output[index] = '\0'; // Null-terminate the input string + printf(KNRM); +} + // ------------------------------------ // Window // ------------------------------------