mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 17:41:41 +01:00
Image: expose more chafa settings
This commit is contained in:
@@ -140,6 +140,9 @@ static void defaultConfig(FFinstance* instance)
|
||||
|
||||
instance->config.logo.chafaFgOnly = false;
|
||||
ffStrbufInitS(&instance->config.logo.chafaSymbols, "block+border+space-wide-inverted"); // Chafa default
|
||||
instance->config.logo.chafaCanvasMode = UINT32_MAX;
|
||||
instance->config.logo.chafaColorSpace = UINT32_MAX;
|
||||
instance->config.logo.chafaDitherMode = UINT32_MAX;
|
||||
|
||||
ffStrbufInit(&instance->config.colorKeys);
|
||||
ffStrbufInit(&instance->config.colorTitle);
|
||||
|
||||
@@ -43,6 +43,9 @@
|
||||
#define FF_LIBRARY_LOAD_SYMBOL(library, symbolName, returnValue) \
|
||||
__typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, ff ## symbolName, symbolName, returnValue);
|
||||
|
||||
#define FF_LIBRARY_LOAD_SYMBOL_LAZY(library, symbolName) \
|
||||
__typeof__(&symbolName) ff ## symbolName = dlsym(library, #symbolName);
|
||||
|
||||
#define FF_LIBRARY_LOAD_SYMBOL_MESSAGE(library, symbolName) \
|
||||
__typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, ff ## symbolName, symbolName, "dlsym " #symbolName " failed");
|
||||
|
||||
|
||||
+4
-1
@@ -38,8 +38,11 @@ Logo options:
|
||||
--sixel <file>: Short for --logo-type sixel --logo <file>
|
||||
--kitty <file>: Short for --logo-type kitty --logo <file>
|
||||
--chafa <file>: Short for --logo-type chafa --logo <file>
|
||||
--chafa-symbols <str>: Specify character symbols to employ in final output. See chafa document for detail
|
||||
--chafa-fg-only <?value>: Produce character-cell output using foreground colors only. See chafa document for detail
|
||||
--chafa-symbols <str>: Specify character symbols to employ in final output. See chafa document for detail
|
||||
--chafa-canvas-mode <value>: Determine how colors are used in the output. This value maps the int value of enum ChafaCanvasMode. See chafa document for detail
|
||||
--chafa-color-space <value>: Set color space used for quantization. 0 for RGB; 1 for DIN99d. See chafa document for detail
|
||||
--chafa-dither-mode <value>: Set output dither mode (No effect with 24-bit color). This value maps the int value of enum ChafaDitherMode. See chafa document for detail
|
||||
|
||||
Display options:
|
||||
-s,--structure <structure>: Set the structure of the fetch. Must be a colon separated list of keys. Use "fastfetch --list-modules" to see the ones available.
|
||||
|
||||
+6
-4
@@ -1018,13 +1018,15 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
instance->config.logo.type = FF_LOGO_TYPE_IMAGE_CHAFA;
|
||||
}
|
||||
else if(strcasecmp(key, "--chafa-fg-only") == 0)
|
||||
{
|
||||
instance->config.logo.chafaFgOnly = optionParseBoolean(value);
|
||||
}
|
||||
else if(strcasecmp(key, "--chafa-symbols") == 0)
|
||||
{
|
||||
optionParseString(key, value, &instance->config.logo.chafaSymbols);
|
||||
}
|
||||
else if(strcasecmp(key, "--chafa-canvas-mode") == 0)
|
||||
instance->config.logo.chafaCanvasMode = optionParseUInt32(key, value);
|
||||
else if(strcasecmp(key, "--chafa-color-space") == 0)
|
||||
instance->config.logo.chafaColorSpace = optionParseUInt32(key, value);
|
||||
else if(strcasecmp(key, "--chafa-dither-mode") == 0)
|
||||
instance->config.logo.chafaDitherMode = optionParseUInt32(key, value);
|
||||
|
||||
///////////////////
|
||||
//Display options//
|
||||
|
||||
@@ -78,6 +78,9 @@ typedef struct FFconfig
|
||||
|
||||
bool chafaFgOnly;
|
||||
FFstrbuf chafaSymbols;
|
||||
uint32_t chafaCanvasMode;
|
||||
uint32_t chafaColorSpace;
|
||||
uint32_t chafaDitherMode;
|
||||
} logo;
|
||||
|
||||
//If one of those is empty, ffLogoPrint will set them
|
||||
|
||||
+35
-17
@@ -240,9 +240,6 @@ static bool printImageChafa(FFinstance* instance, FFLogoRequestData* requestData
|
||||
FF_LIBRARY_LOAD_SYMBOL(chafa, chafa_canvas_config_new, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL(chafa, chafa_canvas_config_set_geometry, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL(chafa, chafa_canvas_config_set_symbol_map, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL(chafa, chafa_canvas_config_set_color_space, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL(chafa, chafa_canvas_config_set_canvas_mode, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL(chafa, chafa_canvas_config_set_fg_only_enabled, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL(chafa, chafa_canvas_new, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL(chafa, chafa_canvas_draw_all_pixels, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL(chafa, chafa_canvas_print, false)
|
||||
@@ -250,12 +247,6 @@ static bool printImageChafa(FFinstance* instance, FFLogoRequestData* requestData
|
||||
FF_LIBRARY_LOAD_SYMBOL(chafa, chafa_canvas_config_unref, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL(chafa, chafa_symbol_map_unref, false)
|
||||
|
||||
#ifndef _WIN32
|
||||
// FIXME: These functions must be imported from `libglib` dlls. Leak them for now
|
||||
FF_LIBRARY_LOAD_SYMBOL(chafa, g_string_free, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL(chafa, g_error_free, false)
|
||||
#endif
|
||||
|
||||
imageData->ffCopyMagickString(imageData->imageInfo->magick, "RGBA", 5);
|
||||
size_t length;
|
||||
void* blob = imageData->ffImageToBlob(imageData->imageInfo, imageData->image, &length, imageData->exceptionInfo);
|
||||
@@ -273,10 +264,31 @@ static bool printImageChafa(FFinstance* instance, FFLogoRequestData* requestData
|
||||
ChafaCanvasConfig* canvasConfig = ffchafa_canvas_config_new();
|
||||
ffchafa_canvas_config_set_geometry(canvasConfig, (gint) requestData->logoCharacterWidth, (gint) requestData->logoCharacterHeight);
|
||||
ffchafa_canvas_config_set_symbol_map(canvasConfig, symbolMap);
|
||||
ffchafa_canvas_config_set_color_space(canvasConfig, CHAFA_COLOR_SPACE_DIN99D);
|
||||
ffchafa_canvas_config_set_canvas_mode(canvasConfig, CHAFA_CANVAS_MODE_TRUECOLOR);
|
||||
// ffchafa_canvas_config_set_fg_only_enabled(canvasConfig, instance->config.logo.chafaFgOnly);
|
||||
// TODO: expose more chafa configs to fastfetch flags
|
||||
|
||||
if(instance->config.logo.chafaFgOnly)
|
||||
{
|
||||
FF_LIBRARY_LOAD_SYMBOL_LAZY(chafa, chafa_canvas_config_set_fg_only_enabled);
|
||||
if(ffchafa_canvas_config_set_fg_only_enabled)
|
||||
ffchafa_canvas_config_set_fg_only_enabled(canvasConfig, true);
|
||||
}
|
||||
if(instance->config.logo.chafaCanvasMode < CHAFA_CANVAS_MODE_MAX)
|
||||
{
|
||||
FF_LIBRARY_LOAD_SYMBOL_LAZY(chafa, chafa_canvas_config_set_canvas_mode);
|
||||
if(ffchafa_canvas_config_set_canvas_mode)
|
||||
ffchafa_canvas_config_set_canvas_mode(canvasConfig, (ChafaCanvasMode) instance->config.logo.chafaCanvasMode);
|
||||
}
|
||||
if(instance->config.logo.chafaColorSpace < CHAFA_COLOR_SPACE_MAX)
|
||||
{
|
||||
FF_LIBRARY_LOAD_SYMBOL_LAZY(chafa, chafa_canvas_config_set_color_space)
|
||||
if(ffchafa_canvas_config_set_color_space)
|
||||
ffchafa_canvas_config_set_color_space(canvasConfig, (ChafaColorSpace) instance->config.logo.chafaColorSpace);
|
||||
}
|
||||
if(instance->config.logo.chafaDitherMode < CHAFA_DITHER_MODE_MAX)
|
||||
{
|
||||
FF_LIBRARY_LOAD_SYMBOL_LAZY(chafa, chafa_canvas_config_set_dither_mode)
|
||||
if(ffchafa_canvas_config_set_dither_mode)
|
||||
ffchafa_canvas_config_set_dither_mode(canvasConfig, (ChafaDitherMode) instance->config.logo.chafaDitherMode);
|
||||
}
|
||||
|
||||
ChafaCanvas* canvas = ffchafa_canvas_new(canvasConfig);
|
||||
ffchafa_canvas_draw_all_pixels(
|
||||
@@ -297,10 +309,16 @@ static bool printImageChafa(FFinstance* instance, FFLogoRequestData* requestData
|
||||
ffLogoPrintChars(instance, result.chars, false);
|
||||
writeCacheStrbuf(requestData, &result, FF_CACHE_FILE_CHAFA);
|
||||
|
||||
#ifndef _WIN32
|
||||
ffg_string_free(str, TRUE);
|
||||
ffg_error_free(error);
|
||||
#endif
|
||||
// FIXME: These functions must be imported from `libglib` dlls on Windows
|
||||
FF_LIBRARY_LOAD_SYMBOL_LAZY(chafa, g_string_free);
|
||||
if(ffg_string_free)
|
||||
ffg_string_free(str, TRUE);
|
||||
if(error)
|
||||
{
|
||||
FF_LIBRARY_LOAD_SYMBOL_LAZY(chafa, g_error_free)
|
||||
if(ffg_error_free)
|
||||
ffg_error_free(error);
|
||||
}
|
||||
|
||||
ffchafa_canvas_unref(canvas);
|
||||
ffchafa_canvas_config_unref(canvasConfig);
|
||||
|
||||
Reference in New Issue
Block a user