A
This commit is contained in:
parent
f3986f2acf
commit
0992128a5f
2 changed files with 65 additions and 84 deletions
4
Makefile
4
Makefile
|
@ -8,9 +8,7 @@ PREFIX ?= /usr/local
|
||||||
BINDIR = $(PREFIX)/bin
|
BINDIR = $(PREFIX)/bin
|
||||||
MANDIR = $(PREFIX)/share/man/man1
|
MANDIR = $(PREFIX)/share/man/man1
|
||||||
|
|
||||||
LDFLAGS != pkg-config --libs libsixel
|
CFLAGS = -Os -march=native -mtune=native -pipe -s -flto -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600
|
||||||
INCFLAGS != pkg-config --cflags libsixel
|
|
||||||
CFLAGS = -Os -march=native -mtune=native -pipe -s -flto -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 $(INCFLAGS)
|
|
||||||
|
|
||||||
SRC = ccc.c util.c file.c icons.c
|
SRC = ccc.c util.c file.c icons.c
|
||||||
|
|
||||||
|
|
17
ccc.c
17
ccc.c
|
@ -13,8 +13,6 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include <sixel.h>
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "icons.h"
|
#include "icons.h"
|
||||||
|
@ -872,7 +870,6 @@ void show_file_content(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strstr(current_file.name, ".jpg") == NULL && strstr(current_file.name, ".png") == NULL) {
|
|
||||||
int c;
|
int c;
|
||||||
/* Check if its binary */
|
/* Check if its binary */
|
||||||
while ((c = fgetc(file)) != EOF) {
|
while ((c = fgetc(file)) != EOF) {
|
||||||
|
@ -881,7 +878,6 @@ void show_file_content(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
int pipe_fd[2];
|
int pipe_fd[2];
|
||||||
if (pipe(pipe_fd) == -1) {
|
if (pipe(pipe_fd) == -1) {
|
||||||
perror("pipe");
|
perror("pipe");
|
||||||
|
@ -891,26 +887,14 @@ void show_file_content(void)
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
/* Child */
|
/* Child */
|
||||||
move_cursor(1, half_width);
|
move_cursor(1, half_width);
|
||||||
if (strstr(current_file.name, ".jpg") || strstr(current_file.name, ".png")) {
|
|
||||||
sixel_encoder_t *encoder = NULL;
|
|
||||||
sixel_encoder_new(&encoder, NULL);
|
|
||||||
/* Should be enough for most terminal */
|
|
||||||
char width[5];
|
|
||||||
snprintf(width, 5, "%d", (cols - half_width) * 6);
|
|
||||||
sixel_encoder_setopt(encoder, 'w', width);
|
|
||||||
sixel_encoder_encode(encoder, current_file.name);
|
|
||||||
sixel_encoder_unref(encoder);
|
|
||||||
} else {
|
|
||||||
close(pipe_fd[0]);
|
close(pipe_fd[0]);
|
||||||
dup2(pipe_fd[1], STDOUT_FILENO);
|
dup2(pipe_fd[1], STDOUT_FILENO);
|
||||||
dup2(pipe_fd[1], STDERR_FILENO);
|
dup2(pipe_fd[1], STDERR_FILENO);
|
||||||
close(pipe_fd[1]);
|
close(pipe_fd[1]);
|
||||||
execlp("vip", "vip", "-c", current_file.name, NULL);
|
execlp("vip", "vip", "-c", current_file.name, NULL);
|
||||||
}
|
|
||||||
_exit(1);
|
_exit(1);
|
||||||
} else if (pid > 0) {
|
} else if (pid > 0) {
|
||||||
/* Parent */
|
/* Parent */
|
||||||
if (!strstr(current_file.name, ".jpg") && !strstr(current_file.name, ".png")) {
|
|
||||||
close(pipe_fd[1]);
|
close(pipe_fd[1]);
|
||||||
char buffer[4096];
|
char buffer[4096];
|
||||||
int row = 1;
|
int row = 1;
|
||||||
|
@ -967,7 +951,6 @@ void show_file_content(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(stream);
|
fclose(stream);
|
||||||
}
|
|
||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
} else {
|
} else {
|
||||||
wpprintw("fork failed: %s", strerror(errno));
|
wpprintw("fork failed: %s", strerror(errno));
|
||||||
|
|
Loading…
Reference in a new issue