Skip to content

Commit

Permalink
make --no-save override --save and --copy
Browse files Browse the repository at this point in the history
  • Loading branch information
spitulax committed Jan 17, 2025
1 parent 0b8aff6 commit 520aed1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ bool capture(void) {
if (g_config->mode == MODE_CUSTOM) {
printf("Region : %s\n", g_config->region);
}
printf("Screenshot directory : %s\n", g_config->screenshot_dir);
if (g_config->save_mode & SAVEMODE_DISK) {
printf("Screenshot directory : %s\n", g_config->screenshot_dir);
printf("Output path : %s\n", g_config->output_path);
}
printf("Last region cache : %s\n", g_config->last_region_file);
Expand Down
19 changes: 15 additions & 4 deletions src/prog.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "compositors.h"
#include "utils.h"
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

Expand Down Expand Up @@ -77,6 +78,7 @@ void usage(void) {
printf(" should be used by last-region.\n");
printf(" Used in mode region and active-window.\n");
printf(" --no-save Don't save the captured image anywhere.\n");
printf(" Overrides --save and --copy.\n");
printf(" --verbose Print extra output.\n");
}

Expand Down Expand Up @@ -129,7 +131,14 @@ bool parse_mode_args(char ***it, Config *config) {
return true;
}

void post_parse_args(Config *config) {
typedef enum {
POST_ARG_NONE = 0,
POST_ARG_NO_SAVE = 1 << 0, // Overrides `save_mode`
} PostArg;

void post_parse_args(Config *config, uint32_t post_args) {
if (post_args & POST_ARG_NO_SAVE) config->save_mode = SAVEMODE_NONE;

imgtype_remap(config);
}

Expand Down Expand Up @@ -169,7 +178,9 @@ ParseArgsResult parse_args(int argc, char *argv[], Config *config) {
}
if (!parse_mode_args(&it, config)) return FAILED;

bool specified_save_mode = false;
uint32_t post_args = POST_ARG_NONE;
bool specified_save_mode = false;

const char *arg;
while ((arg = next_arg(&it)) != NULL) {
if (streq(arg, "--verbose")) {
Expand Down Expand Up @@ -207,7 +218,7 @@ ParseArgsResult parse_args(int argc, char *argv[], Config *config) {
config->save_mode |= SAVEMODE_CLIPBOARD;
}
} else if (streq(arg, "--no-save")) {
config->save_mode = SAVEMODE_NONE;
post_args |= POST_ARG_NO_SAVE;
} else if (streq(arg, "-t")) {
const char *type = next_arg(&it);
if (type == NULL) {
Expand Down Expand Up @@ -302,7 +313,7 @@ ParseArgsResult parse_args(int argc, char *argv[], Config *config) {
if (config->mode == MODE_TEST) return FAILED;
#endif

post_parse_args(config);
post_parse_args(config, post_args);
return OK;

#undef FAILED
Expand Down

0 comments on commit 520aed1

Please sign in to comment.