use macros for keys
This commit is contained in:
parent
bd855396be
commit
3ac8fad187
3 changed files with 34 additions and 14 deletions
4
Makefile
4
Makefile
|
@ -3,11 +3,11 @@
|
||||||
|
|
||||||
TARGET = ccc
|
TARGET = ccc
|
||||||
MANPAGE = ccc.1
|
MANPAGE = ccc.1
|
||||||
SRC = ccc.c util.c file.c
|
SRC = ccc.c util.c file.c config.h
|
||||||
|
|
||||||
# Flags
|
# Flags
|
||||||
LDFLAGS = $(shell pkg-config --libs ncurses)
|
LDFLAGS = $(shell pkg-config --libs ncurses)
|
||||||
CFLAGS = -march=native -mtune=native -O3 -pipe -O3 -s -std=c99 -pedantic $(shell pkg-config --cflags ncurses) -Wall # -Wextra -Werror
|
CFLAGS = -march=native -mtune=native -O3 -pipe -s -std=c99 -pedantic $(shell pkg-config --cflags ncurses) -Wall # -Wextra -Werror
|
||||||
CC=cc
|
CC=cc
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
CONF = config.h
|
CONF = config.h
|
||||||
|
|
34
ccc.c
34
ccc.c
|
@ -107,7 +107,7 @@ int main(int argc, char** argv)
|
||||||
die("ccc: Terminal size needs to be at least 80x24\n");
|
die("ccc: Terminal size needs to be at least 80x24\n");
|
||||||
}
|
}
|
||||||
ch = getch();
|
ch = getch();
|
||||||
/* printf("%d ",ch); */
|
printf("%d ",ch);
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
/* quit */
|
/* quit */
|
||||||
case 'q':
|
case 'q':
|
||||||
|
@ -120,8 +120,8 @@ int main(int argc, char** argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* go back by backspace or h or left arrow */
|
/* go back by backspace or h or left arrow */
|
||||||
case 127:
|
case BACKSPACE:
|
||||||
case 260:
|
case LEFT:
|
||||||
case 'h':;
|
case 'h':;
|
||||||
/* get parent directory */
|
/* get parent directory */
|
||||||
char *last_slash = strrchr(cwd, '/');
|
char *last_slash = strrchr(cwd, '/');
|
||||||
|
@ -132,8 +132,8 @@ int main(int argc, char** argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* enter directory/open a file using enter or l or right arrow */
|
/* enter directory/open a file using enter or l or right arrow */
|
||||||
case 10:
|
case ENTER:
|
||||||
case 261:
|
case RIGHT:
|
||||||
case 'l':;
|
case 'l':;
|
||||||
file *file = get_file(current_selection);
|
file *file = get_file(current_selection);
|
||||||
if (file != NULL) {
|
if (file != NULL) {
|
||||||
|
@ -153,7 +153,7 @@ int main(int argc, char** argv)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* jump up (ctrl u)*/
|
/* jump up (ctrl u)*/
|
||||||
case '\x15':
|
case CTRLU:
|
||||||
if ((current_selection - JUMP_NUM) > 0)
|
if ((current_selection - JUMP_NUM) > 0)
|
||||||
current_selection -= JUMP_NUM;
|
current_selection -= JUMP_NUM;
|
||||||
else
|
else
|
||||||
|
@ -163,7 +163,7 @@ int main(int argc, char** argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* go up by k or up arrow */
|
/* go up by k or up arrow */
|
||||||
case 259:
|
case UP:
|
||||||
case 'k':
|
case 'k':
|
||||||
if (current_selection > 0)
|
if (current_selection > 0)
|
||||||
current_selection--;
|
current_selection--;
|
||||||
|
@ -172,7 +172,7 @@ int main(int argc, char** argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* jump down (ctrl d)*/
|
/* jump down (ctrl d)*/
|
||||||
case '\x04':
|
case CTRLD:
|
||||||
if ((current_selection + JUMP_NUM) < (files_len() - 1))
|
if ((current_selection + JUMP_NUM) < (files_len() - 1))
|
||||||
current_selection += JUMP_NUM;
|
current_selection += JUMP_NUM;
|
||||||
else
|
else
|
||||||
|
@ -182,7 +182,7 @@ int main(int argc, char** argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* go down by j or down arrow */
|
/* go down by j or down arrow */
|
||||||
case 258:
|
case DOWN:
|
||||||
case 'j':
|
case 'j':
|
||||||
if (current_selection < (files_len() - 1))
|
if (current_selection < (files_len() - 1))
|
||||||
current_selection++;
|
current_selection++;
|
||||||
|
@ -210,7 +210,7 @@ int main(int argc, char** argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* ~ to go home */
|
/* ~ to go home */
|
||||||
case 126:;
|
case TILDE:;
|
||||||
char *home = getenv("HOME");
|
char *home = getenv("HOME");
|
||||||
if (home == NULL) {
|
if (home == NULL) {
|
||||||
wpprintw("$HOME is not defined");
|
wpprintw("$HOME is not defined");
|
||||||
|
@ -239,12 +239,12 @@ int main(int argc, char** argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* mark files by space */
|
/* mark files by space */
|
||||||
case 32:
|
case SPACE:
|
||||||
add_file_stat(get_filepath(current_selection), 1);
|
add_file_stat(get_filepath(current_selection), 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* escape */
|
/* escape */
|
||||||
case 27:
|
case ESC:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_RESIZE:
|
case KEY_RESIZE:
|
||||||
|
@ -440,6 +440,8 @@ long add_file_stat(char *filepath, int ftype)
|
||||||
if (ftype == 1) {
|
if (ftype == 1) {
|
||||||
long index = add_marked(filepath, type);
|
long index = add_marked(filepath, type);
|
||||||
free(type);
|
free(type);
|
||||||
|
free(size);
|
||||||
|
free(time);
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
char *total_stat = memalloc(45 * sizeof(char));
|
char *total_stat = memalloc(45 * sizeof(char));
|
||||||
|
@ -492,6 +494,14 @@ void highlight_current_line()
|
||||||
|
|
||||||
/* update the panel */
|
/* update the panel */
|
||||||
wclear(panel);
|
wclear(panel);
|
||||||
|
long num_marked = marked_len();
|
||||||
|
if (num_marked > 0) {
|
||||||
|
/* largest long is 2147483647, 10 characters
|
||||||
|
* (x selected), 11 characters */
|
||||||
|
char *selected = memalloc(21 * sizeof(char));
|
||||||
|
snprintf(selected, 21, "(selected )", num_marked);
|
||||||
|
wprintw(panel, "(%ld/%ld) %s %s", current_selection + 1, files_len(), selected, cwd);
|
||||||
|
}
|
||||||
wprintw(panel, "(%ld/%ld) %s", current_selection + 1, files_len(), cwd);
|
wprintw(panel, "(%ld/%ld) %s", current_selection + 1, files_len(), cwd);
|
||||||
}
|
}
|
||||||
/* print the actual filename and stats */
|
/* print the actual filename and stats */
|
||||||
|
|
10
config.h
10
config.h
|
@ -1,3 +1,13 @@
|
||||||
|
#define CTRLD 0x04
|
||||||
|
#define ENTER 0xA
|
||||||
|
#define CTRLU 0x15
|
||||||
#define ESC 0x1B /* \e or \033 */
|
#define ESC 0x1B /* \e or \033 */
|
||||||
|
#define SPACE 0x20
|
||||||
|
#define TILDE 0x7E
|
||||||
|
#define DOWN 0x102
|
||||||
|
#define UP 0x103
|
||||||
|
#define LEFT 0x104
|
||||||
|
#define RIGHT 0x105
|
||||||
|
#define BACKSPACE 0x107
|
||||||
#define PH 1 /* panel height */
|
#define PH 1 /* panel height */
|
||||||
#define JUMP_NUM 14 /* how long ctrl + u/d jump are */
|
#define JUMP_NUM 14 /* how long ctrl + u/d jump are */
|
||||||
|
|
Loading…
Reference in a new issue