diff --git a/include/cursesutils.h b/include/cursesutils.h index 439e3f9..85d2ad7 100644 --- a/include/cursesutils.h +++ b/include/cursesutils.h @@ -43,9 +43,41 @@ #include #include -// Constants +/* Constants */ #define MAX_PATH_LENGTH 256 +/* COLOR PAIRS DEF */ + +#define FILE_COLOR_PAIR 1 +#define DIR_COLOR_PAIR 2 +#define ARCHIVE_COLOR_PAIR 3 +#define AUDIO_COLOR_PAIR 4 +#define IMAGE_COLOR_PAIR 5 +#define SYMLINK_COLOR_PAIR 6 +#define AQUA_COLOR_PAIR 7 +#define VIOLET_COLOR_PAIR 8 +#define DARK_BG_COLOR_PAIR 9 +#define MAGENTA_COLOR_PAIR 10 +#define SPECIAL_COLOR_PAIR 11 +#define ERROR_COLOR_PAIR 12 +#define CUSTOM_COLOR_PAIR 13 +#define TITLE_COLOR_PAIR 14 +#define HIGHLIGHT_COLOR_PAIR 15 + +/* COMPRESSION OPTIONS COLOR PAIR + MISC DEF */ + +#define STEP_SELECT_FORMAT 0 +#define STEP_SELECT_ACTION 1 + +#define COMP_COLOR_TITLE 31 +#define COMP_COLOR_HIGHLIGHT 32 +#define COMP_COLOR_NORMAL 33 +#define COMP_COLOR_FOOTER 34 + +#define OPTION_TAR 1 +#define OPTION_ZIP 2 +#define OPTION_EXIT 0 + // Function Prototypes void show_message(WINDOW* win, const char* message); void print_limited(WINDOW* win, int y, int x, const char* str); diff --git a/lfm.c b/lfm.c index c666288..fc705f8 100644 --- a/lfm.c +++ b/lfm.c @@ -53,6 +53,19 @@ #define MAX_HISTORY 256 #define MAX_ITEM_NAME_LENGTH 80 // Define a maximum length for item names +/* UNICODES DEF */ + +#define UNICODE_DISK "💾" +#define UNICODE_FOLDER "📁" +#define UNICODE_SYMLINK "🔗" +#define UNICODE_ARCHIVE "📦" +#define UNICODE_AUDIO "🎵 " +#define UNICODE_IMAGE "🖼️" +#define UNICODE_FILE "📄" +#define UNICODE_VIDEO "🎥" +#define UNICODE_SEARCH "🔍" + + const char * err_message[] = { " _ _ ___ _____ ___ _ _____ ____ __ ____ ___ ____ ____ ", "| \\ | |/ _ \\ | ___|_ _| | | ____/ ___| / / | _ \\_ _| _ \\/ ___| ", @@ -194,12 +207,12 @@ void print_items(WINDOW *win, FileItem items[], int count, int highlight, color_pair_init(); // Print title - wattron(win, COLOR_PAIR(9)); + wattron(win, COLOR_PAIR(DARK_BG_COLOR_PAIR)); char *cur_user = get_current_user(); char *cur_hostname = get_hostname(); - wattron(win, A_BOLD | COLOR_PAIR(14)); + wattron(win, A_BOLD | COLOR_PAIR(TITLE_COLOR_PAIR)); mvwprintw(win, 0, 2, " 🗄️ LITE FM: "); - wattroff(win, A_BOLD | COLOR_PAIR(14)); + wattroff(win, A_BOLD | COLOR_PAIR(TITLE_COLOR_PAIR)); char sanitizedCurPath[PATH_MAX]; if (strncmp(current_path, "//", 2) == 0) { @@ -210,29 +223,29 @@ void print_items(WINDOW *win, FileItem items[], int count, int highlight, // Print current path and hidden directories status wattron(win, A_BOLD); - wattron(win, COLOR_PAIR(8)); + wattron(win, COLOR_PAIR(VIOLET_COLOR_PAIR)); mvwprintw(win, 2, 2, " %s@%s ", cur_hostname, cur_user); - wattroff(win, COLOR_PAIR(8)); - wattron(win, COLOR_PAIR(9)); + wattroff(win, COLOR_PAIR(VIOLET_COLOR_PAIR)); + wattron(win, COLOR_PAIR(DARK_BG_COLOR_PAIR)); print_limited(win, 2, 20, sanitizedCurPath); - wattroff(win, COLOR_PAIR(9)); - wattron(win, COLOR_PAIR(9)); + wattroff(win, COLOR_PAIR(DARK_BG_COLOR_PAIR)); + wattron(win, COLOR_PAIR(DARK_BG_COLOR_PAIR)); mvwprintw(win, LINES - 3, (COLS / 2) - 55, " Hidden Dirs: %s ", hidden_dir); - mvwprintw(win, LINES - 3, (COLS / 2) - 30, " 💾 %.2f / %.2f GiB ", systemFreeSpace, totalSystemSpace); - wattroff(win, COLOR_PAIR(9)); + mvwprintw(win, LINES - 3, (COLS / 2) - 30, " %s %.2f / %.2f GiB ", UNICODE_DISK, systemFreeSpace, totalSystemSpace); + wattroff(win, COLOR_PAIR(DARK_BG_COLOR_PAIR)); wattroff(win, A_BOLD); // Print items if (count == 0) { - wattron(win, COLOR_PAIR(3)); + wattron(win, COLOR_PAIR(ARCHIVE_COLOR_PAIR)); int err_msg_size = sizeof(err_message) / sizeof(err_message[0]); for (int i = 0; i < err_msg_size; i++) { mvwprintw(win, i + 5, 2, "%s", err_message[i]); } - wattroff(win, COLOR_PAIR(3)); - wattron(win, A_BOLD | COLOR_PAIR(5)); + wattroff(win, COLOR_PAIR(ARCHIVE_COLOR_PAIR)); + wattron(win, A_BOLD | COLOR_PAIR(IMAGE_COLOR_PAIR)); mvwprintw(win, 15, 2, "<== PRESS H or <-"); - wattroff(win, A_BOLD | COLOR_PAIR(5)); + wattroff(win, A_BOLD | COLOR_PAIR(IMAGE_COLOR_PAIR)); } else { for (int i = 0; i < height - 7 && i + scroll_position < count; i++) { int index = i + scroll_position; @@ -244,31 +257,34 @@ void print_items(WINDOW *win, FileItem items[], int count, int highlight, // Apply color based on file type if (items[index].is_dir) { - wattron(win, COLOR_PAIR(2)); - mvwprintw(win, i + 4, 5, "📁"); + wattron(win, COLOR_PAIR(DIR_COLOR_PAIR)); + mvwprintw(win, i + 4, 5, "%s", UNICODE_FOLDER); } else if (is_symlink(full_path)) { - wattron(win, COLOR_PAIR(6)); // Choose an appropriate color pair for symlinks - mvwprintw(win, i + 4, 5, "🔗"); // Unicode for symlink + wattron(win, COLOR_PAIR(SYMLINK_COLOR_PAIR)); // Choose an appropriate color pair for symlinks + mvwprintw(win, i + 4, 5, "%s", UNICODE_SYMLINK); // Unicode for symlink } else { // Determine file type by extension char *extension = strrchr(items[index].name, '.'); if (extension) { if (strcmp(extension, ".zip") == 0 || strcmp(extension, ".7z") == 0 || strcmp(extension, ".tar") == 0 || strcmp(extension, ".xz") == 0 || strcmp(extension, ".gz") == 0 || strcmp(extension, ".jar") == 0) { - wattron(win, COLOR_PAIR(3)); - mvwprintw(win, i + 4, 5, "📦"); - } else if (strcmp(extension, ".mp3") == 0 || strcmp(extension, ".mp4") == 0 || strcmp(extension, ".wav") == 0 || strcmp(extension, ".flac") == 0 || strcmp(extension, ".opus") == 0) { - wattron(win, COLOR_PAIR(4)); - mvwprintw(win, i + 4, 5, "🎵 "); + wattron(win, COLOR_PAIR(ARCHIVE_COLOR_PAIR)); + mvwprintw(win, i + 4, 5, "%s", UNICODE_ARCHIVE); + } else if (strcmp(extension, ".mp3") == 0 || strcmp(extension, ".wav") == 0 || strcmp(extension, ".flac") == 0 || strcmp(extension, ".opus") == 0) { + wattron(win, COLOR_PAIR(AUDIO_COLOR_PAIR)); + mvwprintw(win, i + 4, 5, "%s", UNICODE_AUDIO); } else if (strcmp(extension, ".png") == 0 || strcmp(extension, ".jpg") == 0 || strcmp(extension, ".webp") == 0 || strcmp(extension, ".gif") == 0) { - wattron(win, COLOR_PAIR(5)); - mvwprintw(win, i + 4, 5, "🖼️"); + wattron(win, COLOR_PAIR(IMAGE_COLOR_PAIR)); + mvwprintw(win, i + 4, 5, "%s", UNICODE_IMAGE); + } else if (strcmp(extension, ".mp4") == 0 || strcmp(extension, ".m4v") == 0 || strcmp(extension, ".mkv") == 0 || strcmp(extension, ".avi") == 0) { + wattron(win, COLOR_PAIR(AUDIO_COLOR_PAIR)); + mvwprintw(win, i+4, 5, "%s", UNICODE_VIDEO); } else { - wattron(win, COLOR_PAIR(1)); - mvwprintw(win, i + 4, 5, "📄"); + wattron(win, COLOR_PAIR(FILE_COLOR_PAIR)); + mvwprintw(win, i + 4, 5, "%s", UNICODE_FILE); } } else { - wattron(win, COLOR_PAIR(1)); - mvwprintw(win, i + 4, 5, "📄"); + wattron(win, COLOR_PAIR(FILE_COLOR_PAIR)); + mvwprintw(win, i + 4, 5, "%s", UNICODE_FILE); } } @@ -285,13 +301,13 @@ void print_items(WINDOW *win, FileItem items[], int count, int highlight, // Turn off color attributes wattroff(win, A_BOLD); - wattroff(win, COLOR_PAIR(1)); - wattroff(win, COLOR_PAIR(2)); - wattroff(win, COLOR_PAIR(3)); - wattroff(win, COLOR_PAIR(4)); - wattroff(win, COLOR_PAIR(5)); - wattroff(win, COLOR_PAIR(6)); // Turn off the color pair for symlinks - wattroff(win, COLOR_PAIR(9)); + wattroff(win, COLOR_PAIR(FILE_COLOR_PAIR)); + wattroff(win, COLOR_PAIR(DIR_COLOR_PAIR)); + wattroff(win, COLOR_PAIR(ARCHIVE_COLOR_PAIR)); + wattroff(win, COLOR_PAIR(AUDIO_COLOR_PAIR)); + wattroff(win, COLOR_PAIR(IMAGE_COLOR_PAIR)); + wattroff(win, COLOR_PAIR(SYMLINK_COLOR_PAIR)); // Turn off the color pair for symlinks + wattroff(win, COLOR_PAIR(DARK_BG_COLOR_PAIR)); if (index == highlight) wattroff(win, A_REVERSE); @@ -421,48 +437,48 @@ void get_file_info_popup(WINDOW * main_win, colorLine(info_win, "File Information: ", 1, 1, 2); /* colorLine params: win, string, color_pair, x, y */ colorLine(info_win, "Name: ", 3, 3, 2); - wattron(info_win, COLOR_PAIR(4)); + wattron(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); wprintw(info_win, "%s", filename); - wattroff(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); colorLine(info_win, "Size: ", 3, 4, 2); - wattron(info_win, COLOR_PAIR(4)); + wattron(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); wprintw(info_win, "%s", format_file_size(file_stat.st_size)); - wattroff(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); const char * file_ext = strrchr(filename, '.'); - colorLine(info_win, "Extension: ", 3, 5, 2); - wattron(info_win, COLOR_PAIR(4)); + colorLine(info_win, "File Type: ", 3, 5, 2); + wattron(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); if (file_ext != NULL) { - wprintw(info_win, "%s", file_ext + 1); + wprintw(info_win, "%s", determine_file_type(full_path)); } else { wprintw(info_win, "none"); } - wattroff(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); colorLine(info_win, "Last Modified: ", 3, 6, 2); - wattron(info_win, COLOR_PAIR(4)); + wattron(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); char mod_time[20]; strftime(mod_time, sizeof(mod_time), "%Y-%m-%d %H:%M:%S", localtime( & file_stat.st_mtime)); wprintw(info_win, "%s", mod_time); - wattroff(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); colorLine(info_win, "Permissions: ", 3, 7, 2); print_permissions(info_win, &file_stat); colorLine(info_win, "Inode: ", 3, 8, 2); - wattron(info_win, COLOR_PAIR(4)); + wattron(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); wprintw(info_win, "%lu", file_stat.st_ino); - wattroff(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); // Additional file attributes can be displayed here struct passwd * pwd = getpwuid(file_stat.st_uid); - wattron(info_win, COLOR_PAIR(3)); + wattron(info_win, COLOR_PAIR(ARCHIVE_COLOR_PAIR)); mvwprintw(info_win, 9, 2, "Owner: "); - wattroff(info_win, COLOR_PAIR(3)); - wattron(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(ARCHIVE_COLOR_PAIR)); + wattron(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); wprintw(info_win, "%s (%d)", pwd -> pw_name, file_stat.st_uid); - wattroff(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); colorLine(info_win, "Press any key to close this window.", 2, info_win_height - 2, 2); wrefresh(info_win); @@ -521,54 +537,54 @@ void get_file_info(WINDOW *info_win, const char *path, const char *filename) { clearLine(info_win, 3, 2); colorLine(info_win, "Name: ", 3, 3, 2); - wattron(info_win, COLOR_PAIR(4)); + wattron(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); wprintw(info_win, "%s", truncated_file_name); - wattroff(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); clearLine(info_win, 4, 2); colorLine(info_win, "Size: ", 3, 4, 2); - wattron(info_win, COLOR_PAIR(4)); + wattron(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); wprintw(info_win, "%s", format_file_size(file_stat.st_size)); - wattroff(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); const char *file_ext = strrchr(filename, '.'); clearLine(info_win, 5, 2); - colorLine(info_win, "Extension: ", 3, 5, 2); - wattron(info_win, COLOR_PAIR(4)); - if (file_ext != NULL && !S_ISDIR(file_stat.st_mode)) { - wprintw(info_win, "%s", file_ext + 1); + colorLine(info_win, "Inode Type: ", 3, 5, 2); + wattron(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); + if (!S_ISDIR(file_stat.st_mode)) { + wprintw(info_win, "%s", determine_file_type(full_path)); } else { - wprintw(info_win, "none"); + wprintw(info_win, "Directory"); } - wattroff(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); char mod_time[20]; strftime(mod_time, sizeof(mod_time), "%Y-%m-%d %H:%M:%S", localtime(&file_stat.st_mtime)); clearLine(info_win, 6, 2); colorLine(info_win, "Last Modified: ", 3, 6, 2); - wattron(info_win, COLOR_PAIR(4)); + wattron(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); wprintw(info_win, "%s", mod_time); - wattroff(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); colorLine(info_win, "Inode: ", 3, 7, 2); - wattron(info_win, COLOR_PAIR(4)); + wattron(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); wprintw(info_win, "%lu", file_stat.st_ino); - wattroff(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); clearLine(info_win, 8, 2); colorLine(info_win, "Group: ", 3, 8, 2); - wattron(info_win, COLOR_PAIR(4)); + wattron(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); struct group *grp = getgrgid(file_stat.st_gid); if (grp != NULL) { wprintw(info_win, "%s", grp->gr_name); } else { wprintw(info_win, "Unknown"); } - wattroff(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); clearLine(info_win, 9, 2); colorLine(info_win, "Type: ", 3, 9, 2); - wattron(info_win, COLOR_PAIR(5)); + wattron(info_win, COLOR_PAIR(IMAGE_COLOR_PAIR)); if (S_ISREG(file_stat.st_mode)) { wprintw(info_win, "Regular File"); @@ -578,15 +594,15 @@ void get_file_info(WINDOW *info_win, const char *path, const char *filename) { display_archive_contents(info_win, full_path, file_ext); } } else if (S_ISDIR(file_stat.st_mode)) { - wattron(info_win, COLOR_PAIR(11)); + wattron(info_win, COLOR_PAIR(SPECIAL_COLOR_PAIR)); wprintw(info_win, "Directory"); - wattroff(info_win, COLOR_PAIR(11)); + wattroff(info_win, COLOR_PAIR(SPECIAL_COLOR_PAIR)); // Horizontal Layout for Parent Directories and Subdirectories - wattron(info_win, A_BOLD | COLOR_PAIR(9)); - mvwprintw(info_win, 11, 2, " Parent Directories: "); - mvwprintw(info_win, 11, getmaxx(info_win) / 2, " Children: "); - wattroff(info_win, A_BOLD | COLOR_PAIR(9)); + wattron(info_win, A_BOLD | COLOR_PAIR(DARK_BG_COLOR_PAIR)); + mvwprintw(info_win, 12, 2, " Parent Directories: "); + mvwprintw(info_win, 12, getmaxx(info_win) / 2, " Children: "); + wattroff(info_win, A_BOLD | COLOR_PAIR(DARK_BG_COLOR_PAIR)); char parent_dir[PATH_MAX]; char current_path[PATH_MAX]; @@ -597,8 +613,8 @@ void get_file_info(WINDOW *info_win, const char *path, const char *filename) { // Make a copy of the parent directory path to avoid modifying the original path strncpy(parent_dir, parent_dir_ptr, sizeof(parent_dir)); parent_dir[sizeof(parent_dir) - 1] = '\0'; // Ensure null termination - int line = 12; - int sub_dir_line = 12; + int line = 13; + int sub_dir_line = 13; int max_y, max_x; getmaxyx(info_win, max_y, max_x); @@ -606,12 +622,12 @@ void get_file_info(WINDOW *info_win, const char *path, const char *filename) { DIR *dir = opendir(parent_dir); struct dirent *entry; if (dir != NULL) { - wattron(info_win, A_BOLD | COLOR_PAIR(9)); + wattron(info_win, A_BOLD | COLOR_PAIR(DARK_BG_COLOR_PAIR)); mvwprintw(info_win, 10, 2, " Parent Directories: "); - wattroff(info_win, A_BOLD | COLOR_PAIR(9)); + wattroff(info_win, A_BOLD | COLOR_PAIR(DARK_BG_COLOR_PAIR)); int col = 2; // Starting column - wattron(info_win, A_BOLD | COLOR_PAIR(2)); + wattron(info_win, A_BOLD | COLOR_PAIR(DIR_COLOR_PAIR)); while ((entry = readdir(dir)) != NULL) { if (entry->d_type == DT_DIR) { // Exclude the current directory and the special entries "." and ".." @@ -629,7 +645,7 @@ void get_file_info(WINDOW *info_win, const char *path, const char *filename) { } } closedir(dir); - wattroff(info_win, A_BOLD | COLOR_PAIR(2)); + wattroff(info_win, A_BOLD | COLOR_PAIR(DIR_COLOR_PAIR)); } else { show_message(info_win, "Error opening parent directory."); } @@ -647,9 +663,9 @@ void get_file_info(WINDOW *info_win, const char *path, const char *filename) { } else { snprintf(truncated_sub_dir_name, sizeof(truncated_sub_dir_name), "%s", entry->d_name); } - wattron(info_win, A_BOLD | COLOR_PAIR(2)); + wattron(info_win, A_BOLD | COLOR_PAIR(DIR_COLOR_PAIR)); mvwprintw(info_win, sub_dir_line++, max_x / 2, " %s", truncated_sub_dir_name); - wattroff(info_win, A_BOLD | COLOR_PAIR(2)); + wattroff(info_win, A_BOLD | COLOR_PAIR(DIR_COLOR_PAIR)); } } } @@ -663,9 +679,9 @@ void get_file_info(WINDOW *info_win, const char *path, const char *filename) { } else { snprintf(truncated_file_name, sizeof(truncated_file_name), "%s", entry->d_name); } - wattron(info_win, A_BOLD | COLOR_PAIR(1)); + wattron(info_win, A_BOLD | COLOR_PAIR(FILE_COLOR_PAIR)); mvwprintw(info_win, sub_dir_line++, max_x / 2, " %s", truncated_file_name); - wattroff(info_win, A_BOLD | COLOR_PAIR(1)); + wattroff(info_win, A_BOLD | COLOR_PAIR(FILE_COLOR_PAIR)); } } closedir(dir); @@ -673,20 +689,20 @@ void get_file_info(WINDOW *info_win, const char *path, const char *filename) { show_message(info_win, "Error opening directory."); } } else if (S_ISLNK(file_stat.st_mode)) { - wattron(info_win, COLOR_PAIR(6)); + wattron(info_win, COLOR_PAIR(SYMLINK_COLOR_PAIR)); wprintw(info_win, "Symbolic Link"); // Read the symlink target len = readlink(full_path, symlink_target, sizeof(symlink_target) - 1); if (len != -1) { symlink_target[len] = '\0'; // Null-terminate the string - wattron(info_win, COLOR_PAIR(4)); + wattron(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); wprintw(info_win, " to %s", symlink_target); - wattroff(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); } else { show_message(info_win, "Error reading symlink target."); } - wattroff(info_win, COLOR_PAIR(6)); + wattroff(info_win, COLOR_PAIR(SYMLINK_COLOR_PAIR)); } else if (S_ISFIFO(file_stat.st_mode)) { wprintw(info_win, "FIFO"); } else if (S_ISCHR(file_stat.st_mode)) { @@ -698,12 +714,12 @@ void get_file_info(WINDOW *info_win, const char *path, const char *filename) { } else { wprintw(info_win, "Unknown"); } - wattroff(info_win, COLOR_PAIR(5)); + wattroff(info_win, COLOR_PAIR(IMAGE_COLOR_PAIR)); clearLine(info_win, 10, 2); - wattron(info_win, COLOR_PAIR(3)); + wattron(info_win, COLOR_PAIR(ARCHIVE_COLOR_PAIR)); mvwprintw(info_win, 10, 2, "Permissions: "); - wattroff(info_win, COLOR_PAIR(3)); + wattroff(info_win, COLOR_PAIR(ARCHIVE_COLOR_PAIR)); print_permissions(info_win, &file_stat); box(info_win, 0, 0); @@ -982,7 +998,7 @@ int main(int argc, char* argv[]) { if (result == 0) { char msg[256]; log_message(LOG_LEVEL_INFO, "File created successfully for `%s`", name_input); - snprintf(msg, sizeof(msg), "📄 File '%s' created at %s.", name_input, timestamp); + snprintf(msg, sizeof(msg), "%s File '%s' created at %s.", UNICODE_FILE, name_input, timestamp); show_term_message(msg, 0); } else if (result == 1) { log_message(LOG_LEVEL_WARN, "File `%s` already exists", name_input); @@ -1077,9 +1093,9 @@ int main(int argc, char* argv[]) { break; case '/': // Find file or directory { - wattron(win, A_BOLD | COLOR_PAIR(7)); - mvwprintw(win, LINES - 3, (COLS / 2) - 75, "🔍 Search ON "); - wattroff(win, A_BOLD | COLOR_PAIR(7)); + wattron(win, A_BOLD | COLOR_PAIR(AQUA_COLOR_PAIR)); + mvwprintw(win, LINES - 3, (COLS / 2) - 75, "%s Search ON ", UNICODE_SEARCH); + wattroff(win, A_BOLD | COLOR_PAIR(AQUA_COLOR_PAIR)); wrefresh(win); char query[NAME_MAX]; get_user_input_from_bottom(stdscr, query, NAME_MAX, "search", current_path); @@ -1296,9 +1312,9 @@ int main(int argc, char* argv[]) { scroll_position = 0; } else if (nextch == '/') { - wattron(win, A_BOLD | COLOR_PAIR(7)); - mvwprintw(win, LINES - 3, (COLS / 2) - 75, "🔍 Search ON "); - wattroff(win, A_BOLD | COLOR_PAIR(7)); + wattron(win, A_BOLD | COLOR_PAIR(AQUA_COLOR_PAIR)); + mvwprintw(win, LINES - 3, (COLS / 2) - 75, "%s Search ON ", UNICODE_SEARCH); + wattroff(win, A_BOLD | COLOR_PAIR(AQUA_COLOR_PAIR)); wrefresh(win); char query[NAME_MAX]; get_user_input_from_bottom(stdscr, query, NAME_MAX, "search", current_path); @@ -1426,9 +1442,9 @@ int main(int argc, char* argv[]) { scroll_position = 0; } else if (nextch == '/') { - wattron(win, A_BOLD | COLOR_PAIR(7)); - mvwprintw(win, LINES - 3, (COLS / 2) - 75, "🔍 Search ON "); - wattroff(win, A_BOLD | COLOR_PAIR(7)); + wattron(win, A_BOLD | COLOR_PAIR(AQUA_COLOR_PAIR)); + mvwprintw(win, LINES - 3, (COLS / 2) - 75, "%s Search ON ", UNICODE_SEARCH); + wattroff(win, A_BOLD | COLOR_PAIR(AQUA_COLOR_PAIR)); wrefresh(win); char query[NAME_MAX]; get_user_input_from_bottom(stdscr, query, NAME_MAX, "search", current_path); diff --git a/src/arg_helpers.c b/src/arg_helpers.c index 0b1eff8..f6bc409 100644 --- a/src/arg_helpers.c +++ b/src/arg_helpers.c @@ -184,7 +184,9 @@ int handle_arguments(int argc, char* argv[], char* current_path) { get_current_working_directory(current_path, PATH_MAX); } - } else { + } + else + { get_current_working_directory(current_path, PATH_MAX); } return 1; diff --git a/src/cursesutils.c b/src/cursesutils.c index 9c1dd2b..777e204 100644 --- a/src/cursesutils.c +++ b/src/cursesutils.c @@ -62,216 +62,216 @@ void colorLine(WINDOW* win, const char* info, int colorpair, int x, int y) int show_compression_options(WINDOW* parent_win) { - WINDOW* options_win; - int choice; - int highlight = 0; - int c; - int step = 0; // 0 for selecting format, 1 for selecting action - - // Define window size and position - int win_height = 10; - int win_width = 40; - int win_y = (LINES - win_height) / 2; - int win_x = (COLS - win_width) / 2; - - // Create a new window for displaying options - options_win = newwin(win_height, win_width, win_y, win_x); - box(options_win, 0, 0); - keypad(options_win, TRUE); // Enable special keys (e.g., arrow keys) - draw_3d_info_win(options_win, win_y, win_x, win_height, win_width, 2, 4); - - // Define colors - init_pair(31, COLOR_BLACK, COLOR_BLUE); // Title - init_pair(32, COLOR_BLACK, COLOR_GREEN); // Highlighted option - init_pair(33, COLOR_WHITE, COLOR_BLACK); // Normal text - init_pair(34, COLOR_RED, COLOR_BLACK); // Footer text - - const char* top_options[] = {"TAR (.tar)", "ZIP (.zip)"}; - const char* bottom_options[] = {"COMPRESS", "EXIT"}; - - int num_top_options = sizeof(top_options) / sizeof(top_options[0]); - int num_bottom_options = sizeof(bottom_options) / sizeof(bottom_options[0]); - char title_buf[60]; + WINDOW* options_win; + int choice; + int highlight = 0; + int c; + int step = STEP_SELECT_FORMAT; // 0 for selecting format, 1 for selecting action + + // Define window size and position + int win_height = 10; + int win_width = 40; + int win_y = (LINES - win_height) / 2; + int win_x = (COLS - win_width) / 2; + + // Create a new window for displaying options + options_win = newwin(win_height, win_width, win_y, win_x); + box(options_win, 0, 0); + keypad(options_win, TRUE); // Enable special keys (e.g., arrow keys) + draw_3d_info_win(options_win, win_y, win_x, win_height, win_width, 2, 4); - while (1) - { - // Clear the window - werase(options_win); + // Define colors + init_pair(COMP_COLOR_TITLE, COLOR_BLACK, COLOR_BLUE); // Title + init_pair(COMP_COLOR_HIGHLIGHT, COLOR_BLACK, COLOR_GREEN); // Highlighted option + init_pair(COMP_COLOR_NORMAL, COLOR_WHITE, COLOR_BLACK); // Normal text + init_pair(COMP_COLOR_FOOTER, COLOR_RED, COLOR_BLACK); // Footer text - // Draw the box again - box(options_win, 0, 0); + const char* top_options[] = {"TAR (.tar)", "ZIP (.zip)"}; + const char* bottom_options[] = {"COMPRESS", "EXIT"}; + + int num_top_options = sizeof(top_options) / sizeof(top_options[0]); + int num_bottom_options = sizeof(bottom_options) / sizeof(bottom_options[0]); + char title_buf[60]; - if (step == 0) + while (1) { - // Display title - wattron(options_win, COLOR_PAIR(31)); - mvwprintw(options_win, 1, (win_width - strlen(" Compression format: ")) / 2, - " Compression format: "); - wattroff(options_win, COLOR_PAIR(31)); - - // Display top options - for (int i = 0; i < num_top_options; ++i) - { - if (i == highlight) - { - wattron(options_win, COLOR_PAIR(32) | A_BOLD); - } - else - { - wattron(options_win, COLOR_PAIR(33)); - } - mvwprintw(options_win, i + 3, (win_width - strlen(top_options[i])) / 2, " %s ", - top_options[i]); - wattroff(options_win, COLOR_PAIR(32) | COLOR_PAIR(33) | A_BOLD); - } + // Clear the window + werase(options_win); - // Display bottom options - int bottom_y = win_height - 2; - int left_x = 2; - int right_x = win_width - strlen(bottom_options[1]) - 2; + // Draw the box again + box(options_win, 0, 0); - // Left bottom option (COMPRESS) - wattron(options_win, COLOR_PAIR(33)); - mvwprintw(options_win, bottom_y, left_x, "%s", bottom_options[0]); - wattroff(options_win, COLOR_PAIR(33)); + if (step == STEP_SELECT_FORMAT) + { + // Display title + wattron(options_win, COLOR_PAIR(COMP_COLOR_TITLE)); + mvwprintw(options_win, 1, (win_width - strlen(" Compression format: ")) / 2, + " Compression format: "); + wattroff(options_win, COLOR_PAIR(COMP_COLOR_TITLE)); + + // Display top options + for (int i = 0; i < num_top_options; ++i) + { + if (i == highlight) + { + wattron(options_win, COLOR_PAIR(COMP_COLOR_HIGHLIGHT) | A_BOLD); + } + else + { + wattron(options_win, COLOR_PAIR(COMP_COLOR_NORMAL)); + } + mvwprintw(options_win, i + 3, (win_width - strlen(top_options[i])) / 2, " %s ", + top_options[i]); + wattroff(options_win, COLOR_PAIR(COMP_COLOR_HIGHLIGHT) | COLOR_PAIR(COMP_COLOR_NORMAL) | A_BOLD); + } - // Right bottom option (EXIT) - wattron(options_win, COLOR_PAIR(33)); - mvwprintw(options_win, bottom_y, right_x, "%s", bottom_options[1]); - wattroff(options_win, COLOR_PAIR(33)); + // Display bottom options + int bottom_y = win_height - 2; + int left_x = 2; + int right_x = win_width - strlen(bottom_options[1]) - 2; - // Refresh and wait for user input - wrefresh(options_win); - c = wgetch(options_win); + // Left bottom option (COMPRESS) + wattron(options_win, COLOR_PAIR(COMP_COLOR_NORMAL)); + mvwprintw(options_win, bottom_y, left_x, "%s", bottom_options[0]); + wattroff(options_win, COLOR_PAIR(COMP_COLOR_NORMAL)); - switch (c) - { - case KEY_UP: - if (highlight > 0) - { - highlight--; - } - break; - case KEY_DOWN: - if (highlight < num_top_options - 1) - { - highlight++; - } - break; - case 10: // Enter key - step = 1; // Move to next step - snprintf(title_buf, 60, " Select %s action: ", top_options[highlight]); - choice = highlight + 1; - highlight = num_top_options; // Set default highlight to COMPRESS - break; - case 27: // ESC key - delwin(options_win); - refresh(); // Refresh the main window to ensure no artifacts remain - return -1; - } - } - else if (step == 1) - { - // Display title - wattron(options_win, COLOR_PAIR(31)); - mvwprintw(options_win, 1, (win_width - strlen(title_buf)) / 2, title_buf); - wattroff(options_win, COLOR_PAIR(31)); + // Right bottom option (EXIT) + wattron(options_win, COLOR_PAIR(COMP_COLOR_NORMAL)); + mvwprintw(options_win, bottom_y, right_x, "%s", bottom_options[1]); + wattroff(options_win, COLOR_PAIR(COMP_COLOR_NORMAL)); - // Display top options - for (int i = 0; i < num_top_options; ++i) - { - if (i == highlight) - { - wattron(options_win, COLOR_PAIR(32) | A_BOLD); + // Refresh and wait for user input + wrefresh(options_win); + c = wgetch(options_win); + + switch (c) + { + case KEY_UP: + if (highlight > 0) + { + highlight--; + } + break; + case KEY_DOWN: + if (highlight < num_top_options - 1) + { + highlight++; + } + break; + case 10: // Enter key + step = STEP_SELECT_ACTION; // Move to next step + snprintf(title_buf, 60, " Select %s action: ", top_options[highlight]); + choice = highlight + OPTION_TAR; // Assign OPTION_TAR (1) or OPTION_ZIP (2) + highlight = num_top_options; // Set default highlight to COMPRESS + break; + case 27: // ESC key + delwin(options_win); + refresh(); // Refresh the main window to ensure no artifacts remain + return -1; + } } - else + else if (step == STEP_SELECT_ACTION) { - wattron(options_win, COLOR_PAIR(33)); - } - mvwprintw(options_win, i + 3, (win_width - strlen(top_options[i])) / 2, " %s ", - top_options[i]); - wattroff(options_win, COLOR_PAIR(32) | COLOR_PAIR(33) | A_BOLD); - } - - // Display bottom options - int bottom_y = win_height - 2; - int left_x = 2; - int right_x = win_width - strlen(bottom_options[1]) - 2; + // Display title + wattron(options_win, COLOR_PAIR(COMP_COLOR_TITLE)); + mvwprintw(options_win, 1, (win_width - strlen(title_buf)) / 2, title_buf); + wattroff(options_win, COLOR_PAIR(COMP_COLOR_TITLE)); - // Left bottom option (COMPRESS) - if (highlight == num_top_options) - { - wattron(options_win, COLOR_PAIR(32) | A_BOLD); - } - else - { - wattron(options_win, COLOR_PAIR(33)); - } - mvwprintw(options_win, bottom_y, left_x, " %s ", bottom_options[0]); - wattroff(options_win, COLOR_PAIR(32) | COLOR_PAIR(33) | A_BOLD); + // Display top options + for (int i = 0; i < num_top_options; ++i) + { + if (i == highlight) + { + wattron(options_win, COLOR_PAIR(COMP_COLOR_HIGHLIGHT) | A_BOLD); + } + else + { + wattron(options_win, COLOR_PAIR(COMP_COLOR_NORMAL)); + } + mvwprintw(options_win, i + 3, (win_width - strlen(top_options[i])) / 2, " %s ", + top_options[i]); + wattroff(options_win, COLOR_PAIR(COMP_COLOR_HIGHLIGHT) | COLOR_PAIR(COMP_COLOR_NORMAL) | A_BOLD); + } - // Right bottom option (EXIT) - if (highlight == num_top_options + 1) - { - wattron(options_win, COLOR_PAIR(32) | A_BOLD); - } - else - { - wattron(options_win, COLOR_PAIR(33)); - } - mvwprintw(options_win, bottom_y, right_x, "%s", bottom_options[1]); - wattroff(options_win, COLOR_PAIR(32) | COLOR_PAIR(33) | A_BOLD); + // Display bottom options + int bottom_y = win_height - 2; + int left_x = 2; + int right_x = win_width - strlen(bottom_options[1]) - 2; - // Refresh and wait for user input - wrefresh(options_win); - c = wgetch(options_win); + // Left bottom option (COMPRESS) + if (highlight == num_top_options) + { + wattron(options_win, COLOR_PAIR(COMP_COLOR_HIGHLIGHT) | A_BOLD); + } + else + { + wattron(options_win, COLOR_PAIR(COMP_COLOR_NORMAL)); + } + mvwprintw(options_win, bottom_y, left_x, " %s ", bottom_options[0]); + wattroff(options_win, COLOR_PAIR(COMP_COLOR_HIGHLIGHT) | COLOR_PAIR(COMP_COLOR_NORMAL) | A_BOLD); - switch (c) - { - case KEY_LEFT: - if (highlight == num_top_options + 1) - { - highlight = num_top_options; // Move to COMPRESS - } - break; - case KEY_RIGHT: - if (highlight == num_top_options) - { - highlight = num_top_options + 1; // Move to EXIT - } - break; - case 10: // Enter key - if (highlight == num_top_options) - { - // Handle compression logic - delwin(options_win); - refresh(); // Refresh the main window to ensure no artifacts remain - if (choice == 1) + // Right bottom option (EXIT) + if (highlight == num_top_options + 1) { - return 1; // return 1 (compression type: tar) + wattron(options_win, COLOR_PAIR(COMP_COLOR_HIGHLIGHT) | A_BOLD); } else { - return 2; // return 2 (compression type: zip) + wattron(options_win, COLOR_PAIR(COMP_COLOR_NORMAL)); } - } - else if (highlight == num_top_options + 1) - { - delwin(options_win); - refresh(); // Refresh the main window to ensure no artifacts remain - return 0; // Indicate "EXIT" was chosen - } - break; - case 27: // ESC key - delwin(options_win); - refresh(); // Refresh the main window to ensure no artifacts remain - return -1; - } + mvwprintw(options_win, bottom_y, right_x, "%s", bottom_options[1]); + wattroff(options_win, COLOR_PAIR(COMP_COLOR_HIGHLIGHT) | COLOR_PAIR(COMP_COLOR_NORMAL) | A_BOLD); + + // Refresh and wait for user input + wrefresh(options_win); + c = wgetch(options_win); + + switch (c) + { + case KEY_LEFT: + if (highlight == num_top_options + 1) + { + highlight = num_top_options; // Move to COMPRESS + } + break; + case KEY_RIGHT: + if (highlight == num_top_options) + { + highlight = num_top_options + 1; // Move to EXIT + } + break; + case 10: // Enter key + if (highlight == num_top_options) + { + // Handle compression logic + delwin(options_win); + refresh(); // Refresh the main window to ensure no artifacts remain + if (choice == OPTION_TAR) + { + return OPTION_TAR; // return 1 (compression type: tar) + } + else + { + return OPTION_ZIP; // return 2 (compression type: zip) + } + } + else if (highlight == num_top_options + 1) + { + delwin(options_win); + refresh(); // Refresh the main window to ensure no artifacts remain + return OPTION_EXIT; // Indicate "EXIT" was chosen + } + break; + case 27: // ESC key + delwin(options_win); + refresh(); // Refresh the main window to ensure no artifacts remain + return -1; + } + } } - } - delwin(options_win); - wrefresh(parent_win); + delwin(options_win); + wrefresh(parent_win); } void show_term_message(const char* message, int err) @@ -340,23 +340,22 @@ void init_custom_color(short color_index, int r, int g, int b) void color_pair_init() { - // Define color pairs - init_pair(1, COLOR_GREEN, COLOR_BLACK); // File color (Green) - init_pair(2, COLOR_BLUE, COLOR_BLACK); // Directory color (Blue) - init_pair(3, 167, 235); // Unextracted archives (Red) - init_pair(4, 175, 235); // Audio files (Pink) - init_pair(5, 214, 235); // Image files (yellow) - init_pair(6, 108, 235); // bright blue gruvbox type - init_pair(7, 108, 235); // aqua gruvbox - init_pair(8, 61, 234); // violet base03 - init_pair(9, 234, 230); - // init_pair(9, 235, 223); // gruvbox dark bg, white fg - init_pair(10, 125, 234); // magenta - init_pair(11, 168, COLOR_BLACK); - init_pair(12, COLOR_RED, COLOR_BLACK); // Regular color red - init_custom_color(13, 0xDC, 0x9A, 0x1F); // #BDAE93 #DC9A1F - init_pair(14, 235, 175); // ping bg, black fg - init_pair(15, 175, 175); + // Define color pairs with descriptive names + init_pair(FILE_COLOR_PAIR, COLOR_GREEN, COLOR_BLACK); // File color (Green) + init_pair(DIR_COLOR_PAIR, COLOR_BLUE, COLOR_BLACK); // Directory color (Blue) + init_pair(ARCHIVE_COLOR_PAIR, 167, 235); // Unextracted archives (Red) + init_pair(AUDIO_COLOR_PAIR, 175, 235); // Audio files (Pink) + init_pair(IMAGE_COLOR_PAIR, 214, 235); // Image files (Yellow) + init_pair(SYMLINK_COLOR_PAIR, 108, 235); // Bright blue (Gruvbox type) + init_pair(AQUA_COLOR_PAIR, 108, 235); // Aqua (Gruvbox) + init_pair(VIOLET_COLOR_PAIR, 61, 234); // Violet (Base03) + init_pair(DARK_BG_COLOR_PAIR, 234, 230); // Dark background, light foreground + init_pair(MAGENTA_COLOR_PAIR, 125, 234); // Magenta + init_pair(SPECIAL_COLOR_PAIR, 168, COLOR_BLACK); // Special color (e.g., Orange) + init_pair(ERROR_COLOR_PAIR, COLOR_RED, COLOR_BLACK); // Error messages (Red) + init_custom_color(CUSTOM_COLOR_PAIR, 0xDC, 0x9A, 0x1F); // Custom color (#DC9A1F) + init_pair(TITLE_COLOR_PAIR, 235, 175); // Pink background, black foreground + init_pair(HIGHLIGHT_COLOR_PAIR, 175, 175); // Highlight color } int confirm_action(WINDOW* win, const char* message) diff --git a/src/filepreview.c b/src/filepreview.c index d631b8d..e283ee1 100644 --- a/src/filepreview.c +++ b/src/filepreview.c @@ -44,7 +44,7 @@ const char* get_file_extension(const char* filename) const char* determine_file_type(const char* filename) { static char file_type[MAX_FILE_TYPE_LENGTH]; - char *command; + char* command; // Construct the command to run the 'file' command with the provided filename asprintf(&command, "file --brief --mime-type \"%s\"", filename); @@ -217,9 +217,9 @@ void display_file(WINDOW* info_win, const char* filename) { strcpy(sanitizedCurPath, filename); } - wattron(info_win, A_BOLD | COLOR_PAIR(9)); + wattron(info_win, A_BOLD | COLOR_PAIR(DARK_BG_COLOR_PAIR)); print_limited(info_win, 1, 1, sanitizedCurPath); - wattroff(info_win, A_BOLD | COLOR_PAIR(9)); + wattroff(info_win, A_BOLD | COLOR_PAIR(DARK_BG_COLOR_PAIR)); // Initialize color pairs for syntax highlighting start_color(); @@ -516,7 +516,7 @@ void launch_env_var(WINDOW* win, const char* current_path, const char* filename, void print_permissions(WINDOW* info_win, struct stat* file_stat) { - wattron(info_win, COLOR_PAIR(4)); + wattron(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); wprintw(info_win, (S_ISDIR(file_stat->st_mode)) ? "d" : "-"); wprintw(info_win, (file_stat->st_mode & S_IRUSR) ? "r" : "-"); wprintw(info_win, (file_stat->st_mode & S_IWUSR) ? "w" : "-"); @@ -527,7 +527,7 @@ void print_permissions(WINDOW* info_win, struct stat* file_stat) wprintw(info_win, (file_stat->st_mode & S_IROTH) ? "r" : "-"); wprintw(info_win, (file_stat->st_mode & S_IWOTH) ? "w" : "-"); wprintw(info_win, (file_stat->st_mode & S_IXOTH) ? "x" : "-"); - wattroff(info_win, COLOR_PAIR(4)); + wattroff(info_win, COLOR_PAIR(AUDIO_COLOR_PAIR)); } /* @@ -585,14 +585,14 @@ void display_archive_contents(WINDOW* info_win, const char* full_path, const cha } // Construct the command - /* + /* * Using ASPRINTF: * - * ASPRINTF IS THE GNU VERSION OF SPRINTF + * ASPRINTF IS THE GNU VERSION OF SPRINTF * - * IT DYNAMICALLY ALLOCATES MEMORY BASED ON THE INPUT STRING TO AVOID OVERFLOWS + * IT DYNAMICALLY ALLOCATES MEMORY BASED ON THE INPUT STRING TO AVOID OVERFLOWS * - * SAFER TO USE ASPRINTF OVER SPRINTF AND SNPRINTF + * SAFER TO USE ASPRINTF OVER SPRINTF AND SNPRINTF * */ char* cmd;