mirror of
https://gittea.dev/nova/th.git
synced 2025-10-21 10:20:15 -04:00
Compare commits
4 Commits
8fade0c4a8
...
0b98e8eb68
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0b98e8eb68 | ||
![]() |
87ae2a5e8f | ||
![]() |
f0ad6295f7 | ||
![]() |
e979209de3 |
72
dir.c
72
dir.c
@@ -192,42 +192,11 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
offset_vertical = selected_file_current - (terminal_height/3)*2;
|
offset_vertical = selected_file_current - (terminal_height/3)*2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
offset_front = 0;
|
||||||
}
|
}
|
||||||
for (i = offset_vertical; i < *dir_file_count && i < (terminal_height + offset_vertical); i++) {
|
for (i = offset_vertical; i < *dir_file_count && i < (terminal_height + offset_vertical); i++) {
|
||||||
|
|
||||||
/* shortens the printed file name if it is too long
|
|
||||||
* example input: aaaaaaaa.txt
|
|
||||||
* example output: aaa~.txt
|
|
||||||
* if no extension is found, the name will truncate */
|
|
||||||
char *file_name;
|
|
||||||
unsigned long file_name_width = strlen(dir_content[i].file_name);
|
|
||||||
if ((file_name_width + offset_front + is_selected) > line_width - 3) {
|
|
||||||
char *extension = strrchr(dir_content[i].file_name, '.');
|
|
||||||
if (extension) {
|
|
||||||
int char_offset = (file_name_width + offset_front + is_selected) - (line_width - 3) ;
|
|
||||||
if ((file_name_width - char_offset - strlen(extension) - 1) > 1) {
|
|
||||||
file_name = malloc(file_name_width - char_offset + 1);
|
|
||||||
memcpy(file_name, dir_content[i].file_name, file_name_width - char_offset);
|
|
||||||
memcpy(file_name + (file_name_width - char_offset - strlen(extension)), extension, strlen(extension));
|
|
||||||
file_name[file_name_width - char_offset - strlen(extension) - 1] = '~';
|
|
||||||
file_name[file_name_width - char_offset] = '\0';
|
|
||||||
} else {
|
|
||||||
file_name = malloc(strlen(extension)+1);
|
|
||||||
file_name[0] = '~';
|
|
||||||
memcpy(file_name+1, extension, strlen(extension));
|
|
||||||
file_name[strlen(extension)] = '\0';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
file_name = malloc(file_name_width+1);
|
|
||||||
memcpy(file_name, dir_content[i].file_name, file_name_width);
|
|
||||||
file_name[file_name_width] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
file_name = malloc(file_name_width+1);
|
|
||||||
memcpy(file_name, dir_content[i].file_name, file_name_width);
|
|
||||||
file_name[file_name_width] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (print_info) {
|
if (print_info) {
|
||||||
@@ -248,7 +217,8 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
} else {
|
} else {
|
||||||
offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1);
|
offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
offset_back = line_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
@@ -267,6 +237,37 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
wattroff(win, A_REVERSE);
|
wattroff(win, A_REVERSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* shortens the printed file name if it is too long
|
||||||
|
* example input: aaaaaaaa.txt
|
||||||
|
* example output: aaa~.txt
|
||||||
|
* if no extension is found, the name will truncate */
|
||||||
|
char *file_name;
|
||||||
|
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);
|
||||||
|
|
||||||
|
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] = '~';
|
||||||
|
} else {
|
||||||
|
file_name = malloc(printable_size-1);
|
||||||
|
memcpy(file_name, dir_content[i].file_name, printable_size);
|
||||||
|
file_name[printable_size-2] = '~';
|
||||||
|
file_name[printable_size-1] = '\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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mvwaddstr(win, i-offset_vertical, 0, bg);
|
mvwaddstr(win, i-offset_vertical, 0, bg);
|
||||||
if(print_info) {
|
if(print_info) {
|
||||||
#if SETTINGS_LINE_NUMBERS == 2
|
#if SETTINGS_LINE_NUMBERS == 2
|
||||||
@@ -300,7 +301,6 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, file_name, line_width-offset_front-is_selected-2);
|
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, file_name, line_width-offset_front-is_selected-2);
|
||||||
free(file_name);
|
|
||||||
|
|
||||||
if (dir_content[i].file_type &= FILE_TYPE_DIR) {
|
if (dir_content[i].file_type &= FILE_TYPE_DIR) {
|
||||||
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir_content[i].file_size);
|
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir_content[i].file_size);
|
||||||
@@ -311,8 +311,8 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mvwaddnstr(win, i-offset_vertical, 0, file_name, line_width);
|
mvwaddnstr(win, i-offset_vertical, 0, file_name, line_width);
|
||||||
free(file_name);
|
|
||||||
}
|
}
|
||||||
|
free(file_name);
|
||||||
|
|
||||||
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
wattroff(win, COLOR_PAIR(8));
|
wattroff(win, COLOR_PAIR(8));
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "file_previews.h"
|
#include "file_previews.h"
|
||||||
#include "backend.h"
|
#include "backend.h"
|
||||||
@@ -36,7 +37,7 @@ extern unsigned int status;
|
|||||||
extern char *start_path;
|
extern char *start_path;
|
||||||
extern char *input;
|
extern char *input;
|
||||||
|
|
||||||
extern time_t seed;
|
extern time_t *seed;
|
||||||
|
|
||||||
char search_buffer[255];
|
char search_buffer[255];
|
||||||
unsigned int timeout_time = 0;
|
unsigned int timeout_time = 0;
|
||||||
@@ -633,8 +634,10 @@ void jump_to_dir(int passes, int index){
|
|||||||
void order_by(int passes, int index){
|
void order_by(int passes, int index){
|
||||||
(void)passes;
|
(void)passes;
|
||||||
|
|
||||||
seed = time(NULL);
|
free(seed);
|
||||||
srand(seed);
|
seed = malloc(sizeof(time_t));
|
||||||
|
*seed = time(NULL);
|
||||||
|
|
||||||
order_func = key_binding[index].black_magic;
|
order_func = key_binding[index].black_magic;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
|
7
main.c
7
main.c
@@ -21,7 +21,7 @@ unsigned int settings;
|
|||||||
unsigned int file_modifiers;
|
unsigned int file_modifiers;
|
||||||
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
char *start_path;
|
char *start_path;
|
||||||
time_t seed;
|
time_t *seed;
|
||||||
|
|
||||||
WINDOW *win_t;
|
WINDOW *win_t;
|
||||||
WINDOW *win_b;
|
WINDOW *win_b;
|
||||||
@@ -102,7 +102,6 @@ int main(){
|
|||||||
if (dt - t >= SETTINGS_RELOAD_DIR_DELTA) {
|
if (dt - t >= SETTINGS_RELOAD_DIR_DELTA) {
|
||||||
time(&t);
|
time(&t);
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
srand(seed);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -209,6 +208,8 @@ void init() {
|
|||||||
char *start_path = getcwd(NULL, 0);
|
char *start_path = getcwd(NULL, 0);
|
||||||
setenv("START_PATH", start_path, 0);
|
setenv("START_PATH", start_path, 0);
|
||||||
free(start_path);
|
free(start_path);
|
||||||
seed = time(NULL);
|
|
||||||
|
seed = malloc(sizeof(time_t));
|
||||||
|
*seed = time(NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
46
sorting.c
46
sorting.c
@@ -4,12 +4,11 @@
|
|||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
extern time_t seed;
|
extern time_t *seed;
|
||||||
extern unsigned int settings;
|
|
||||||
extern unsigned int file_modifiers;
|
|
||||||
|
|
||||||
int skip_hidden_files(const struct dirent *entry){
|
int skip_hidden_files(const struct dirent *entry){
|
||||||
|
|
||||||
@@ -43,38 +42,37 @@ int sort_natural(const void *file0, const void *file1){
|
|||||||
char result = 0;
|
char result = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
is_num = 0;
|
|
||||||
|
|
||||||
if ((*a >= '0') && (*a <= '9')) {
|
if ((*a <= '9') && (*a >= '0')) {
|
||||||
parsed_number0 = 0;
|
parsed_number0 = 0;
|
||||||
while((*a >= '0') && (*a <= '9')) {
|
do {
|
||||||
parsed_number0 = (parsed_number0 * 10) + (*a - '0');
|
parsed_number0 = (parsed_number0 * 10) + (*a - '0');
|
||||||
a++;
|
a++;
|
||||||
}
|
} while((*a <= '9') && (*a >= '0'));
|
||||||
is_num |= 1;
|
is_num |= 1;
|
||||||
}
|
}
|
||||||
if ((*b >= '0') && (*b <= '9')) {
|
if ((*b <= '9') && (*b >= '0')) {
|
||||||
parsed_number1 = 0;
|
parsed_number1 = 0;
|
||||||
while((*b >= '0') && (*b <= '9')) {
|
do {
|
||||||
parsed_number1 = (parsed_number1 * 10) + (*b - '0');
|
parsed_number1 = (parsed_number1 * 10) + (*b - '0');
|
||||||
b++;
|
b++;
|
||||||
}
|
} while((*b <= '9') && (*b >= '0'));
|
||||||
is_num |= 2;
|
is_num |= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_num) {
|
if (is_num) {
|
||||||
if (is_num == 1) {
|
if (is_num == 1) {
|
||||||
if (*b < '0') {
|
if (*b > '9') {
|
||||||
result = 1;
|
|
||||||
} else {
|
|
||||||
result = -1;
|
result = -1;
|
||||||
|
} else {
|
||||||
|
result = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (is_num == 2) {
|
} else if (is_num == 2) {
|
||||||
if (*a < '0') {
|
if (*a > '9') {
|
||||||
result = -1;
|
|
||||||
} else {
|
|
||||||
result = 1;
|
result = 1;
|
||||||
|
} else {
|
||||||
|
result = -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@@ -88,6 +86,7 @@ int sort_natural(const void *file0, const void *file1){
|
|||||||
}
|
}
|
||||||
/* those breaks are not set here, due to the possibillity that both numbers are equal
|
/* those breaks are not set here, due to the possibillity that both numbers are equal
|
||||||
* in which case the comparison should continue */
|
* in which case the comparison should continue */
|
||||||
|
is_num = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char aa = ((*a >= 'A') && (*a <= 'Z')) ? (*a | ' ') : *a;
|
unsigned char aa = ((*a >= 'A') && (*a <= 'Z')) ? (*a | ' ') : *a;
|
||||||
@@ -119,8 +118,21 @@ int sort_random(const void *file0, const void *file1){
|
|||||||
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
time_t num = (time_t)&seed;
|
||||||
|
unsigned long i;
|
||||||
|
for (i = 0; i < 6; i++){
|
||||||
|
num ^= *seed;
|
||||||
|
if (num%2) {
|
||||||
|
num ^= (time_t)#
|
||||||
|
num ^= num << i;
|
||||||
|
} else {
|
||||||
|
num ^= (time_t)&seed;
|
||||||
|
num ^= num >> i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num ^= getpid();
|
||||||
|
|
||||||
return ((rand()%3)-1);
|
return ((num%3) - 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
int sort_type(const void *file0, const void *file1){
|
int sort_type(const void *file0, const void *file1){
|
||||||
|
Reference in New Issue
Block a user