Skip to content

Commit

Permalink
feat: Enhance output of --all function
Browse files Browse the repository at this point in the history
  • Loading branch information
yellow-footed-honeyguide committed Sep 16, 2024
1 parent 4328154 commit 2c63d25
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.10)
project(nooks VERSION 1.4.1)
project(nooks VERSION 1.4.2)

set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED True)
Expand Down
40 changes: 16 additions & 24 deletions actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void show_all_spots() {
return; // Exit function
}

printf("Saved nooks:\n\n"); // Print header for saved nooks
printf("Marked paths:\n"); // Print header for saved nooks
char line[MAX_PATH]; // Buffer for reading lines from config file
while (fgets(line, sizeof(line), file) != NULL) { // Read config file line by line
line[strcspn(line, "\n")] = '\0'; // Remove trailing newline character
Expand All @@ -220,8 +220,8 @@ void show_all_spots() {
char saved_dir[MAX_PATH]; // Buffer for directory path in current line
if (sscanf(line, "%s %s", saved_spot, saved_dir) ==
2) { // Extract spot and directory from line
printf("\033[48;5;24m\033[37m%s:\033[0m \033[3m%s\033[0m\n", saved_spot,
saved_dir); // Print spot and directory with formatting
// Print spot and directory with formatting
printf("\033[48;2;230;240;250m\033[38;2;0;70;120m\033[1m%s:\033[0m \033[38;2;80;80;80m%s\033[0m\n", saved_spot, saved_dir);
}
}

Expand All @@ -240,27 +240,19 @@ void print_help() {
printf("Navigate to saved directories or save the current directory.\n"); // Print description
printf("\n"); // Print blank line
printf("Options:\n"); // Print options header
printf(" -s, --save-mark [NAME] Save the current directory with an mark name\n"); // Print
// save-mark
// option
printf(" -q, --quiet Quiet mode\n"); // Print quiet mode option
printf(" -a, --all Show all saved directories\n"); // Print show all option
printf(" -h, --help Display this help and exit\n"); // Print help option
printf("\n"); // Print blank line
printf("Examples:\n"); // Print examples header
printf(
" nooks -s work Save the current directory with the name 'work'\n"); // Print
// save
// example
printf(
" nooks work Navigate to the directory saved with the name 'work'\n"); // Print navigate example
printf(" nooks -a Show all saved directories\n"); // Print show all example
printf("\n"); // Print blank line
printf(
"Report bugs to https://github.com/yellow-footed-honeyguide/nooks/issues\n"); // Print
// bug
// report
// information
printf(" -s, --save-mark [NAME] Save the current directory with an mark name\n");
printf(" -d, --delete-mark [NAME] Delete saved mark\n");
printf(" -q, --quiet Quiet mode\n");
printf(" -a, --all-marks Show all saved directories\n");
printf(" -h, --help Display this help and exit\n");
printf("\n");
printf("Examples:\n");
printf(" nooks -s work Save the current directory with the name 'work'\n");
printf(" nooks -d work Delete mark 'work'\n");
printf(" nooks work Navigate to the directory saved with the name 'work'\n");
printf(" nooks -a Show all saved directories\n");
printf("\n");
printf("Report bugs to https://github.com/yellow-footed-honeyguide/nooks/issues\n");
}

/**
Expand Down
8 changes: 4 additions & 4 deletions handle_arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void handle_arguments(int argc, char *argv[]) { // Function to process command-
static struct option long_options[] = {
{"save-mark", required_argument, 0, 's'}, // Option to save current directory
{"delete-mark", required_argument, 0, 'd'}, // Option to save current directory
{"all", no_argument, 0, 'a'}, // Option to show all saved spots
{"all-marks", no_argument, 0, 'a'}, // Option to show all saved spots
{"help", no_argument, 0, 'h'}, // Option to display help
{"version", no_argument, 0, 'v'}, // Option to display version
{"quiet", no_argument, 0, 'q'}, // Option for quiet mode
Expand Down Expand Up @@ -57,14 +57,14 @@ void handle_arguments(int argc, char *argv[]) { // Function to process command-
fprintf(stderr, "Option -%c requires an argument.\n",
optopt); // Print error message
fprintf(stderr,
"Usage: %s [-s|--save-mark mark_name] [-a|--all] [-h|--help] "
"Usage: %s [-s|--save-mark mark_name] [-a|--all-marks] [-h|--help] "
"[directory_name]\n",
argv[0]); // Print usage information
exit(EXIT_FAILURE); // Exit the program with failure status
} else { // For other unknown options
fprintf(stderr, "Unknown option '-%c'.\n", optopt); // Print error message
fprintf(stderr,
"Usage: %s [-s|--save-mark mark_name] [-d|--delete-mark mark_name] [-a|--all] [-h|--help] "
"Usage: %s [-s|--save-mark mark_name] [-d|--delete-mark mark_name] [-a|--all-marks] [-h|--help] "
"[directory_name]\n",
argv[0]); // Print usage information
exit(EXIT_FAILURE); // Exit the program with failure status
Expand All @@ -75,7 +75,7 @@ void handle_arguments(int argc, char *argv[]) { // Function to process command-
}
}

// Handle the --all or -a option
// Handle the --all-marks or -a option
if (all_option_used) {
show_all_spots();
return;
Expand Down

0 comments on commit 2c63d25

Please sign in to comment.