Compare commits

...
2 Commits
Author SHA1 Message Date
nova e876aa9899 readme 2026-06-19 00:16:52 +02:00
nova 1889eaad6f now depending on libmagic 2026-06-19 00:06:07 +02:00
5 changed files with 61 additions and 42 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
CC := gcc
CFLAGS := -Wall -Wextra -O3 -flto=auto
CFLAGS := -Wall -Wextra -O3 -flto=auto -lmagic
CURSES := $(shell pkg-config --libs ncursesw)
CFLAGS_DEBUG := $(CFLAGS) -ggdb
CFLAGS_PROFILE := $(CFLAGS) -pg
+28
View File
@@ -1,2 +1,30 @@
# th
~~~text
/home/toaster/src/desktop/c/th/README.md
th 15 backend.c 3.22 K # th
14 backend.h 253 B a filemanager born from spite
13 colors.c 3.54 K
12 colors.h 41 B qwert* user should adjust
11 config.h 8.07 K bindings in config.h, lol
10 defines.h 2.82 K
9 dir.c 11.05 K dependencies:
8 dir.h 367 B libc
7 file_prev~.c 2.68 K a c compiler
6 file_previ~.h 297 B make
5 interact~.c 17.79 K ncurses
4 interactio~.h 900 B pthreads
3 LICENSE 33.76 K libmagic
2 main.c 5.00 K ueberzugpp (optional)
1 Makefile 709 B stuff in config.h
15 README.md 1.14 K
1 sorting.c 5.62 K note:
2 sorting.h 633 B th does as little checking
3 string.h 2.39 K as possible; it is highly
4 threadin~.c 14.11 K insecure.
5 threading.h 246 B example: if you dont have
ueberzugpp installed,
and hover a picture without
disabling it in config.h,
th just crashes
-rw-r--r-- 176.03K sum of dir, 23.89G total free
+29 -40
View File
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <magic.h>
#include "backend.h"
#include "defines.h"
@@ -12,6 +13,8 @@ static FILE *ueberzug = NULL;
extern unsigned int terminal_height;
extern unsigned int terminal_width;
char previewd;
magic_t cookie_type;
magic_t cookie_description;
char* text(file *f);
void images_print(char *file_name);
@@ -19,24 +22,11 @@ void images_clear();
char* generic(file *f);
char* get_mimetype(file *f){
static const char *cmd_str = "file --mime-type -b";
char *cmd = parse_cmd(cmd_str, f);
char *mime = (char*)magic_file(cookie_type, f->file_name);
FILE *cmd_open = popen(cmd, "r");
char *line = NULL;
size_t size = 0;
free(cmd);
if (getline(&line, &size, cmd_open) != -1){
pclose(cmd_open);
return line;
} else {
pclose(cmd_open);
return "unknown";
}
return mime;
}
char* preview_file(file *f){
/* this calls "file" on path */
char *file_buffer;
@@ -46,19 +36,23 @@ char* preview_file(file *f){
images_clear();
#endif
if (strstr(mime, "text")) {
file_buffer = text(f);
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
} else if (strstr(mime, "image")) {
file_buffer = generic(f);
images_print(f->file_name);
previewd = 1;
#endif
} else {
if (mime != NULL) {
if (strstr(mime, "text")) {
file_buffer = text(f);
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
} else if (strstr(mime, "image")) {
file_buffer = generic(f);
images_print(f->file_name);
previewd = 1;
#endif
} else {
file_buffer = generic(f);
}
} else {
file_buffer = generic(f);
}
free(mime);
/*free(mime); seems like magic_file handles the free too*/
return file_buffer;
}
@@ -80,21 +74,11 @@ char* text(file *f){
}
}
char* generic(file *f){
static const char *cmd_str = "file";
char *cmd = parse_cmd(cmd_str, f);
char *mime = (char*)magic_file(cookie_description, f->file_name);
char *buffer = malloc(strlen(mime)+1);
memcpy(buffer, mime, strlen(mime)+1);
return buffer;
FILE *cmd_open = popen(cmd, "r");
char *line = NULL;
size_t size = 0;
free(cmd);
if (getline(&line, &size, cmd_open) != -1) {
pclose(cmd_open);
return line;
} else {
pclose(cmd_open);
return "failed executing shell command \"file\"";
}
}
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
void images_clear(){
@@ -119,13 +103,18 @@ void images_print(char *file_name){
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
}
void file_preview_init(){
cookie_type = magic_open(MAGIC_MIME_TYPE);
cookie_description = magic_open(MAGIC_NONE);
magic_load(cookie_type, NULL);
magic_load(cookie_description, NULL);
}
void ueberzug_close(){
images_clear();
pclose(ueberzug);
+2 -1
View File
@@ -7,7 +7,8 @@
char* preview_file(file *f);
char* get_mimetype(file *f);
void images_clear();
void ueberzug_init();
void file_preview_init();
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
void ueberzug_init();
void ueberzug_close();
#endif
+1
View File
@@ -177,6 +177,7 @@ void init() {
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
ueberzug_init(); /* in file_previews.c */
#endif
file_preview_init();
ESCDELAY = 10;
global_path = getcwd(NULL, 0);