Skip to content

Commit 31c042f

Browse files
committed
* Compile out enable_inline_img ifndef USE_IMAGE
* Make auto-selection a true option for inline_img_protocol, with a separate variable for configuration
1 parent b1c4ae3 commit 31c042f

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

display.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -530,12 +530,14 @@ drawAnchorCursor0(Buffer *buf, AnchorList *al, int hseq, int prevhseq,
530530
int start_pos = an->start.pos;
531531
int end_pos = an->end.pos;
532532
for (i = an->start.pos; i < an->end.pos; i++) {
533-
if (enable_inline_image && (l->propBuf[i] & PE_IMAGE)) {
533+
#ifdef USE_IMAGE
534+
if (enable_inline_image && (l->propBuf[i] & PE_IMAGE)) {
534535
if (start_pos == i)
535536
start_pos = i + 1;
536537
else if (end_pos == an->end.pos)
537538
end_pos = i - 1;
538539
}
540+
#endif
539541
if (l->propBuf[i] & (PE_IMAGE | PE_ANCHOR | PE_FORM)) {
540542
if (active)
541543
l->propBuf[i] |= PE_ACTIVE;

fm.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,14 @@ extern int REV_LB[];
317317
#define EOL(l) (&(l)->ptr[(l)->length])
318318
#define IS_EOL(p,l) ((p)==&(l)->ptr[(l)->length])
319319

320+
#ifdef USE_IMAGE
321+
#define INLINE_IMG_AUTO -1
320322
#define INLINE_IMG_NONE 0
321323
#define INLINE_IMG_OSC5379 1
322324
#define INLINE_IMG_SIXEL 2
323325
#define INLINE_IMG_ITERM2 3
324326
#define INLINE_IMG_KITTY 4
327+
#endif
325328

326329
/*
327330
* Types.
@@ -940,7 +943,10 @@ global char *CurrentKeyData;
940943
global char *CurrentCmdData;
941944
global char *w3m_reqlog;
942945
extern char *w3m_version;
943-
extern signed char enable_inline_image;
946+
#ifdef USE_IMAGE
947+
global unsigned char enable_inline_image init(INLINE_IMG_NONE);
948+
global signed char enable_inline_image_config init(INLINE_IMG_AUTO);
949+
#endif
944950

945951
#define DUMP_BUFFER 0x01
946952
#define DUMP_HEAD 0x02

image.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ static int inline_img_protocol_autodetect(void);
4444
void
4545
initImage()
4646
{
47-
/* This must be checked first and always, since the rest of this module
48-
* tests this variable as a boolean, so will get a likely false
49-
* positive */
50-
if (enable_inline_image == -1)
51-
enable_inline_image = inline_img_protocol_autodetect();
47+
enable_inline_image = enable_inline_image_config == INLINE_IMG_AUTO
48+
? inline_img_protocol_autodetect()
49+
: enable_inline_image_config;
5250

5351
if (activeImage)
5452
return;
@@ -178,11 +176,11 @@ have_img2sixel(void)
178176
int wstatus;
179177

180178
if (getenv("W3M_IMG2SIXEL"))
181-
return 1;
179+
return TRUE;
182180

183181
switch (child_pid = fork()) {
184182
case -1:
185-
return 0;
183+
return FALSE;
186184
case 0:
187185
close(STDOUT_FILENO);
188186
close(STDERR_FILENO);

main.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ static int searchKeyNum(void);
127127
#define help() fusage(stdout, 0)
128128
#define usage() fusage(stderr, 1)
129129

130-
signed char enable_inline_image = -1;
131-
132130
static void
133131
fversion(FILE * f)
134132
{
@@ -719,13 +717,13 @@ main(int argc, char **argv)
719717
set_pixel_per_line = TRUE;
720718
}
721719
}
722-
#endif
723720
else if (!strcmp("-ri", argv[i])) {
724721
enable_inline_image = INLINE_IMG_OSC5379;
725722
}
726723
else if (!strcmp("-sixel", argv[i])) {
727724
enable_inline_image = INLINE_IMG_SIXEL;
728725
}
726+
#endif
729727
else if (!strcmp("-num", argv[i]))
730728
showLineNum = TRUE;
731729
else if (!strcmp("-no-proxy", argv[i]))
@@ -6006,11 +6004,13 @@ deleteFiles()
60066004
}
60076005
while ((f = popText(fileToDelete)) != NULL) {
60086006
unlink(f);
6007+
#ifdef USE_IMAGE
60096008
if (enable_inline_image == INLINE_IMG_SIXEL && strcmp(f+strlen(f)-4, ".gif") == 0) {
60106009
Str firstframe = Strnew_charp(f);
60116010
Strcat_charp(firstframe, "-1");
60126011
unlink(firstframe->ptr);
60136012
}
6013+
#endif
60146014
}
60156015
}
60166016

rc.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ static struct sel_c graphic_char_str[] = {
377377

378378
#ifdef USE_IMAGE
379379
static struct sel_c inlineimgstr[] = {
380+
{N_S(INLINE_IMG_AUTO), N_("auto-select protocol")},
380381
{N_S(INLINE_IMG_NONE), N_("external command")},
381382
{N_S(INLINE_IMG_OSC5379), N_("OSC 5379 (mlterm)")},
382383
{N_S(INLINE_IMG_SIXEL), N_("sixel (img2sixel)")},
@@ -449,7 +450,7 @@ struct param_ptr params1[] = {
449450
CMT_EXT_IMAGE_VIEWER, NULL},
450451
{"image_scale", P_SCALE, PI_TEXT, (void *)&image_scale, CMT_IMAGE_SCALE,
451452
NULL},
452-
{"inline_img_protocol", P_CHARINT, PI_SEL_C, (void *)&enable_inline_image,
453+
{"inline_img_protocol", P_CHARINT, PI_SEL_C, (void *)&enable_inline_image_config,
453454
CMT_INLINE_IMG_PROTOCOL, (void *)inlineimgstr},
454455
{"imgdisplay", P_STRING, PI_TEXT, (void *)&Imgdisplay, CMT_IMGDISPLAY,
455456
NULL},
@@ -1313,7 +1314,7 @@ sync_with_option(void)
13131314
init_migemo();
13141315
#endif
13151316
#ifdef USE_IMAGE
1316-
if (fmInitialized && (displayImage || enable_inline_image))
1317+
if (fmInitialized && (displayImage || enable_inline_image_config))
13171318
initImage();
13181319
#else
13191320
displayImage = FALSE; /* XXX */

0 commit comments

Comments
 (0)