mirror of
https://gittea.dev/nova/th.git
synced 2025-10-21 10:20:15 -04:00
Compare commits
5 Commits
d3e46846cd
...
4d9dc46691
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4d9dc46691 | ||
![]() |
8dcf88baea | ||
![]() |
8839f737c5 | ||
![]() |
36012b1a71 | ||
![]() |
4784ec3f64 |
5
config.h
5
config.h
@@ -44,6 +44,7 @@ static const binding key_binding[] = {
|
||||
/* blackmagic holds a modifier of an action, either as string or as function pointer depending on the action */
|
||||
{ "q", quit_program, NULL, "quit" },
|
||||
{ " ", toggle_selection, NULL, "toggle file selection" }, /* on hovered file/directory */
|
||||
{ "v", select_all, NULL, "select all files in dir" },
|
||||
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
|
||||
{ "B", enter_shell, "$SHELL", "enter $SHELL shell" },
|
||||
{ "/", search, NULL, "search" },
|
||||
@@ -59,6 +60,8 @@ static const binding key_binding[] = {
|
||||
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
|
||||
{ "dD", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory
|
||||
* this means that it does not delete the hovered files if files are already selected */
|
||||
{ "yn", yank_text, "name", "yank filename of hovered file" },
|
||||
{ "yp", yank_text, "path", "yank path of hovered file" },
|
||||
{ "yy", yank_file, "copy", "copy/yank file/directory" },
|
||||
{ "dd", yank_file, "cut", "cut file/directory" },
|
||||
{ "pp", paste, NULL, "paste" },
|
||||
@@ -100,6 +103,7 @@ static const binding key_binding[] = {
|
||||
|
||||
static const char size_unit[] = { 'B', 'K', 'M', 'G', 'T', 'P' }; /* this defines the maximum size unit, deleting everything except B results in all sizes being displayed in byte */
|
||||
|
||||
static const char clipboard_cmd[] = "xsel -ib --trim"; /* assembles the following shell cmd: echo "hovered_file" | clipboard_cmd */
|
||||
static const char ui_btm_text_storage_left[] = "total free";
|
||||
static const char ui_btm_current_dir_size[] = "sum of dir";
|
||||
|
||||
@@ -109,6 +113,7 @@ static const unsigned long mimetype_default_count = sizeof(mimetype_default_cmd)
|
||||
static const unsigned long file_extension_default_count = sizeof(file_extension_default_cmd) / sizeof(extension);
|
||||
static const char size_unit_count = (sizeof(size_unit) / sizeof(size_unit[0])) - 1;
|
||||
#else
|
||||
static const char clipboard_cmd[];
|
||||
static const mimetype mimetype_default_cmd[];
|
||||
static const extension file_extension_default_cmd[];
|
||||
static const binding key_binding[];
|
||||
|
@@ -100,7 +100,7 @@ char* generic(char *path){
|
||||
}
|
||||
}
|
||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||
void images_clear() {
|
||||
void images_clear(){
|
||||
if (previewd == 1) {
|
||||
fprintf(ueberzug, "{\"action\": \"remove\", \
|
||||
\"identifier\": \"preview\"}\n");
|
||||
@@ -108,7 +108,7 @@ void images_clear() {
|
||||
previewd = 0;
|
||||
}
|
||||
}
|
||||
void images_print(char *file_name) {
|
||||
void images_print(char *file_name){
|
||||
char *path=getcwd(NULL, 0);
|
||||
|
||||
fprintf(ueberzug, "{\"action\":\"add\", \
|
||||
@@ -129,4 +129,8 @@ void ueberzug_init(){
|
||||
ueberzug = popen("ueberzug layer -s --no-cache ", "w");
|
||||
#endif
|
||||
}
|
||||
void ueberzug_close(){
|
||||
images_clear();
|
||||
pclose(ueberzug);
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,9 +1,13 @@
|
||||
#ifndef PREVIEW_GUARD
|
||||
#define PREVIEW_GUARD
|
||||
#include "file_previews.c"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
char* preview_file(char *file_name, unsigned long file_size);
|
||||
char* get_mimetype(char *path);
|
||||
void images_clear();
|
||||
void ueberzug_init();
|
||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||
void ueberzug_close();
|
||||
#endif
|
||||
|
@@ -194,6 +194,16 @@ void toggle_selection(){
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
}
|
||||
void select_all(){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
unsigned long i;
|
||||
for(i = 0; i < mid_file_count; i++) {
|
||||
mid_content[i].status ^= FILE_STATUS_SELECTED;
|
||||
}
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
}
|
||||
void move_down(int passes){
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
if (passes == 0) {
|
||||
@@ -343,6 +353,10 @@ void open_with(){
|
||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
||||
cmd = concat(cmd, "\"");
|
||||
|
||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||
images_clear();
|
||||
#endif
|
||||
|
||||
if (system(cmd) == -1) {
|
||||
FAIL("open_with", "creating subcommand failed unhandled");
|
||||
}
|
||||
@@ -523,6 +537,9 @@ void update(){
|
||||
void enter_shell(int passes, int index){
|
||||
(void)passes;
|
||||
|
||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||
images_clear();
|
||||
#endif
|
||||
endwin();
|
||||
if (system(key_binding[index].black_magic) != 0) {
|
||||
/*do nothing*/
|
||||
@@ -686,6 +703,27 @@ void cmd_on_selected(int passes, int index){
|
||||
free(file_str);
|
||||
}
|
||||
}
|
||||
void yank_text(int passes, int index){
|
||||
(void)passes;
|
||||
char *cmd;
|
||||
if (strncmp((char*)key_binding[index].black_magic, "path", 4) == 0) {
|
||||
char *path=getcwd(NULL, 0);
|
||||
cmd = concat("echo \"", path);
|
||||
cmd = concat(cmd, "/");
|
||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
||||
cmd = concat(cmd, "\" | ");
|
||||
cmd = concat(cmd, clipboard_cmd);
|
||||
free(path);
|
||||
} else {
|
||||
cmd = concat("echo \"", mid_content[selected_file_current].file_name);
|
||||
cmd = concat(cmd, "\" | ");
|
||||
cmd = concat(cmd, clipboard_cmd);
|
||||
}
|
||||
if (system(cmd) == -1) {
|
||||
/*do nothing*/
|
||||
}
|
||||
free(cmd);
|
||||
}
|
||||
void yank_file(int passes, int index){
|
||||
(void)passes;
|
||||
|
||||
@@ -747,11 +785,19 @@ void paste(){
|
||||
mvprintw(i, 0, cmd);
|
||||
if (system(cmd) != 0) {
|
||||
cmd = concat(cmd, *yank_files.list);
|
||||
char *line = NULL;
|
||||
size_t size = 0;
|
||||
FILE *cmd_open;
|
||||
while (1) {
|
||||
cmd = concat(cmd, "_");
|
||||
if (system(cmd) == 0) {
|
||||
cmd_open = popen(cmd, "r");
|
||||
getline(&line, &size, cmd_open);
|
||||
|
||||
if (pclose(cmd_open) == 0) {
|
||||
break;
|
||||
} }
|
||||
}
|
||||
cmd = concat(cmd, "_");
|
||||
}
|
||||
|
||||
}
|
||||
yank_files.list++;
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@
|
||||
void user_interactions();
|
||||
void quit_program();
|
||||
void toggle_selection();
|
||||
void select_all();
|
||||
void move_right();
|
||||
void move_up(int passes);
|
||||
void move_down(int passes);
|
||||
@@ -25,6 +26,7 @@ void not_implemented(int passes, int index);
|
||||
void jump_to_dir(int passes, int index);
|
||||
void order_by(int passes, int index);
|
||||
void cmd_on_selected(int passes, int index);
|
||||
void yank_text(int passes, int index);
|
||||
void yank_file(int passes, int index);
|
||||
void paste();
|
||||
void search();
|
||||
|
5
main.c
5
main.c
@@ -107,10 +107,13 @@ int main(){
|
||||
#endif
|
||||
|
||||
}
|
||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||
ueberzug_close();
|
||||
#endif
|
||||
threading_free();
|
||||
free(start_path);
|
||||
|
||||
if (threading) {
|
||||
if (threading) {
|
||||
pthread_join(thread_l, NULL);
|
||||
pthread_join(thread_r, NULL);
|
||||
pthread_join(thread_m, NULL);
|
||||
|
28
threading.c
28
threading.c
@@ -277,6 +277,16 @@ void *thread_btm(){
|
||||
|
||||
char size_index = -1;
|
||||
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
unsigned long i;
|
||||
unsigned long total_dir_size = 0;
|
||||
for(i = 0; i < mid_file_count; i++) {
|
||||
if (!(mid_content[i].file_type & (FILE_TYPE_DIR | FILE_TYPE_SYMLINK))) {
|
||||
total_dir_size += mid_content[i].file_size;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
|
||||
do {
|
||||
parsed_number=disk_size_free;
|
||||
disk_size_free /= 1024;
|
||||
@@ -286,9 +296,25 @@ void *thread_btm(){
|
||||
|
||||
snprintf(float_str, 10, "%0.2lf", parsed_number);
|
||||
|
||||
memcpy(btm_buffer + (offset_back - strlen(float_str) - 1), float_str, strlen(float_str));
|
||||
btm_buffer[offset_back - 2] = size_unit[(unsigned)size_index];
|
||||
offset_back -= strlen(float_str) + 2;
|
||||
memcpy(btm_buffer + offset_back, float_str, strlen(float_str));
|
||||
|
||||
parsed_number = 0;
|
||||
size_index = -1;
|
||||
do {
|
||||
parsed_number=total_dir_size;
|
||||
total_dir_size /= 1024;
|
||||
size_index++;
|
||||
} while (total_dir_size > 1 && size_index < size_unit_count);
|
||||
|
||||
offset_back -= strlen(ui_btm_current_dir_size) + 5;
|
||||
memcpy(btm_buffer + offset_back, ui_btm_current_dir_size, strlen(ui_btm_current_dir_size));
|
||||
|
||||
snprintf(float_str, 10, "%0.2lf", parsed_number);
|
||||
btm_buffer[offset_back - 2] = size_unit[(unsigned)size_index];
|
||||
offset_back -= strlen(float_str) + 2;
|
||||
memcpy(btm_buffer + offset_back, float_str, strlen(float_str));
|
||||
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
}
|
||||
|
Reference in New Issue
Block a user