From 08095635bc879115cfd47f48204817ab2868127a Mon Sep 17 00:00:00 2001 From: Nikita Ivanov Date: Wed, 23 Nov 2022 23:01:23 +0100 Subject: [PATCH] A better way to fix chafa and foot issue --- doc/ctpv.1 | 24 ++++++++++++++++++++++++ sh/helpers.sh | 7 ++++++- src/config.c | 1 + src/ctpv.h | 2 +- src/shell.c | 1 + 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/doc/ctpv.1 b/doc/ctpv.1 index 90d2757..f092e60 100644 --- a/doc/ctpv.1 +++ b/doc/ctpv.1 @@ -312,6 +312,30 @@ Print only text and do not use any image previewing method. Do not print resolved path of symbolic links. . .TP +.B autochafa +By default, +.I Chafa +is always forced to use \(lqsymbols\(rq format because +.I lf +does not support +\(lqsixel\(rq output in the preview window. +However, one could install a +.UR https://github.com/horriblename/lf +fork of +.I lf +.UE +that does. +For such cases the +.B autochafa +option exists, which allows +.I Chafa +to decide which format to use. +Use it if you are sure that the version of +.I lf +you are using will be able to handle whatever output produced by +.IR Chafa . +. +.TP .B showgpg Preview .BR gpg (1) diff --git a/sh/helpers.sh b/sh/helpers.sh index e362136..3efd778 100644 --- a/sh/helpers.sh +++ b/sh/helpers.sh @@ -18,6 +18,10 @@ noimages() { [ -n "$noimages" ] } +autochafa() { + [ -z "$autochafa" ] +} + is_kitty() { case "$TERM" in *-kitty) return 0 ;; @@ -61,7 +65,8 @@ is_anim_image() { } chafa_run() { - chafa -s "${w}x${h}" -f symbols "$1" + autochafa && format='-f symbols' || format= + chafa -s "${w}x${h}" $format "$1" | sed 's/#/\n#/g' } setup_fifo() { diff --git a/src/config.c b/src/config.c index 40ff78a..37938e9 100644 --- a/src/config.c +++ b/src/config.c @@ -60,6 +60,7 @@ static struct Option options[] = { DEF_OPTION_BOOL(forcechafa), DEF_OPTION_BOOL(noimages), DEF_OPTION_BOOL(nosymlinkinfo), + DEF_OPTION_BOOL(autochafa), DEF_OPTION_BOOL(showgpg), }; diff --git a/src/ctpv.h b/src/ctpv.h index 589c25c..dbe1ad1 100644 --- a/src/ctpv.h +++ b/src/ctpv.h @@ -16,7 +16,7 @@ struct CTPV { char *server_id_s; struct { int forcekitty, forcekittyanim, forcechafa, noimages, nosymlinkinfo; - int showgpg; + int autochafa, showgpg; } opts; }; diff --git a/src/shell.c b/src/shell.c index 35986f8..01b7124 100644 --- a/src/shell.c +++ b/src/shell.c @@ -42,6 +42,7 @@ RESULT run_script(char *script, size_t script_len, int *exitcode, int *signal, OPT_SETENV(forcechafa); OPT_SETENV(noimages); OPT_SETENV(nosymlinkinfo); + OPT_SETENV(autochafa); OPT_SETENV(showgpg); char *scr = prepend_helpers(script, script_len);