Skip to content

Conversation

DarNCelsius
Copy link
Contributor

No description provided.

@DarNCelsius
Copy link
Contributor Author

DarNCelsius commented May 9, 2021

It's a little beefy perhaps. I can't but help wish we had an xml solution to use for XFCE and Openbox files. Would tidy this up quite a bit. XFCE WM Theme is also in a similar file, which I had plans to do next.
XFConf is an option too:
xfconf

@LinusDierheimer
Copy link
Collaborator

Funny thing, i just pushed XFCE theme detection.

@DarNCelsius
Copy link
Contributor Author

I see it. So this could be done a lot simpler.

@LinusDierheimer
Copy link
Collaborator

Yes i'm just at reviewing your PR


ffParsePropFileConfig(instance, "xfce4/terminal/terminalrc", "FontUseSystem=%[^\n]", fontName.chars);

if((fontName.chars[0] == '\0') || !ffStrbufCompS(&fontName, "FALSE"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • A fontName.length == 0 is the better way to test for this when using strbufs.
  • Maybe an ffStrbufIgnCaseComp would be more save to get it right?
  • I think a ) == 0 is more readable as a ! which implicitly casts an uint32_t to a bool

static void printXCFETerminal(FFinstance* instance)
{
FFstrbuf fontName;
ffStrbufInitA(&fontName, 256);
Copy link
Collaborator

Choose a reason for hiding this comment

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

is a capacity of 256 really needed?

FFstrbuf fontName;
ffStrbufInitA(&fontName, 256);

ffParsePropFileConfig(instance, "xfce4/terminal/terminalrc", "FontUseSystem=%[^\n]", fontName.chars);
Copy link
Collaborator

Choose a reason for hiding this comment

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

You will need to do a ffStrbufRecalculateLength after directly writing to the char buffer.

Comment on lines 63 to 64
ffStrbufAppendC(&absolutePath, '/');
ffStrbufAppendS(&absolutePath, ".config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Those two lines can be combined to "/.config/x

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doh

Comment on lines 66 to 101
FILE* file = fopen(absolutePath.chars, "r");
if(file == NULL)
{
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't open \"%s\"", absolutePath.chars);
ffStrbufDestroy(&absolutePath);
ffStrbufDestroy(&fontName);

return;
}

FFstrbuf matchText;
ffStrbufInitAS(&matchText, 64, "<property name=\"MonospaceFontName\" type=\"string\" value=\"");

char* line = NULL;
size_t len = 0;

while(getline(&line, &len, file) != -1)
{
ffStrbufAppendS(&fontName, line);
ffStrbufTrimLeft(&fontName, ' ');

if(ffStrbufStartsWithS(&fontName, matchText.chars))
{
ffStrbufSubstrAfter(&fontName, matchText.length -1);
ffStrbufSubstrBefore(&fontName, fontName.length - 4); // ["/>\n]
break;
}
ffStrbufClear(&fontName);
}
ffStrbufDestroy(&matchText);
ffStrbufDestroy(&absolutePath);

if(line != NULL)
free(line);

fclose(file);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this whole section can be replaced by a ffParsePropFileConfig, see my implementation in WM theme.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ffParsePropFileConfig fails if the line has different spacing though. That's why I trimmed the result before the compare. It's very fragile if someone decides to edit the file manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could the function be modified to ignore leading/trailing whitespace somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leading would suffice.

Is there a use case for keeping leading white space intact?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think its worth implementing a ffSettingsGetXFConf at this point using libxfconf. I will look into this soon.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But as a note, a single white space in the scanf format string counts as any number of white spaces in the scanned string, thats why i prepended a single white space before the actual format string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the info. I await the new functionality. 😁

Copy link
Collaborator

Choose a reason for hiding this comment

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

You have waited long enough, here it is!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice. The new system looks a lot better too. 👍


fclose(file);

if(fontName.chars[0] != '\0')
Copy link
Collaborator

Choose a reason for hiding this comment

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

fontName.length > 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was using length initially - it failed unless I used Recalculate. This approach worked though.


static void printXCFETerminal(FFinstance* instance)
{
FFstrbuf fontName;
Copy link
Collaborator

Choose a reason for hiding this comment

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

With the following suggestions in mind, i'm not sure if we need a strbuf. Possible i'm wrong at this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was just trying to avoid including strings.h altogether.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am too, but if we never need to modify the buffer we need neither strbufs nor strings.h

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. Will try. :)

@DarNCelsius
Copy link
Contributor Author

Quite happy with this one, apart from the string.h requirement. I couldn't think of an elegant solution.

@LinusDierheimer
Copy link
Collaborator

This seems fine. There is no problem with including string.h, just with using some dangerous functions out of it. Good resource for this is the commit history of https://github.com/git/git/blob/master/banned.h. I don't see a problem with strcasecmp.

@LinusDierheimer LinusDierheimer merged commit 1ece13c into fastfetch-cli:master May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants