Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gzip help text #2060

Merged
merged 3 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const char** argv_dnsmasq = NULL;
#define COL_BLUE "\x1b[94m" // bright foreground color
#define COL_PURPLE "\x1b[95m" // bright foreground color
#define COL_CYAN "\x1b[96m" // bright foreground color
#define CLI_OVER "\r\x1b[K" // go back to beginning of line and erase to end of line

static bool __attribute__ ((pure)) is_term(void)
{
Expand Down Expand Up @@ -149,6 +150,16 @@ const char __attribute__ ((pure)) *cli_bold(void)
return is_term() ? COL_BOLD : "";
}

const char __attribute__ ((pure)) *cli_underline(void)
{
return is_term() ? COL_ULINE : "";
}

const char __attribute__ ((pure)) *cli_italics(void)
{
return is_term() ? COL_ITALIC : "";
}

// Resets font to normal
const char __attribute__ ((pure)) *cli_normal(void)
{
Expand All @@ -165,7 +176,7 @@ static const char __attribute__ ((pure)) *cli_color(const char *color)
const char __attribute__ ((pure)) *cli_over(void)
{
// \x1b[K is the ANSI escape sequence for "erase to end of line"
return is_term() ? "\r\x1b[K" : "\r";
return is_term() ? CLI_OVER : "\r";
}

static inline bool strEndsWith(const char *input, const char *end)
Expand Down Expand Up @@ -925,6 +936,7 @@ void parse_args(int argc, char* argv[])
if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "help") == 0 || strcmp(argv[i], "--help") == 0)
{
const char *bold = cli_bold();
const char *uline = cli_underline();
const char *normal = cli_normal();
const char *blue = cli_color(COL_BLUE);
const char *cyan = cli_color(COL_CYAN);
Expand Down Expand Up @@ -1015,12 +1027,17 @@ void parse_args(int argc, char* argv[])

printf("%sEmbedded GZIP un-/compressor:%s\n", yellow, normal);
printf(" A simple but fast in-memory gzip compressor\n\n");
printf(" Usage: %spihole-FTL --compress %sinfile %s[outfile]%s\n", green, cyan, purple, normal);
printf(" Usage: %spihole-FTL --uncompress %sinfile %s[outfile]%s\n\n", green, cyan, purple, normal);
printf(" - %sinfile%s is the file to be compressed.\n", cyan, normal);
printf(" - %s[outfile]%s is the optional target. If omitted, FTL will\n", purple, normal);
printf(" %s--compress%s: use the %sinfile%s and append %s.gz%s at the end\n", green, normal, cyan, normal, cyan, normal);
printf(" %s--uncompress%s: use the %sinfile%s and remove %s.gz%s at the end\n\n", green, normal, cyan, normal, cyan, normal);
printf(" Usage: %spihole-FTL --gzip %sinfile %s[outfile]%s\n\n", green, cyan, purple, normal);
printf(" - %sinfile%s is the file to be processed. If the filename ends\n", cyan, normal);
printf(" in %s.gz%s, FTL will uncompress, otherwise it will compress\n\n", yellow, normal);
printf(" - %s[outfile]%s is the optional target file.\n", purple, normal);
printf(" If omitted, FTL will try to derive the target file from\n");
printf(" the source file.\n\n");
printf(" Examples:\n");
printf(" - %spihole-FTL --gzip %sfile.txt%s\n", green, cyan, normal);
printf(" compresses %sfile.txt%s to %sfile.txt%s.gz%s\n\n", cyan, normal, cyan, yellow, normal);
printf(" - %spihole-FTL --gzip %sfile.txt%s.gz%s\n", green, cyan, yellow, normal);
printf(" %sun%scompresses %sfile.txt%s.gz%s to %sfile.txt%s\n\n", uline, normal, cyan, yellow, normal, cyan, normal);

printf("%sTeleporter:%s\n", yellow, normal);
printf("\t%s--teleporter%s Create a Teleporter archive in the\n", green, normal);
Expand Down
2 changes: 2 additions & 0 deletions src/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const char *cli_done(void) __attribute__ ((pure));
const char *cli_bold(void) __attribute__ ((pure));
const char *cli_normal(void) __attribute__ ((pure));
const char *cli_over(void) __attribute__ ((pure));
const char *cli_underline(void) __attribute__ ((pure));
const char *cli_italics(void) __attribute__ ((pure));

void test_dnsmasq_options(int argc, const char *argv[]);

Expand Down
Loading