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
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

View File

@ -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"

View File

@ -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)

View File

@ -14,7 +14,7 @@ struct CTPV {
} mode;
char *server_id_s;
struct {
int forcekitty;
int forcekitty, noimages;
} 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)
{
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);