penelope icon indicating copy to clipboard operation
penelope copied to clipboard

Emoji check fix

Open DystopianRescuer opened this issue 5 months ago • 4 comments

Noto Color Emoji isn't the only available emoji font. Personally, I use Apple Color Emoji since most of my devices are Apple—except for my ThinkPad running Arch (it makes things feel more consistent, haha).

Beyond personal preference, there are several other fonts that provide emoji support — such as ttf-twemoji, ttf-joypixels, openmoji, and more — though some are less common.

A more robust approach would be to check whether any installed font supports at least one emoji (e.g., U+1F600, the 😀 emoji). This would provide a more reliable indication that a working emoji font is present on the system, regardless of its name.

DystopianRescuer avatar Jul 18 '25 03:07 DystopianRescuer

In my current code, if the system is Apple I return True as it supports all my emojis by default. fc-list probably isn't present by default on macOS so your code will return Exception. Also there are some default fonts on distros like Parrot which support smile but not other emojis I use.

brightio avatar Jul 18 '25 10:07 brightio

That is why i left the first if that checks if myOS is Darwin

DystopianRescuer avatar Jul 18 '25 15:07 DystopianRescuer

But yeah, i should probably consider the case where fc-list is not present and print something like "emoji font package could not be found" rather than stoping the program with an excepción, but i still do believe that checking that you have a package that supports one emoji is a better option than checking for an specific package, ill add the exception handler and ill pull request again. (ill also think a better a approach, what do you think about my first try? it's on my first commit)

DystopianRescuer avatar Jul 18 '25 15:07 DystopianRescuer

On linux systems, penelope most probably run on distros like Kali that already have this package installed. With my code

	possible_paths = (
		"/usr/share/fonts/truetype/noto/NotoColorEmoji.ttf",
		"/usr/share/fonts/noto/NotoColorEmoji.ttf",
		"/usr/local/share/fonts/noto/NotoColorEmoji.ttf",
		"/usr/local/share/fonts/noto-emoji/NotoColorEmoji.ttf"
	)

	for path in possible_paths:
		if os.path.isfile(path):
			return True

This way is faster that running fc-list with subprocess. Also there are distros that have the above files installed but not the fc-list binary. Generally I try to first catch the most cases and then the more rare as I go down.

What I recommend is to replace the code

if "Noto Color Emoji" in subprocess.run(["fc-list"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True).stdout:
			return True

which resides inside a try-except block with:

result = subprocess.run(
		["fc-list", ":charset=1F480"],  # 1F480 = Skull emoji
		stdout=subprocess.PIPE,
		stderr=subprocess.PIPE,
		text=True
	)
	return bool(result.stdout.strip())

Also notice that I replaced the smile emoji with the skull emoji because the smile is present on most fonts but not the ones I use.

brightio avatar Jul 19 '25 07:07 brightio