[v0.23] Add --logo-short/long. Closes #11

This commit is contained in:
Dr-Noob
2022-01-23 10:55:26 +01:00
parent bd1158c139
commit d120f9a1cd
4 changed files with 58 additions and 19 deletions

View File

@@ -26,6 +26,8 @@ struct args_struct {
bool verbose_flag;
bool version_flag;
bool list_gpus;
bool logo_long;
bool logo_short;
int gpu_idx;
STYLE style;
struct color** colors;
@@ -35,21 +37,25 @@ int errn = 0;
static struct args_struct args;
const char args_chr[] = {
/* [ARG_COLOR] = */ 'c',
/* [ARG_GPU] = */ 'g',
/* [ARG_LIST] = */ 'l',
/* [ARG_HELP] = */ 'h',
/* [ARG_VERBOSE] = */ 'v',
/* [ARG_VERSION] = */ 'V',
/* [ARG_COLOR] = */ 'c',
/* [ARG_GPU] = */ 'g',
/* [ARG_LIST] = */ 'l',
/* [ARG_LOGO_LONG] = */ 1,
/* [ARG_LOGO_SHORT] = */ 2,
/* [ARG_HELP] = */ 'h',
/* [ARG_VERBOSE] = */ 'v',
/* [ARG_VERSION] = */ 'V',
};
const char *args_str[] = {
/* [ARG_COLOR] = */ "color",
/* [ARG_GPU] = */ "gpu",
/* [ARG_LIST] = */ "list-gpus",
/* [ARG_HELP] = */ "help",
/* [ARG_VERBOSE] = */ "verbose",
/* [ARG_VERSION] = */ "version",
/* [ARG_COLOR] = */ "color",
/* [ARG_GPU] = */ "gpu",
/* [ARG_LIST] = */ "list-gpus",
/* [ARG_LOGO_LONG] = */ "logo-long",
/* [ARG_LOGO_SHORT] = */ "logo-short",
/* [ARG_HELP] = */ "help",
/* [ARG_VERBOSE] = */ "verbose",
/* [ARG_VERSION] = */ "version",
};
int getarg_int(char* str) {
@@ -111,6 +117,14 @@ bool list_gpus() {
return args.list_gpus;
}
bool show_logo_long() {
return args.logo_long;
}
bool show_logo_short() {
return args.logo_short;
}
bool show_version() {
return args.version_flag;
}
@@ -134,8 +148,9 @@ char* build_short_options() {
char* str = (char *) emalloc(sizeof(char) * (len*2 + 1));
memset(str, 0, sizeof(char) * (len*2 + 1));
sprintf(str, "%c:%c:%c%c%c%c", c[ARG_GPU],
sprintf(str, "%c:%c:%c%c%c%c%c%c", c[ARG_GPU],
c[ARG_COLOR], c[ARG_HELP], c[ARG_LIST],
c[ARG_LOGO_SHORT], c[ARG_LOGO_LONG],
c[ARG_VERBOSE], c[ARG_VERSION]);
return str;
@@ -203,16 +218,20 @@ bool parse_args(int argc, char* argv[]) {
args.version_flag = false;
args.help_flag = false;
args.list_gpus = false;
args.logo_long = false;
args.logo_short = false;
args.gpu_idx = 0;
args.colors = NULL;
const struct option long_options[] = {
{args_str[ARG_COLOR], required_argument, 0, args_chr[ARG_COLOR] },
{args_str[ARG_GPU], required_argument, 0, args_chr[ARG_GPU] },
{args_str[ARG_LIST], no_argument, 0, args_chr[ARG_LIST] },
{args_str[ARG_HELP], no_argument, 0, args_chr[ARG_HELP] },
{args_str[ARG_VERBOSE], no_argument, 0, args_chr[ARG_VERBOSE] },
{args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] },
{args_str[ARG_COLOR], required_argument, 0, args_chr[ARG_COLOR] },
{args_str[ARG_GPU], required_argument, 0, args_chr[ARG_GPU] },
{args_str[ARG_LIST], no_argument, 0, args_chr[ARG_LIST] },
{args_str[ARG_LOGO_SHORT], no_argument, 0, args_chr[ARG_LOGO_SHORT] },
{args_str[ARG_LOGO_LONG], no_argument, 0, args_chr[ARG_LOGO_LONG] },
{args_str[ARG_HELP], no_argument, 0, args_chr[ARG_HELP] },
{args_str[ARG_VERBOSE], no_argument, 0, args_chr[ARG_VERBOSE] },
{args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] },
{0, 0, 0, 0}
};
@@ -237,6 +256,12 @@ bool parse_args(int argc, char* argv[]) {
else if(opt == args_chr[ARG_LIST]) {
args.list_gpus = true;
}
else if(opt == args_chr[ARG_LOGO_SHORT]) {
args.logo_short = true;
}
else if(opt == args_chr[ARG_LOGO_LONG]) {
args.logo_long = true;
}
else if(opt == args_chr[ARG_HELP]) {
args.help_flag = true;
}
@@ -260,6 +285,12 @@ bool parse_args(int argc, char* argv[]) {
args.help_flag = true;
}
if(args.logo_short && args.logo_long) {
printWarn("%s and %s cannot be specified together", args_str[ARG_LOGO_SHORT], args_str[ARG_LOGO_LONG]);
args.logo_short = false;
args.logo_long = false;
}
if((args.help_flag + args.version_flag) > 1) {
printWarn("You should specify just one option");
args.help_flag = true;

View File

@@ -20,6 +20,8 @@ enum {
ARG_COLOR,
ARG_GPU,
ARG_LIST,
ARG_LOGO_LONG,
ARG_LOGO_SHORT,
ARG_HELP,
ARG_VERBOSE,
ARG_VERSION
@@ -34,6 +36,8 @@ int max_arg_str_length();
bool parse_args(int argc, char* argv[]);
bool show_help();
bool list_gpus();
bool show_logo_long();
bool show_logo_short();
bool show_version();
bool verbose_enabled();
void free_colors_struct(struct color** cs);

View File

@@ -22,6 +22,8 @@ void print_help(char *argv[]) {
printf(" -%c, --%s %*s Set the color scheme (by default, gpufetch uses the system color scheme) See COLORS section for a more detailed explanation\n", c[ARG_COLOR], t[ARG_COLOR], (int) (max_len-strlen(t[ARG_COLOR])), "");
printf(" -%c, --%s %*s List the available GPUs in the system\n", c[ARG_LIST], t[ARG_LIST], (int) (max_len-strlen(t[ARG_LIST])), "");
printf(" -%c, --%s %*s Select the GPU to use (default: 0)\n", c[ARG_GPU], t[ARG_GPU], (int) (max_len-strlen(t[ARG_GPU])), "");
printf(" --%s %*s Show the short version of the logo\n", t[ARG_LOGO_SHORT], (int) (max_len-strlen(t[ARG_LOGO_SHORT])), "");
printf(" --%s %*s Show the long version of the logo\n", t[ARG_LOGO_LONG], (int) (max_len-strlen(t[ARG_LOGO_LONG])), "");
printf(" -%c, --%s %*s Enable verbose output\n", c[ARG_VERBOSE], t[ARG_VERBOSE], (int) (max_len-strlen(t[ARG_VERBOSE])), "");
printf(" -%c, --%s %*s Print this help and exit\n", c[ARG_HELP], t[ARG_HELP], (int) (max_len-strlen(t[ARG_HELP])), "");
printf(" -%c, --%s %*s Print gpufetch version and exit\n", c[ARG_VERSION], t[ARG_VERSION], (int) (max_len-strlen(t[ARG_VERSION])), "");

View File

@@ -219,6 +219,8 @@ void replace_bgbyfg_color(struct ascii_logo* logo) {
}
struct ascii_logo* choose_ascii_art_aux(struct ascii_logo* logo_long, struct ascii_logo* logo_short, struct terminal* term, int lf) {
if(show_logo_long()) return logo_long;
if(show_logo_short()) return logo_short;
if(ascii_fits_screen(term->w, *logo_long, lf)) {
return logo_long;
}