1
0
mirror of https://gittea.dev/nova/th.git synced 2026-03-16 15:27:25 -04:00

Compare commits

...

6 Commits

Author SHA1 Message Date
nova
f53fd66d88 added printing of mid_content[selected_file_current].file_name in top ui 2026-02-04 22:20:00 +01:00
nova
7e4ae9bb84 remove now useless memcopy 2026-02-04 22:17:52 +01:00
nova
36c8524a70 removed unused stdlib.h 2026-02-04 21:56:56 +01:00
nova
99ac76162f no longer try to file preview in a directory without files 2026-02-04 21:56:28 +01:00
nova
1d3b71b00f fix incorrect offset on files with long extensions 2026-02-04 21:55:03 +01:00
nova
84b1c17dd8 unzip jis 2026-02-02 23:24:41 +01:00
5 changed files with 28 additions and 14 deletions

View File

@@ -93,6 +93,7 @@ static const binding key_binding[] = {
{ "ut", cmd_on_selected, "tar -xvf", "unzip tar" },
{ "ut", cmd_on_selected, "gzip -d", "unzip gzip" },
{ "uz", cmd_on_selected, "unzip ", "unzip zip" },
{ "uj", cmd_on_selected, "unzip -O shift-jis", "unzip zip shift-jis" },
{ "on", order_by, sort_natural, "order natural" },
{ "oe", order_by, sort_extension, "order extension" },

31
dir.c
View File

@@ -238,30 +238,41 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
/* shortens the printed file name if it is too long
* example input: aaaaaaaa.txt
* example input: aaaaaaaa.txt
* example output: aaa~.txt
* example input: aaaaaaaa.longextension
* example output: ~.longe~
* if no extension is found, the name will truncate */
char *file_name = NULL;
unsigned long printable_size = (offset_back - is_selected - offset_front);
if (strlen(dir_content[i].file_name) > printable_size) {
unsigned long printable_size = offset_back - (is_selected + offset_front);
if (strlen(dir_content[i].file_name) >= printable_size) {
char *extension = strrchr(dir_content[i].file_name, '.');
if (extension && extension != dir_content[i].file_name) {
file_name = malloc(printable_size);
printable_size -= strlen(extension);
file_name = malloc(printable_size+1);
memcpy(file_name, dir_content[i].file_name, printable_size);
memcpy(file_name + printable_size-1, extension, strlen(extension));
file_name[printable_size + strlen(extension)-1] = '\0';
file_name[printable_size - 2] = '~';
/*if the extension is bigger than the filename this is false */
if ((&file_name[printable_size - strlen(extension)] - 2) > file_name) {
memcpy(file_name, dir_content[i].file_name, (printable_size - strlen(extension)));
memcpy(file_name + (printable_size - strlen(extension))-1, extension, strlen(extension)+1);
file_name[printable_size - strlen(extension) - 2] = '~';
file_name[printable_size] = '\0';
} else {
memcpy(file_name + 1, extension, printable_size - 1);
file_name[0] = '~';
file_name[printable_size-2] = '~';
file_name[printable_size-1] = '\0';
}
} else {
file_name = malloc(printable_size);
memcpy(file_name, dir_content[i].file_name, printable_size);
file_name[printable_size-2] = '~';
file_name[printable_size-1] = '\0';
file_name[printable_size] = '\0';
}
} else {
file_name = malloc(strlen(dir_content[i].file_name)+1);
memcpy(file_name, dir_content[i].file_name, strlen(dir_content[i].file_name)+1);
memcpy(file_name, dir_content[i].file_name, strlen(dir_content[i].file_name));
file_name[strlen(dir_content[i].file_name)] = '\0';
}

View File

@@ -1,6 +1,5 @@
#include <curses.h>
#include <dirent.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <pthread.h>

View File

@@ -188,7 +188,7 @@ void *thread_rgt(){
rgt_content->file_type = 0;
rgt_content->permissions = mid_content[selected_file_current].permissions;
}
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME) {
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME && mid_file_count > 0) {
unsigned long i = 0;
for (i = 0; i < rgt_file_count; i++) {
@@ -246,6 +246,7 @@ void *thread_top(){
top_buffer = malloc(strlen(global_path)+1);
memcpy(top_buffer, global_path, strlen(global_path)+1);
top_width = strlen(top_buffer);
/*printing of mid_content[selected_file_current].file_name is done directly in window.c window_top()*/
pthread_mutex_unlock(&mutex_top);
}

View File

@@ -37,11 +37,13 @@ void window_top(WINDOW *win){
werase(win);
if (pthread_mutex_trylock(&mutex_top) == 0) {
wattron(win, COLOR_PAIR(COLOR_PATH));
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
wattron(win, COLOR_PAIR(COLOR_PATH));
mvwaddstr(win, 0, 0, top_buffer);
mvwaddch(win, 0, strlen(top_buffer), '/');
wattroff(win, COLOR_PAIR(COLOR_PATH));
mvwaddstr(win, 0, strlen(top_buffer)+1, mid_content[selected_file_current].file_name);
}
wattroff(win, COLOR_PAIR(COLOR_PATH));
pthread_mutex_unlock(&mutex_top);
} else {
mvwaddstr(win, 0, terminal_width/2, "LOADING");