Add noimages option

This commit is contained in:
Nikita Ivanov 2022-06-21 02:06:49 +05:00
parent 456a0eb4da
commit 5b6e333366
No known key found for this signature in database
GPG Key ID: 6E656AC5B97B5133
5 changed files with 14 additions and 1 deletions

View File

@ -268,6 +268,10 @@ Always use
.I Kitty .I Kitty
terminal's built-in method of previewing images. 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 .SS Defining custom previews
. .
A snippet below defines a new preview with name A snippet below defines a new preview with name

View File

@ -15,6 +15,10 @@ use_kitty() {
is_kitty is_kitty
} }
noimages() {
[ -n "$noimages" ]
}
fifo_open() { fifo_open() {
# https://unix.stackexchange.com/a/522940/183147 # https://unix.stackexchange.com/a/522940/183147
dd oflag=nonblock conv=notrunc,nocreat count=0 of="$1" \ dd oflag=nonblock conv=notrunc,nocreat count=0 of="$1" \
@ -39,6 +43,8 @@ check_exists() {
} }
send_image() { send_image() {
noimages && return 127
if use_kitty; then if use_kitty; then
kitty +kitten icat --transfer-mode file --align left \ kitty +kitten icat --transfer-mode file --align left \
--place "${w}x${h}@${x}x${y}" "$1" --place "${w}x${h}@${x}x${y}" "$1"
@ -53,6 +59,7 @@ send_image() {
} }
convert_and_show_image() { convert_and_show_image() {
noimages && exit 127
setup_fifo setup_fifo
[ -n "$cache_valid" ] || "$@" || exit "$?" [ -n "$cache_valid" ] || "$@" || exit "$?"
send_image "$cache_f" send_image "$cache_f"

View File

@ -42,6 +42,7 @@ static VectorPreview *previews;
static struct Option options[] = { static struct Option options[] = {
{ "forcekitty", OPTION_BOOL, { .i = &ctpv.opts.forcekitty } }, { "forcekitty", OPTION_BOOL, { .i = &ctpv.opts.forcekitty } },
{ "noimages", OPTION_BOOL, { .i = &ctpv.opts.noimages } },
}; };
static void any_type_null(char **s) static void any_type_null(char **s)

View File

@ -14,7 +14,7 @@ struct CTPV {
} mode; } mode;
char *server_id_s; char *server_id_s;
struct { struct {
int forcekitty; int forcekitty, noimages;
} opts; } opts;
}; };

View File

@ -35,6 +35,7 @@ int run_script(char *script, size_t script_len, int *exitcode, int *signal,
SpawnProg sp, void *sp_arg) SpawnProg sp, void *sp_arg)
{ {
ERRCHK_RET_ERN(setenv("forcekitty", ctpv.opts.forcekitty ? "1" : "", 1) == -1); 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 *scr = prepend_helpers(script, script_len);
char *args[] = SHELL_ARGS(scr); char *args[] = SHELL_ARGS(scr);