oops many changes
This commit is contained in:
12 files changed
+219
-330
No files matched your search
@@ -1,52 +1,86 @@
|
||||
#include "app/cli.h"
|
||||
#include "common/utils.h"
|
||||
#include "config.h"
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// Helper function to parse device-specific arguments
|
||||
static int parse_device_argument(const char *optarg, const char *action,
|
||||
int *keyboard_value, int *mouse_value, int value) {
|
||||
if (optarg == NULL || strcmp(optarg, "both") == 0) {
|
||||
*keyboard_value = value;
|
||||
*mouse_value = value;
|
||||
} else if (strcmp(optarg, "keyboard") == 0) {
|
||||
*keyboard_value = value;
|
||||
} else if (strcmp(optarg, "mouse") == 0) {
|
||||
*mouse_value = value;
|
||||
} else {
|
||||
fprintf(stderr, "Error: Invalid %s device '%s'\n", action, optarg);
|
||||
fprintf(stderr, "Use: keyboard, mouse, or both\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Helper function to validate and set volume
|
||||
static void set_volume(int *volume_ptr, int value) {
|
||||
*volume_ptr = validate_volume(value);
|
||||
}
|
||||
|
||||
void print_usage(const char *program_name) {
|
||||
printf("KeyVibe - Mechanical Keyboard Sound Simulator\n");
|
||||
printf("Version: %s\n\n", PROJECT_VERSION);
|
||||
|
||||
|
||||
printf("USAGE:\n");
|
||||
printf(" %s [OPTIONS]\n\n", program_name);
|
||||
|
||||
|
||||
printf("SOUND CONTROL:\n");
|
||||
printf(" -S, --sound PACK Keyboard sound pack (default: eg-oreo)\n");
|
||||
printf(" -M, --mouse PACK Mouse sound pack (default: ping)\n");
|
||||
printf(" -l, --list List available sound packs\n\n");
|
||||
|
||||
|
||||
printf("VOLUME CONTROL:\n");
|
||||
printf(" -V, --volume LEVEL Set both keyboard & mouse volume [0-100]\n");
|
||||
printf(
|
||||
" -V, --volume LEVEL Set both keyboard & mouse volume [0-100]\n");
|
||||
printf(" -K, --keyboard-volume Set keyboard volume [0-100]\n");
|
||||
printf(" -O, --mouse-volume Set mouse volume [0-100]\n\n");
|
||||
|
||||
|
||||
printf("MUTE CONTROL:\n");
|
||||
printf(" -m, --mute[=DEVICE] Mute sounds (keyboard|mouse|both)\n");
|
||||
printf(" -u, --unmute[=DEVICE] Unmute sounds (keyboard|mouse|both)\n\n");
|
||||
|
||||
|
||||
printf("ENABLE/DISABLE:\n");
|
||||
printf(" --enable[=DEVICE] Enable sounds (keyboard|mouse|both)\n");
|
||||
printf(" --disable[=DEVICE] Disable sounds (keyboard|mouse|both)\n\n");
|
||||
|
||||
|
||||
printf("DAEMON CONTROL:\n");
|
||||
printf(" -d, --daemon Run in background\n");
|
||||
printf(" -s, --stop Stop background daemon\n\n");
|
||||
|
||||
|
||||
printf("OTHER:\n");
|
||||
printf(" -v, --verbose Enable verbose output\n");
|
||||
printf(" -h, --help Show this help\n\n");
|
||||
|
||||
|
||||
printf("EXAMPLES:\n");
|
||||
printf(" %s --list # List sound packs\n", program_name);
|
||||
printf(" %s -S cherrymx-blue -V 75 # Cherry MX Blue at 75%%\n", program_name);
|
||||
printf(" %s --daemon # Run in background\n", program_name);
|
||||
printf(" %s --mute keyboard # Mute only keyboard\n", program_name);
|
||||
printf(" %s --disable mouse # Disable mouse sounds\n", program_name);
|
||||
printf(" %s --keyboard-volume 80 --mouse-volume 60 # Different volumes\n", program_name);
|
||||
printf(" %s --list # List sound packs\n",
|
||||
program_name);
|
||||
printf(" %s -S cherrymx-blue -V 75 # Cherry MX Blue at "
|
||||
"75%%\n",
|
||||
program_name);
|
||||
printf(" %s --daemon # Run in background\n",
|
||||
program_name);
|
||||
printf(" %s --mute keyboard # Mute only keyboard\n",
|
||||
program_name);
|
||||
printf(
|
||||
" %s --disable mouse # Disable mouse sounds\n",
|
||||
program_name);
|
||||
printf(" %s --keyboard-volume 80 --mouse-volume 60 # Different volumes\n",
|
||||
program_name);
|
||||
printf("\n");
|
||||
printf("CONFIG: Settings are saved to ~/.keyvibe.json and auto-reload in daemon mode.\n");
|
||||
printf("CONFIG: Settings are saved to ~/.keyvibe.json and auto-reload in "
|
||||
"daemon mode.\n");
|
||||
}
|
||||
|
||||
int parse_cli(int argc, char **argv, CliOptions *out) {
|
||||
@@ -115,96 +149,41 @@ int parse_cli(int argc, char **argv, CliOptions *out) {
|
||||
out->mouse_sound = optarg;
|
||||
break;
|
||||
case 'V':
|
||||
out->volume = atoi(optarg);
|
||||
if (out->volume < 0)
|
||||
out->volume = 0;
|
||||
if (out->volume > 100)
|
||||
out->volume = 100;
|
||||
set_volume(&out->volume, atoi(optarg));
|
||||
break;
|
||||
case 'K':
|
||||
out->keyboard_volume = atoi(optarg);
|
||||
if (out->keyboard_volume < 0)
|
||||
out->keyboard_volume = 0;
|
||||
if (out->keyboard_volume > 100)
|
||||
out->keyboard_volume = 100;
|
||||
set_volume(&out->keyboard_volume, atoi(optarg));
|
||||
break;
|
||||
case 'O':
|
||||
out->mouse_volume = atoi(optarg);
|
||||
if (out->mouse_volume < 0)
|
||||
out->mouse_volume = 0;
|
||||
if (out->mouse_volume > 100)
|
||||
out->mouse_volume = 100;
|
||||
set_volume(&out->mouse_volume, atoi(optarg));
|
||||
break;
|
||||
case 'm':
|
||||
if (optarg == NULL || strcmp(optarg, "both") == 0) {
|
||||
out->keyboard_mute = 1;
|
||||
out->mouse_mute = 1;
|
||||
} else if (strcmp(optarg, "keyboard") == 0) {
|
||||
out->keyboard_mute = 1;
|
||||
} else if (strcmp(optarg, "mouse") == 0) {
|
||||
out->mouse_mute = 1;
|
||||
} else {
|
||||
fprintf(stderr, "Error: Invalid mute device '%s'\n", optarg);
|
||||
fprintf(stderr, "Use: keyboard, mouse, or both\n");
|
||||
if (parse_device_argument(optarg, "mute", &out->keyboard_mute, &out->mouse_mute, 1) != 0) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
if (optarg == NULL || strcmp(optarg, "both") == 0) {
|
||||
out->keyboard_mute = 0;
|
||||
out->mouse_mute = 0;
|
||||
} else if (strcmp(optarg, "keyboard") == 0) {
|
||||
out->keyboard_mute = 0;
|
||||
} else if (strcmp(optarg, "mouse") == 0) {
|
||||
out->mouse_mute = 0;
|
||||
} else {
|
||||
fprintf(stderr, "Error: Invalid unmute device '%s'\n", optarg);
|
||||
fprintf(stderr, "Use: keyboard, mouse, or both\n");
|
||||
if (parse_device_argument(optarg, "unmute", &out->keyboard_mute, &out->mouse_mute, 0) != 0) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case 1000: // --enable
|
||||
if (optarg == NULL) {
|
||||
// Handle space-separated argument: --enable mouse
|
||||
if (optind < argc && argv[optind][0] != '-') {
|
||||
optarg = argv[optind++];
|
||||
} else {
|
||||
optarg = "both"; // default to both if no argument
|
||||
}
|
||||
}
|
||||
if (strcmp(optarg, "both") == 0) {
|
||||
out->keyboard_enabled = 1;
|
||||
out->mouse_enabled = 1;
|
||||
} else if (strcmp(optarg, "keyboard") == 0) {
|
||||
out->keyboard_enabled = 1;
|
||||
} else if (strcmp(optarg, "mouse") == 0) {
|
||||
out->mouse_enabled = 1;
|
||||
} else {
|
||||
fprintf(stderr, "Error: Invalid enable device '%s'\n", optarg);
|
||||
fprintf(stderr, "Use: keyboard, mouse, or both\n");
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case 1001: // --disable
|
||||
if (optarg == NULL) {
|
||||
// Handle space-separated argument: --disable mouse
|
||||
if (optind < argc && argv[optind][0] != '-') {
|
||||
optarg = argv[optind++];
|
||||
} else {
|
||||
optarg = "both"; // default to both if no argument
|
||||
{
|
||||
int enable_value = (opt == 1000) ? 1 : 0;
|
||||
const char *action = (opt == 1000) ? "enable" : "disable";
|
||||
|
||||
if (optarg == NULL) {
|
||||
// Handle space-separated argument: --enable mouse
|
||||
if (optind < argc && argv[optind][0] != '-') {
|
||||
optarg = argv[optind++];
|
||||
} else {
|
||||
optarg = "both"; // default to both if no argument
|
||||
}
|
||||
}
|
||||
if (parse_device_argument(optarg, action, &out->keyboard_enabled, &out->mouse_enabled, enable_value) != 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (strcmp(optarg, "both") == 0) {
|
||||
out->keyboard_enabled = 0;
|
||||
out->mouse_enabled = 0;
|
||||
} else if (strcmp(optarg, "keyboard") == 0) {
|
||||
out->keyboard_enabled = 0;
|
||||
} else if (strcmp(optarg, "mouse") == 0) {
|
||||
out->mouse_enabled = 0;
|
||||
} else {
|
||||
fprintf(stderr, "Error: Invalid disable device '%s'\n", optarg);
|
||||
fprintf(stderr, "Use: keyboard, mouse, or both\n");
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case 'l':
|
||||
|
||||
Reference in new issue
Block a user