mirror of
https://gittea.dev/nova/th.git
synced 2025-10-21 18:30:15 -04:00
image previews can now be disabled
This commit is contained in:
1
config.h
1
config.h
@@ -1,4 +1,5 @@
|
|||||||
#define SETTINGS_LINE_NUMBERS 2 /* 0 is disabled, 1 is enabled, 2 is relative */
|
#define SETTINGS_LINE_NUMBERS 2 /* 0 is disabled, 1 is enabled, 2 is relative */
|
||||||
|
#define SETTINGS_UEBERZUG_IMAGE_PREVIEW 1 /* 0 is disabled, 1 is enabled, 2 is with caching */
|
||||||
|
|
||||||
/* {{{ */
|
/* {{{ */
|
||||||
#ifndef CONFIG_GUARD
|
#ifndef CONFIG_GUARD
|
||||||
|
@@ -1,9 +1,14 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "backend.h"
|
|
||||||
|
|
||||||
|
#include "backend.h"
|
||||||
|
#include "defines.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
static FILE *ueberzug = NULL;
|
static FILE *ueberzug = NULL;
|
||||||
|
#endif
|
||||||
extern unsigned int terminal_height;
|
extern unsigned int terminal_height;
|
||||||
extern unsigned int terminal_width;
|
extern unsigned int terminal_width;
|
||||||
char previewd;
|
char previewd;
|
||||||
@@ -43,14 +48,19 @@ char* preview_file(char *file_name, unsigned long file_size){
|
|||||||
|
|
||||||
|
|
||||||
char *mime = get_mimetype(file_name);
|
char *mime = get_mimetype(file_name);
|
||||||
|
|
||||||
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
images_clear();
|
images_clear();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (strstr(mime, "text")) {
|
if (strstr(mime, "text")) {
|
||||||
file_buffer = text(file_name, &file_size);
|
file_buffer = text(file_name, &file_size);
|
||||||
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
} else if (strstr(mime, "image")) {
|
} else if (strstr(mime, "image")) {
|
||||||
file_buffer = generic(file_name);
|
file_buffer = generic(file_name);
|
||||||
images_print(file_name);
|
images_print(file_name);
|
||||||
previewd = 1;
|
previewd = 1;
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
file_buffer = generic(file_name);
|
file_buffer = generic(file_name);
|
||||||
}
|
}
|
||||||
@@ -74,28 +84,6 @@ char* text(char *path, unsigned long *file_size){
|
|||||||
return "failed reading file";
|
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* generic(char *path){
|
||||||
char *cmd = concat("file ./\"", path);
|
char *cmd = concat("file ./\"", path);
|
||||||
cmd = concat(cmd, "\"");
|
cmd = concat(cmd, "\"");
|
||||||
@@ -111,6 +99,34 @@ char* generic(char *path){
|
|||||||
return "failed executing shell command \"file\"";
|
return "failed executing shell command \"file\"";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ueberzug_init(){
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
ueberzug = popen("ueberzug layer -s ", "w");
|
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\":\"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);
|
||||||
|
}
|
||||||
|
void ueberzug_init(){
|
||||||
|
|
||||||
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW == 2
|
||||||
|
ueberzug = popen("ueberzug layer -s ", "w");
|
||||||
|
#elif SETTINGS_UEBERZUG_IMAGE_PREVIEW == 1
|
||||||
|
ueberzug = popen("ueberzug layer -s --no-cache ", "w");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
4
main.c
4
main.c
@@ -183,8 +183,10 @@ void init() {
|
|||||||
|
|
||||||
threading_init(); /* found in threading.c */
|
threading_init(); /* found in threading.c */
|
||||||
colors_init(); /* in colors.c */
|
colors_init(); /* in colors.c */
|
||||||
ueberzug_init(); /* in file_previews.c */
|
|
||||||
dir_init(); /*in dir.c */
|
dir_init(); /*in dir.c */
|
||||||
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
|
ueberzug_init(); /* in file_previews.c */
|
||||||
|
#endif
|
||||||
|
|
||||||
ESCDELAY = 10;
|
ESCDELAY = 10;
|
||||||
char *start_path = getcwd(NULL, 0);
|
char *start_path = getcwd(NULL, 0);
|
||||||
|
@@ -157,7 +157,6 @@ void *thread_rgt(){
|
|||||||
|
|
||||||
if (mid_content[selected_file_current].permissions & S_IRUSR) {
|
if (mid_content[selected_file_current].permissions & S_IRUSR) {
|
||||||
if (file_current.file_type == FILE_TYPE_DIR || file_current.file_type == FILE_TYPE_SYMLINK) {
|
if (file_current.file_type == FILE_TYPE_DIR || file_current.file_type == FILE_TYPE_SYMLINK) {
|
||||||
images_clear();
|
|
||||||
|
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
for (i = 0; i < rgt_file_count; i++) {
|
for (i = 0; i < rgt_file_count; i++) {
|
||||||
|
Reference in New Issue
Block a user