From 7810e661142326f79115c136f95c1a47bad01a89 Mon Sep 17 00:00:00 2001 From: Laan Tungir Date: Thu, 14 Aug 2025 11:28:34 -0400 Subject: [PATCH] Version v0.2.72 - Clean pipe mode output - suppressed startup messages for seamless piping --- otp.c | 55 +++++++++++++++---------------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/otp.c b/otp.c index 2947ebe..cfade7a 100644 --- a/otp.c +++ b/otp.c @@ -134,18 +134,23 @@ int main(int argc, char* argv[]) { // Load preferences first load_preferences(); + // Check for piped input first (before any output) + int is_pipe_mode = (argc == 1 && has_stdin_data()); + // Check for OTP thumb drive on startup char otp_drive_path[512]; if (detect_otp_thumb_drive(otp_drive_path, sizeof(otp_drive_path))) { - printf("Detected OTP thumb drive: %s\n", otp_drive_path); - printf("Using as default pads directory for this session.\n\n"); + // Only show messages in interactive/command mode, not pipe mode + if (!is_pipe_mode) { + printf("Detected OTP thumb drive: %s\n", otp_drive_path); + printf("Using as default pads directory for this session.\n\n"); + } strncpy(current_pads_dir, otp_drive_path, sizeof(current_pads_dir) - 1); current_pads_dir[sizeof(current_pads_dir) - 1] = '\0'; } - // Check for piped input - if (argc == 1 && has_stdin_data()) { - // No arguments but has piped data - enter pipe mode for interactive pad selection + if (is_pipe_mode) { + // No arguments but has piped data - enter pipe mode char* piped_text = read_stdin_text(); if (piped_text) { int result = pipe_mode(argc, argv, piped_text); @@ -2409,8 +2414,6 @@ int pipe_mode(int argc, char* argv[], const char* piped_text) { (void)argc; // Suppress unused parameter warning (void)argv; // Suppress unused parameter warning - printf("Piped text received: \"%s\"\n", piped_text); - // Check if we have a default pad configured char* default_pad = get_default_pad_path(); if (default_pad) { @@ -2427,49 +2430,21 @@ int pipe_mode(int argc, char* argv[], const char* piped_text) { strncpy(pad_checksum, filename, 64); pad_checksum[64] = '\0'; - printf("Using default pad: %.16s...\n\n", pad_checksum); free(default_pad); - // Encrypt using the default pad + // Encrypt using the default pad (silent mode) return encrypt_text(pad_checksum, piped_text); } } - printf("Warning: Default pad not found or invalid: %s\n", default_pad); + fprintf(stderr, "Error: Default pad not found or invalid: %s\n", default_pad); free(default_pad); - // Fall through to interactive selection - } - - printf("No default pad configured.\n\n"); - - // List available pads for interactive selection - int pad_count = list_available_pads(); - if (pad_count == 0) { - printf("No pads available. Generate a pad first.\n"); return 1; } - // Reopen stdin from the controlling terminal for interactive input - FILE* tty = fopen("/dev/tty", "r"); - if (!tty) { - printf("Error: Cannot open terminal for input\n"); - return 1; - } - - printf("\nEnter pad selection (number, checksum, or prefix): "); - fflush(stdout); - - char pad_input[MAX_HASH_LENGTH]; - if (!fgets(pad_input, sizeof(pad_input), tty)) { - printf("Error: Failed to read pad selection\n"); - fclose(tty); - return 1; - } - pad_input[strcspn(pad_input, "\n")] = 0; - fclose(tty); - - // Encrypt the piped text - return encrypt_text(pad_input, piped_text); + fprintf(stderr, "Error: No default pad configured for pipe mode\n"); + fprintf(stderr, "Configure a default pad in ~/.otp/otp.conf\n"); + return 1; } // Preferences management functions implementation