added image previews using ueberzug
This commit is contained in:
@@ -3,8 +3,14 @@
|
||||
#include <string.h>
|
||||
#include "defines.h"
|
||||
|
||||
static FILE *ueberzug = NULL;
|
||||
extern unsigned int terminal_height;
|
||||
extern unsigned int terminal_width;
|
||||
char previewd;
|
||||
|
||||
char* text(char *path, unsigned long *file_size);
|
||||
void images_print(char *file_name);
|
||||
void images_clear();
|
||||
char* generic(char *path);
|
||||
|
||||
char* get_mimetype(char *path){
|
||||
@@ -43,6 +49,14 @@ char* preview_file(char *file_name, unsigned long file_size){
|
||||
} else {
|
||||
file_buffer = generic(file_name);
|
||||
}
|
||||
|
||||
if (strstr(mime, "image")) {
|
||||
images_print(file_name);
|
||||
previewd = 1;
|
||||
} else {
|
||||
images_clear();
|
||||
}
|
||||
|
||||
free(mime);
|
||||
return file_buffer;
|
||||
|
||||
@@ -58,6 +72,28 @@ char* text(char *path, unsigned long *file_size){
|
||||
return "failed reading file";
|
||||
}
|
||||
}
|
||||
void images_clear() {
|
||||
if (previewd == 1) {
|
||||
fprintf(ueberzug, "{\"action\": \"remove\", \
|
||||
\"identifier\": \"preview\"}\n");
|
||||
fflush(ueberzug);
|
||||
previewd = 0;
|
||||
}
|
||||
}
|
||||
void images_print(char *file_name) {
|
||||
char *path=getcwd(NULL, 0);
|
||||
fprintf(ueberzug, "{\"action\": \"remove\", \
|
||||
\"identifier\": \"preview\"}\n");
|
||||
fprintf(ueberzug, "{\"action\":\"add\", \
|
||||
\"identifier\":\"preview\", \
|
||||
\"max_height\":%d, \
|
||||
\"max_width\":%d, \
|
||||
\"y\":0, \
|
||||
\"x\":%d, \
|
||||
\"path\":\"%s/%s\"}\n", terminal_height, terminal_width/2, terminal_width/2, path, file_name);
|
||||
fflush(ueberzug);
|
||||
free(path);
|
||||
}
|
||||
char* generic(char *path){
|
||||
char *cmd = concat("file ./\"", path);
|
||||
cmd = concat(cmd, "\"");
|
||||
@@ -73,3 +109,6 @@ char* generic(char *path){
|
||||
return "failed executing shell command \"file\"";
|
||||
}
|
||||
}
|
||||
void ueberzug_init(){
|
||||
ueberzug = popen("ueberzug layer -s ", "w");
|
||||
}
|
||||
|
@@ -1,5 +1,10 @@
|
||||
#include "file_previews.c"
|
||||
#include "defines.h"
|
||||
#ifndef PREVIEW_GUARD
|
||||
#define PREVIEW_GUARD
|
||||
#include "file_previews.c"
|
||||
#endif
|
||||
|
||||
char* preview_file(char *file_name, unsigned long file_size);
|
||||
char* get_mimetype(char *path);
|
||||
void images_clear();
|
||||
void ueberzug_init();
|
||||
|
5
main.c
5
main.c
@@ -10,6 +10,7 @@
|
||||
#include "defines.h"
|
||||
#include "colors.h"
|
||||
#include "interactions.h"
|
||||
#include "file_previews.h"
|
||||
|
||||
unsigned int terminal_height;
|
||||
unsigned int terminal_width;
|
||||
@@ -188,7 +189,9 @@ void init() {
|
||||
}
|
||||
|
||||
threading_init(); /* found in threading.c */
|
||||
colors_init();
|
||||
colors_init(); /* in colors.c */
|
||||
ueberzug_init(); /* in file_previews.c */
|
||||
|
||||
ESCDELAY = 10;
|
||||
char *start_path = getcwd(NULL, 0);
|
||||
setenv("START_PATH", start_path, 0);
|
||||
|
@@ -180,6 +180,7 @@ void *thread_rgt(void *data){
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
|
||||
if (file_current_type == FILE_TYPE_DIR || file_current_type == FILE_TYPE_SYMLINK) {
|
||||
images_clear();
|
||||
|
||||
unsigned long i = 0;
|
||||
for (i = 0; i < rgt_file_count; i++) {
|
||||
|
Reference in New Issue
Block a user