Skip to content

Commit

Permalink
bugfix: pywal should handle if the colours are not present
Browse files Browse the repository at this point in the history
  • Loading branch information
nikp123 committed Jul 12, 2024
1 parent 8582f51 commit 210a8e7
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions src/shared/config/pywal.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@

EXP_FUNC bool pywalConfigGetFilename(char *filename) {
char *a = getenv("XDG_CACHE_HOME");
if (a == NULL){
if(a == NULL) {
a = getenv("HOME");
// user should not be HOME-less under any circumstances
// we will not handle a HOME-less case
if(a == NULL)
return false;

sprintf(filename,"%s%s", a, "/.config/wal/colors");
} else {
sprintf(filename,"%s%s",a,"/wal/colors");
return true;
}
if (a == NULL){
return false;
} else {
sprintf(filename,"%s%s",a,"/.cache/wal/colors");
sprintf(filename,"%s%s", a, "/wal/colors");
}

FILE *file = fopen(filename, "r");
if ( file != NULL )
{

if(file != NULL) {
fclose(file);
} else {
return false;
}

return true;
}

Expand All @@ -35,27 +37,18 @@ EXP_FUNC void pywalGetColors(unsigned int *fgColorNum, unsigned int *bgColorNum)
pywalConfigGetFilename(filename);
FILE *file = fopen(filename, "r");
int count = 0;
if ( file != NULL )
{
if(file != NULL) {
char line[256]; /* or other suitable maximum line size */
while (fgets(line, sizeof line, file) != NULL) /* read a line */
{
if (count == lineNumberFg)
{
while (fgets(line, sizeof line, file) != NULL) {
if (count == lineNumberFg) {
sscanf(line, "#%06X", fgColorNum);
}
else if (count == lineNumberBg)
{
} else if (count == lineNumberBg) {
sscanf(line, "#%06X", bgColorNum);
break;
}
else
{
count++;
}
} else count++;
}
fclose(file);
}
fclose(file);
free(filename);
}

Expand Down

2 comments on commit 210a8e7

@nikp123
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@make-42 did you use an LLM to generate this code. Just checking.

@make-42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not. I did use StackOverflow though.

Please sign in to comment.