mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
fastfetch: pretty printing --help
This commit is contained in:
parent
0ffbb8c364
commit
d64716ab74
@ -40,10 +40,93 @@ static void printCommandFormatHelp(const char* command)
|
|||||||
fprintf(stderr, "Error: Module '%s' is not supported\n", type.chars);
|
fprintf(stderr, "Error: Module '%s' is not supported\n", type.chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void printCommandHelp(const char* command)
|
static void printCommandHelp(const char* command)
|
||||||
{
|
{
|
||||||
if(command == NULL)
|
if(command == NULL)
|
||||||
puts(FASTFETCH_DATATEXT_HELP);
|
{
|
||||||
|
static char input[] = FASTFETCH_DATATEXT_HELP;
|
||||||
|
if (isatty(STDOUT_FILENO))
|
||||||
|
{
|
||||||
|
char* token = strtok(input, "\n");
|
||||||
|
puts(token);
|
||||||
|
|
||||||
|
while ((token = strtok(NULL, "\n")))
|
||||||
|
{
|
||||||
|
// handle empty lines
|
||||||
|
char* back = token;
|
||||||
|
while (*--back != '\0');
|
||||||
|
ffPrintCharTimes('\n', (uint32_t) (token - back - 1));
|
||||||
|
|
||||||
|
if (isalpha(*token)) // highlight subjects
|
||||||
|
{
|
||||||
|
char* colon = strchr(token, ':');
|
||||||
|
if (colon)
|
||||||
|
{
|
||||||
|
fputs("\e[1;4m", stdout); // Bold + Underline
|
||||||
|
fwrite(token, 1, (uint32_t) (colon - token), stdout);
|
||||||
|
fputs("\e[m", stdout);
|
||||||
|
|
||||||
|
if (colon - token == 5 && memcmp(token, "Usage", 5) == 0)
|
||||||
|
{
|
||||||
|
char* cmd = strstr(colon, "fastfetch ");
|
||||||
|
if (cmd)
|
||||||
|
{
|
||||||
|
fwrite(colon, 1, (uint32_t) (cmd - colon), stdout);
|
||||||
|
fputs("\e[1mfastfetch \e[m", stdout);
|
||||||
|
cmd += strlen("fastfetch ");
|
||||||
|
if (*cmd == '<')
|
||||||
|
{
|
||||||
|
char* gt = strchr(cmd, '>');
|
||||||
|
if (gt)
|
||||||
|
{
|
||||||
|
fputs("\e[3m", stdout);
|
||||||
|
fwrite(cmd, 1, (uint32_t) (gt - cmd + 1), stdout);
|
||||||
|
fputs("\e[m", stdout);
|
||||||
|
cmd = gt + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
puts(cmd);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
puts(colon);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (*token == ' ') // highlight options. All options are indented
|
||||||
|
{
|
||||||
|
char* dash = strchr(token, '-'); // start of an option
|
||||||
|
if (dash)
|
||||||
|
{
|
||||||
|
char* colon = strchr(dash, ':'); // end of an option
|
||||||
|
if (colon)
|
||||||
|
{
|
||||||
|
*colon = '\0';
|
||||||
|
char* lt = strrchr(dash, '<');
|
||||||
|
*colon = ':';
|
||||||
|
fputs("\e[1m", stdout); // Bold
|
||||||
|
fwrite(token, 1, (uint32_t) ((lt ? lt : colon) - token), stdout);
|
||||||
|
fputs("\e[m", stdout);
|
||||||
|
if (lt)
|
||||||
|
{
|
||||||
|
fputs("\e[3m", stdout);
|
||||||
|
fwrite(lt, 1, (uint32_t) (colon - lt), stdout);
|
||||||
|
fputs("\e[m", stdout);
|
||||||
|
}
|
||||||
|
puts(colon);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
puts(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
puts(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(ffStrEqualsIgnCase(command, "color"))
|
else if(ffStrEqualsIgnCase(command, "color"))
|
||||||
puts(FASTFETCH_DATATEXT_HELP_COLOR);
|
puts(FASTFETCH_DATATEXT_HELP_COLOR);
|
||||||
else if(ffStrEqualsIgnCase(command, "format"))
|
else if(ffStrEqualsIgnCase(command, "format"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user