From 5b6e3333665c7efd4a4a2be30305a5175436bc9e Mon Sep 17 00:00:00 2001 From: Nikita Ivanov Date: Tue, 21 Jun 2022 02:06:49 +0500 Subject: [PATCH] Add noimages option --- doc/ctpv.1 | 4 ++++ sh/helpers.sh | 7 +++++++ src/config.c | 1 + src/ctpv.h | 2 +- src/shell.c | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/ctpv.1 b/doc/ctpv.1 index 81fbbda..5641486 100644 --- a/doc/ctpv.1 +++ b/doc/ctpv.1 @@ -268,6 +268,10 @@ Always use .I Kitty terminal's built-in method of previewing images. . +.TP +.B noimages +Print only text and do not use any image previewing method. +. .SS Defining custom previews . A snippet below defines a new preview with name diff --git a/sh/helpers.sh b/sh/helpers.sh index 0fe69ca..a8fa7e2 100644 --- a/sh/helpers.sh +++ b/sh/helpers.sh @@ -15,6 +15,10 @@ use_kitty() { is_kitty } +noimages() { + [ -n "$noimages" ] +} + fifo_open() { # https://unix.stackexchange.com/a/522940/183147 dd oflag=nonblock conv=notrunc,nocreat count=0 of="$1" \ @@ -39,6 +43,8 @@ check_exists() { } send_image() { + noimages && return 127 + if use_kitty; then kitty +kitten icat --transfer-mode file --align left \ --place "${w}x${h}@${x}x${y}" "$1" @@ -53,6 +59,7 @@ send_image() { } convert_and_show_image() { + noimages && exit 127 setup_fifo [ -n "$cache_valid" ] || "$@" || exit "$?" send_image "$cache_f" diff --git a/src/config.c b/src/config.c index 844f0d0..ee763d3 100644 --- a/src/config.c +++ b/src/config.c @@ -42,6 +42,7 @@ static VectorPreview *previews; static struct Option options[] = { { "forcekitty", OPTION_BOOL, { .i = &ctpv.opts.forcekitty } }, + { "noimages", OPTION_BOOL, { .i = &ctpv.opts.noimages } }, }; static void any_type_null(char **s) diff --git a/src/ctpv.h b/src/ctpv.h index d490dbd..f5612c1 100644 --- a/src/ctpv.h +++ b/src/ctpv.h @@ -14,7 +14,7 @@ struct CTPV { } mode; char *server_id_s; struct { - int forcekitty; + int forcekitty, noimages; } opts; }; diff --git a/src/shell.c b/src/shell.c index 5ab8c5b..6c12ea9 100644 --- a/src/shell.c +++ b/src/shell.c @@ -35,6 +35,7 @@ int run_script(char *script, size_t script_len, int *exitcode, int *signal, SpawnProg sp, void *sp_arg) { ERRCHK_RET_ERN(setenv("forcekitty", ctpv.opts.forcekitty ? "1" : "", 1) == -1); + ERRCHK_RET_ERN(setenv("noimages", ctpv.opts.noimages ? "1" : "", 1) == -1); char *scr = prepend_helpers(script, script_len); char *args[] = SHELL_ARGS(scr);