Skip to content

Commit e6e1894

Browse files
Refactor font output
1 parent 32d3b26 commit e6e1894

File tree

18 files changed

+150
-148
lines changed

18 files changed

+150
-148
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ set(LIBFASTFETCH_SRC
200200
src/detection/cpu/cpu.c
201201
src/detection/gpu/gpu.c
202202
src/detection/memory/memory.c
203+
src/detection/font/font.c
203204
src/detection/displayserver/displayserver.c
204205
src/detection/terminalfont/terminalfont.c
205206
src/detection/media/media.c

completions/bash

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ __fastfetch_completion()
180180
"--cpu-temp"
181181
"--gpu-temp"
182182
"--battery-temp"
183-
"--font-inline"
184183
"--localip-show-ipv4"
185184
"--localip-show-ipv6"
186185
"--localip-show-loop"

presets/examples/5

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
--icons-key I
99
--icons-format {5}
1010
--font-key F
11-
--font-format {21}
1211
--cursor-key C

presets/verbose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
--wm-theme-format Name: {}
1212
--theme-format Plasma: {}; Plasma colors: {}; Plasma colors pretty: {}; GTK2: {}; GTK3: {}; GTK4: {}; GTK: {}
1313
--icons-format Plasma: {}; GTK2: {}; GTK3: {}; GTK4: {}; GTK: {}
14-
--font-format Type: {}; Font: {}
14+
--font-format Font1: {}; Font2: {}; Font3: {}; Font4: {}
1515
--cursor-format Theme: {}; Size: {}
1616
--terminal-format Process: {}; Path: {}; Exe: {}
1717
--terminal-font-format Pretty: {}; Name: {}; Size: {}; Styles: {}

src/common/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ static void defaultConfig(FFinstance* instance)
236236

237237
ffStrbufInitA(&instance->config.separatorString, 0);
238238

239-
instance->config.fontInline = true;
240-
241239
instance->config.localIpShowIpV4 = true;
242240
instance->config.localIpShowIpV6 = false;
243241
instance->config.localIpShowLoop = false;

src/data/help.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ Module specific options:
9797
--cpu-temp <?value>: Detect and display CPU temperature if supported. Default is false
9898
--gpu-temp <?value>: Detect and display GPU temperature if supported. Default is false
9999
--battery-temp <?value>: Detect and display Battery temperature if supported. Default is false
100-
--font-inline <?value>: Display fonts of different DE in one line
101100
--localip-show-ipv4 <?value>: Show ipv4 addresses in local ip module. Default is true
102101
--localip-show-ipv6 <?value>: Show ipv6 addresses in local ip module. Default is false
103102
--localip-show-loop <?value>: Show loop back addresses (127.0.0.1) in local ip module. Default is false

src/detection/font/font.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "font.h"
2+
#include "detection/internal.h"
3+
4+
void ffDetectFontImpl(const FFinstance* instance, FFFontResult* font);
5+
6+
static void detectFont(const FFinstance* instance, FFFontResult* font)
7+
{
8+
ffStrbufInit(&font->error);
9+
10+
for(uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i)
11+
ffStrbufInit(&font->fonts[i]);
12+
13+
ffDetectFontImpl(instance, font);
14+
15+
if(font->error.length > 0)
16+
return;
17+
18+
for(uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i)
19+
{
20+
if(font->fonts[i].length > 0)
21+
return;
22+
}
23+
24+
ffStrbufAppendS(&font->error, "No fonts found");
25+
}
26+
27+
const FFFontResult* ffDetectFont(const FFinstance* instance)
28+
{
29+
FF_DETECTION_INTERNAL_GUARD(FFFontResult,
30+
detectFont(instance, &result);
31+
);
32+
}

src/detection/font/font.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44
#define FF_INCLUDED_detection_font_font
55

66
#include "fastfetch.h"
7-
#include "util/FFstrbuf.h"
8-
#include "util/FFlist.h"
7+
8+
#define FF_DETECT_FONT_NUM_FONTS 4
99

1010
typedef struct FFFontResult
1111
{
12-
const char* type;
13-
FFstrbuf fontPretty;
12+
FFstrbuf error;
13+
14+
/**
15+
* Linux / BSD: QT, GTK2, GTK3, GTK4
16+
* MacOS: System, User, Unset, Unset
17+
* Other: Unset, Unset, Unset, Unset
18+
*/
19+
FFstrbuf fonts[FF_DETECT_FONT_NUM_FONTS];
1420
} FFFontResult;
1521

16-
const char* ffDetectFontImpl(FFinstance* instance, FFlist* result);
22+
const FFFontResult* ffDetectFont(const FFinstance* instance);
1723

1824
#endif

src/detection/font/font_android.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include "fastfetch.h"
2-
#include "common/font.h"
32

4-
const char* ffDetectFontImpl(FFinstance* instance, FFlist* result)
3+
void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
54
{
6-
FF_UNUSED(instance, result);
7-
return "Font detection is not supported on Android";
5+
FF_UNUSED(instance);
6+
ffStrbufAppendS(&result->error, "Not implemented");
87
}

src/detection/font/font_apple.m

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,27 @@
44

55
#import <AppKit/AppKit.h>
66

7-
#define FF_FONT_MODULE_NAME "Font"
8-
9-
static void detectFontForType(CTFontUIFontType uiType, FFFontResult* result)
7+
static void detectFontForType(CTFontUIFontType uiType, FFstrbuf* font)
108
{
119
CTFontRef ctFont = CTFontCreateUIFontForLanguage(uiType, 12, NULL);
10+
ffCfStrGetString(CTFontCopyFullName(ctFont), font);
1211

13-
ffStrbufInit(&result->fontPretty);
14-
ffCfStrGetString(CTFontCopyFullName(ctFont), &result->fontPretty);
12+
if(font->length == 0)
13+
return;
1514

1615
FFstrbuf familyName;
1716
ffStrbufInit(&familyName);
1817
ffCfStrGetString(CTFontCopyFamilyName(ctFont), &familyName);
1918

20-
if (ffStrbufComp(&familyName, &result->fontPretty) != 0)
21-
{
22-
ffStrbufAppendF(&result->fontPretty, " (%*s)", familyName.length, familyName.chars);
23-
}
19+
if (ffStrbufComp(&familyName, font) != 0)
20+
ffStrbufAppendF(font, " (%*s)", familyName.length, familyName.chars);
2421

2522
ffStrbufDestroy(&familyName);
2623
}
2724

28-
const char* ffDetectFontImpl(FFinstance* instance, FFlist* result)
25+
void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
2926
{
3027
FF_UNUSED(instance);
31-
32-
FFFontResult* resultSystem = (FFFontResult*)ffListAdd(result);
33-
resultSystem->type = "SYS";
34-
detectFontForType(kCTFontUIFontSystem, resultSystem);
35-
36-
FFFontResult* resultUser = (FFFontResult*)ffListAdd(result);
37-
resultUser->type = "USER";
38-
detectFontForType(kCTFontUIFontUser, resultUser);
39-
40-
return NULL;
28+
detectFontForType(kCTFontUIFontSystem, &result->fonts[0]);
29+
detectFontForType(kCTFontUIFontUser, &result->fonts[1]);
4130
}

0 commit comments

Comments
 (0)