Fix arrow keys, comments and indentation

This commit is contained in:
Night Kaly 2024-11-05 20:00:50 +00:00
parent 9d54946b7a
commit ece4178645
Signed by: night0721
SSH key fingerprint: SHA256:B/hgVwUoBpx5vdNsXl9w8XwZljA9766uk6T4ubZp5HM
2 changed files with 143 additions and 148 deletions

284
ccc.c
View file

@ -165,31 +165,31 @@ int main(int argc, char **argv)
run = 0; run = 0;
break; break;
/* reload using z */ /* reload */
case 'z': case 'z':
change_dir(cwd, 0, 0); change_dir(cwd, 0, 0);
break; break;
/* go back by backspace or h or left arrow */ /* go back */
case BACKSPACE: /* PASSTHROUGH */ case BACKSPACE:
case LEFT: /* PASSTHROUGH */ case ARROW_LEFT:
case 'h':; case 'h':;
/* get parent directory */ /* get parent directory */
strcpy(p_cwd, cwd); strcpy(p_cwd, cwd);
char *last_slash = strrchr(cwd, '/'); char *last_slash = strrchr(cwd, '/');
if (last_slash != NULL) { if (last_slash != NULL) {
if (last_slash == cwd) { if (last_slash == cwd) {
change_dir("/", 0, 0); change_dir("/", 0, 0);
break; break;
} }
*last_slash = '\0'; *last_slash = '\0';
change_dir(cwd, 0, 0); change_dir(cwd, 0, 0);
} }
break; break;
/* enter directory/open a file using enter or l or right arrow */ /* enter directory/open a file */
case ENTER: /* PASSTHROUGH */ case ENTER:
case RIGHT: /* PASSTHROUGH */ case ARROW_RIGHT:
case 'l': case 'l':
strcpy(p_cwd, cwd); strcpy(p_cwd, cwd);
file c_file = files->items[sel_file]; file c_file = files->items[sel_file];
@ -215,189 +215,185 @@ int main(int argc, char **argv)
} }
break; break;
/* jump up (ctrl u) */ /* jump up */
case CTRLU: case CTRLU:
if ((sel_file - JUMP_NUM) > 0) if ((sel_file - JUMP_NUM) > 0)
sel_file -= JUMP_NUM; sel_file -= JUMP_NUM;
else else
sel_file = 0; sel_file = 0;
list_files(); list_files();
break; break;
/* go up by k or up arrow */ /* go up */
case UP: /* PASSTHROUGH */ case ARROW_UP:
case 'k': case 'k':
if (sel_file > 0) if (sel_file > 0)
sel_file--; sel_file--;
list_files(); list_files();
break; break;
/* jump down (ctrl d) */ /* jump down */
case CTRLD: case CTRLD:
if ((sel_file + JUMP_NUM) < (files->length - 1)) if ((sel_file + JUMP_NUM) < (files->length - 1))
sel_file += JUMP_NUM; sel_file += JUMP_NUM;
else else
sel_file = (files->length - 1); sel_file = (files->length - 1);
list_files(); list_files();
break; break;
/* go down by j or down arrow */ /* go down */
case DOWN: /* PASSTHROUGH */ case ARROW_DOWN:
case 'j': case 'j':
if (sel_file < (files->length - 1)) if (sel_file < (files->length - 1))
sel_file++; sel_file++;
list_files(); list_files();
break; break;
/* jump to the bottom */ /* jump to the bottom */
case 'G': case 'G':
sel_file = (files->length - 1); sel_file = (files->length - 1);
list_files(); list_files();
break; break;
/* jump to the top */ /* jump to the top */
case 'g': case 'g':
ch2 = read_key(); ch2 = read_key();
switch (ch2) { switch (ch2) {
case 'g': case 'g':
sel_file = 0; sel_file = 0;
list_files(); list_files();
break; break;
default: default:
break; break;
} }
break; break;
/* '~' go to $HOME */ /* '~' go to $HOME */
case TILDE:; case TILDE:;
char *home = getenv("HOME"); char *home = getenv("HOME");
if (home == NULL) { if (home == NULL) {
wpprintw("$HOME not defined"); wpprintw("$HOME not defined");
} else { } else {
change_dir(home, 0, 0); change_dir(home, 0, 0);
} }
break; break;
/* go to the trash dir */ /* go to the trash dir */
case 't':; case 't':;
char *trash_dir = check_trash_dir(); char *trash_dir = check_trash_dir();
if (trash_dir != NULL) { if (trash_dir != NULL) {
strcpy(p_cwd, cwd); strcpy(p_cwd, cwd);
change_dir(trash_dir, 0, 0); change_dir(trash_dir, 0, 0);
} }
break; break;
/* sort files */ /* sort files */
case 'u': case 'u':
sort_files(); sort_files();
break; break;
/* show directories' sizes */ /* show directories' sizes */
case 'A': case 'A':
dirs_size = !dirs_size; dirs_size = !dirs_size;
change_dir(cwd, 0, 0); change_dir(cwd, 0, 0);
break; break;
/* go to previous dir */ /* go to previous dir */
case '-': case '-':
if (strlen(p_cwd) != 0) if (strlen(p_cwd) != 0)
change_dir(p_cwd, 0, 0); change_dir(p_cwd, 0, 0);
break; break;
/* show help */ /* show help */
case '?': case '?':
show_help(); show_help();
break; break;
/* toggle hidden files */ /* toggle hidden files */
case '.': case '.':
show_hidden = !show_hidden; show_hidden = !show_hidden;
change_dir(cwd, 0, 0); change_dir(cwd, 0, 0);
break; break;
/* toggle file details */ /* toggle file details */
case 'i': case 'i':
file_details = !file_details; file_details = !file_details;
change_dir(cwd, 0, 0); change_dir(cwd, 0, 0);
break; break;
case 'w': case 'w':
show_icons = !show_icons; show_icons = !show_icons;
change_dir(cwd, 0, 0); change_dir(cwd, 0, 0);
break; break;
case 'f': case 'f':
create_file(); create_file();
break; break;
case 'n': case 'n':
create_dir(); create_dir();
break; break;
case 'r': case 'r':
rename_file(); rename_file();
break; break;
case ':': case ':':
goto_dir(); goto_dir();
break; break;
case 'X': case 'X':
toggle_executable(); toggle_executable();
break; break;
/* mark one file */ /* mark one file */
case SPACE: case SPACE:
add_file_stat(files->items[sel_file].name, files->items[sel_file].path, 1); add_file_stat(files->items[sel_file].name, files->items[sel_file].path, 1);
list_files(); list_files();
break; break;
/* mark all files in directory */ /* mark all files in directory */
case 'a': case 'a':
change_dir(cwd, sel_file, 2); /* reload current dir */ change_dir(cwd, sel_file, 2); /* reload current dir */
break; break;
/* mark actions: */ /* mark actions: */
/* delete */ /* delete */
case 'd': case 'd':
delete_files(); delete_files();
break; break;
/* move */ /* move */
case 'm': case 'm':
if (marked->length) { if (marked->length) {
; ;
} }
break; break;
/* copy */ /* copy */
case 'c': case 'c':
if (marked->length) { if (marked->length) {
; ;
} }
break; break;
/* symbolic link */ /* symbolic link */
case 's': case 's':
if (marked->length) { if (marked->length) {
; ;
} }
break; break;
/* bulk rename */ /* bulk rename */
case 'b': case 'b':
if (marked->length) { if (marked->length) {
; ;
} }
break; break;
/* escape */
case ESC:
break;
default: default:
break; break;
@ -1246,6 +1242,10 @@ int read_key(void)
} }
} }
FILE *f = fopen("/home/night/a", "a");
fprintf(f, "c: %d\n", c);
fclose(f);
if (c == '\033') { if (c == '\033') {
char seq[3]; char seq[3];

View file

@ -42,15 +42,10 @@ In COLS:
/* Keybindings */ /* Keybindings */
#define CTRLD 0x04 #define CTRLD 0x04
#define ENTER 0xA #define ENTER 0xD
#define CTRLU 0x15 #define CTRLU 0x15
#define ESC 0x1B
#define SPACE 0x20 #define SPACE 0x20
#define TILDE 0x7E #define TILDE 0x7E
#define DOWN 0x102
#define UP 0x103
#define LEFT 0x104
#define RIGHT 0x105
/* Colros */ /* Colros */
#define GREEN "166;227;161" #define GREEN "166;227;161"