Compare commits
No commits in common. "d67e01086c5e02146c321e7403d1c6384acbfd05" and "ec474c4704939c3e403cc675cd6ad66e1755c5cb" have entirely different histories.
d67e01086c
...
ec474c4704
9 changed files with 1107 additions and 1275 deletions
13
Makefile
13
Makefile
|
@ -1,6 +1,7 @@
|
|||
.POSIX:
|
||||
.SUFFIXES:
|
||||
|
||||
CC = cc
|
||||
VERSION = 1.0
|
||||
TARGET = ccc
|
||||
MANPAGE = $(TARGET).1
|
||||
|
@ -9,9 +10,9 @@ PREFIX ?= /usr/local
|
|||
BINDIR = $(PREFIX)/bin
|
||||
MANDIR = $(PREFIX)/share/man/man1
|
||||
|
||||
LDFLAGS != pkg-config --libs libsixel
|
||||
INCFLAGS != pkg-config --cflags libsixel
|
||||
CFLAGS = -Os -march=native -mtune=native -pipe -s -flto -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 $(INCFLAGS)
|
||||
# Flags
|
||||
LDFLAGS = $(shell pkg-config --libs ncursesw)
|
||||
CFLAGS = -O3 -march=native -mtune=native -pipe -s -flto -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 $(shell pkg-config --cflags ncursesw)
|
||||
|
||||
SRC = ccc.c util.c file.c icons.c
|
||||
|
||||
|
@ -34,11 +35,11 @@ install: $(TARGET)
|
|||
chmod 644 $(DESTDIR)$(MANDIR)/$(MANPAGE)
|
||||
|
||||
uninstall:
|
||||
rm $(DESTDIR)$(BINDIR)/$(TARGET)
|
||||
rm $(DESTDIR)$(MANDIR)/$(MANPAGE)
|
||||
$(RM) $(DESTDIR)$(BINDIR)/$(TARGET)
|
||||
$(RM) $(DESTDIR)$(MANDIR)/$(MANPAGE)
|
||||
|
||||
clean:
|
||||
rm $(TARGET)
|
||||
$(RM) $(TARGET)
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
|
|
|
@ -13,17 +13,17 @@ Consider this project incomplete and WIP!
|
|||
| File details | X | |
|
||||
| File icons! | X | |
|
||||
| Searching for files | | |
|
||||
| Sorting | X | |
|
||||
| Sorting | | |
|
||||
| Marking and marking operations | | |
|
||||
| Other operations on files | | |
|
||||
| Image previews | X | |
|
||||
| Image previews | | |
|
||||
| Help | X | |
|
||||
| History | | |
|
||||
| Bookmarks | | |
|
||||
| Bulk rename | | |
|
||||
|
||||
## Features added that are not in [fff](https://github.com/night0721/fff):
|
||||
- File preview
|
||||
- File preview (without highlighting)
|
||||
|
||||
# Usage
|
||||
```
|
||||
|
@ -93,6 +93,7 @@ p: execute paste/move/delete/bulk_rename
|
|||
```
|
||||
|
||||
# Dependencies
|
||||
- ncurses
|
||||
- Any [Nerd Font](https://www.nerdfonts.com/) for file icons (optional, but turned on by default)
|
||||
|
||||
# Building
|
||||
|
|
37
config.h
37
config.h
|
@ -19,11 +19,14 @@ In COLS:
|
|||
0 will make them equal (at the center),
|
||||
15 will make files bigger
|
||||
-15 will make preview bigger */
|
||||
#define WINDOW_OFFSET -30
|
||||
#define WINDOW_OFFSET 0
|
||||
|
||||
/* Options */
|
||||
#define DRAW_BORDERS true /* draw borders around windows */
|
||||
#define DRAW_PREVIEW true /* draw file preview */
|
||||
|
||||
#define SHOW_HIDDEN true /* show hidden files/dotfiles at startup */
|
||||
#define SHOW_DETAILS false /* show file details at startup */
|
||||
#define SHOW_DETAILS true /* show file details at startup */
|
||||
#define SHOW_ICONS true /* show file icons at startup */
|
||||
|
||||
/* Calculate directories' sizes RECURSIVELY upon entering
|
||||
|
@ -42,29 +45,13 @@ In COLS:
|
|||
|
||||
/* Keybindings */
|
||||
#define CTRLD 0x04
|
||||
#define ENTER 0xD
|
||||
#define ENTER 0xA
|
||||
#define CTRLU 0x15
|
||||
#define ESC 0x1B
|
||||
#define SPACE 0x20
|
||||
#define TILDE 0x7E
|
||||
|
||||
/* Colros */
|
||||
#define GREEN "166;227;161"
|
||||
#define BLUE "137;180;250"
|
||||
#define PINK "245;194;231"
|
||||
#define RED "243;139;168"
|
||||
#define YELLOW "249;226;175"
|
||||
#define LAVENDER "180;190;254"
|
||||
#define WHITE "205;214;244"
|
||||
|
||||
enum keys {
|
||||
BACKSPACE = 127,
|
||||
ARROW_LEFT = 1000,
|
||||
ARROW_RIGHT,
|
||||
ARROW_UP,
|
||||
ARROW_DOWN,
|
||||
DEL_KEY,
|
||||
HOME_KEY,
|
||||
END_KEY,
|
||||
PAGE_UP,
|
||||
PAGE_DOWN
|
||||
};
|
||||
#define DOWN 0x102
|
||||
#define UP 0x103
|
||||
#define LEFT 0x104
|
||||
#define RIGHT 0x105
|
||||
#define BACKSPACE 0x107
|
||||
|
|
21
file.c
21
file.c
|
@ -1,6 +1,8 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <libgen.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "file.h"
|
||||
|
@ -22,6 +24,8 @@ void arraylist_free(ArrayList *list)
|
|||
free(list->items[i].name);
|
||||
if (list->items[i].path != NULL)
|
||||
free(list->items[i].path);
|
||||
if (list->items[i].type != NULL)
|
||||
free(list->items[i].type);
|
||||
if (list->items[i].stats != NULL)
|
||||
free(list->items[i].stats);
|
||||
if (list->items[i].icon != NULL)
|
||||
|
@ -56,12 +60,12 @@ void arraylist_remove(ArrayList *list, long index)
|
|||
if (index >= list->length)
|
||||
return;
|
||||
|
||||
/* marked stuff doesn't work with this
|
||||
free(list->items[index].name);
|
||||
free(list->items[index].path);
|
||||
free(list->items[index].type);
|
||||
free(list->items[index].stats);
|
||||
free(list->items[index].icon);
|
||||
*/
|
||||
|
||||
for (long i = index; i < list->length - 1; i++)
|
||||
list->items[i] = list->items[i + 1];
|
||||
|
||||
|
@ -71,10 +75,10 @@ void arraylist_remove(ArrayList *list, long index)
|
|||
/*
|
||||
* Force will not remove duplicate marked files, instead it just skip adding
|
||||
*/
|
||||
void arraylist_add(ArrayList *list, char *name, char *path, char *stats, int type, char *icon, char color[12], bool marked, bool force)
|
||||
void arraylist_add(ArrayList *list, char *name, char *path, char *stats, char *type, wchar_t *icon, int color, bool marked, bool force)
|
||||
{
|
||||
file new_file = { name, path, type, stats, icon };
|
||||
memcpy(new_file.color, color, 12);
|
||||
/* name, path, stats, type, icon, color */
|
||||
file new_file = { name, path, type, stats, icon, color };
|
||||
|
||||
if (list->capacity != list->length) {
|
||||
if (marked) {
|
||||
|
@ -118,16 +122,17 @@ char *get_line(ArrayList *list, long index, bool detail, bool icons)
|
|||
length = name_len + 6; /* 4 for icon, 1 for space and 1 for null */
|
||||
}
|
||||
|
||||
char *line = memalloc(length);
|
||||
char *line = memalloc(length * sizeof(char));
|
||||
line[0] = '\0';
|
||||
if (detail) {
|
||||
strcat(line, file.stats);
|
||||
strcat(line, " ");
|
||||
}
|
||||
if (icons) {
|
||||
char *tmp = memalloc(10);
|
||||
snprintf(tmp, 10, "%s ", file.icon);
|
||||
char *tmp = memalloc(8 * sizeof(char));
|
||||
snprintf(tmp, 8, "%ls", file.icon);
|
||||
strcat(line, tmp);
|
||||
strcat(line, " ");
|
||||
free(tmp);
|
||||
}
|
||||
strcat(line, file.name);
|
||||
|
|
19
file.h
19
file.h
|
@ -2,25 +2,14 @@
|
|||
#define FILE_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
enum ftypes {
|
||||
REG,
|
||||
DRY, /* DIR is taken */
|
||||
LNK,
|
||||
CHR,
|
||||
SOC,
|
||||
BLK,
|
||||
FIF
|
||||
};
|
||||
|
||||
typedef struct file {
|
||||
char *name; /* basename */
|
||||
char *path; /* absolute path */
|
||||
int type;
|
||||
char *type;
|
||||
char *stats;
|
||||
char *icon;
|
||||
char color[12];
|
||||
wchar_t *icon;
|
||||
int color;
|
||||
} file;
|
||||
|
||||
typedef struct ArrayList {
|
||||
|
@ -33,7 +22,7 @@ ArrayList *arraylist_init(size_t capacity);
|
|||
void arraylist_free(ArrayList *list);
|
||||
long arraylist_search(ArrayList *list, char *filepath, bool bname);
|
||||
void arraylist_remove(ArrayList *list, long index);
|
||||
void arraylist_add(ArrayList *list, char *name, char *path, char *stats, int type, char *icon, char color[12], bool marked, bool force);
|
||||
void arraylist_add(ArrayList *list, char *filename, char *path, char *stats, char *type, wchar_t *icon, int color, bool marked, bool force);
|
||||
char *get_line(ArrayList *list, long index, bool detail, bool icons);
|
||||
|
||||
#endif
|
||||
|
|
51
icons.c
51
icons.c
|
@ -2,6 +2,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include "icons.h"
|
||||
#include "util.h"
|
||||
|
@ -22,98 +23,98 @@ unsigned int hash(char *name)
|
|||
return hash_value;
|
||||
}
|
||||
|
||||
void hashtable_init(void)
|
||||
void hashtable_init()
|
||||
{
|
||||
for (int i = 0; i < TABLE_SIZE; i++)
|
||||
hash_table[i] = NULL;
|
||||
|
||||
icon *c = memalloc(sizeof(icon));
|
||||
strcpy(c->name, "c");
|
||||
c->icon = "";
|
||||
c->icon = L"";
|
||||
|
||||
icon *h = memalloc(sizeof(icon));
|
||||
strcpy(h->name, "h");
|
||||
h->icon = "";
|
||||
h->icon = L"";
|
||||
|
||||
icon *cpp = memalloc(sizeof(icon));
|
||||
strcpy(cpp->name, "cpp");
|
||||
cpp->icon = "";
|
||||
cpp->icon = L"";
|
||||
|
||||
icon *hpp = memalloc(sizeof(icon));
|
||||
strcpy(hpp->name, "hpp");
|
||||
hpp->icon = "";
|
||||
hpp->icon = L"";
|
||||
|
||||
icon *md = memalloc(sizeof(icon));
|
||||
strcpy(md->name, "md");
|
||||
md->icon = "";
|
||||
md->icon = L"";
|
||||
|
||||
icon *py = memalloc(sizeof(icon));
|
||||
strcpy(py->name, "py");
|
||||
py->icon = "";
|
||||
py->icon = L"";
|
||||
|
||||
icon *java = memalloc(sizeof(icon));
|
||||
strcpy(java->name, "java");
|
||||
java->icon = "";
|
||||
java->icon = L"";
|
||||
|
||||
icon *json = memalloc(sizeof(icon));
|
||||
strcpy(json->name, "json");
|
||||
json->icon = "";
|
||||
json->icon = L"";
|
||||
|
||||
icon *js = memalloc(sizeof(icon));
|
||||
strcpy(js->name, "js");
|
||||
js->icon = "";
|
||||
js->icon = L"";
|
||||
|
||||
icon *html = memalloc(sizeof(icon));
|
||||
strcpy(html->name, "html");
|
||||
html->icon = "";
|
||||
html->icon = L"";
|
||||
|
||||
icon *rs = memalloc(sizeof(icon));
|
||||
strcpy(rs->name, "rs");
|
||||
rs->icon = "";
|
||||
rs->icon = L"";
|
||||
|
||||
icon *sh = memalloc(sizeof(icon));
|
||||
strcpy(sh->name, "sh");
|
||||
sh->icon = "";
|
||||
sh->icon = L"";
|
||||
|
||||
icon *go = memalloc(sizeof(icon));
|
||||
strcpy(go->name, "go");
|
||||
go->icon = "";
|
||||
go->icon = L"";
|
||||
|
||||
icon *r = memalloc(sizeof(icon));
|
||||
strcpy(r->name, "r");
|
||||
r->icon = "";
|
||||
r->icon = L"";
|
||||
|
||||
icon *diff = memalloc(sizeof(icon));
|
||||
strcpy(diff->name, "diff");
|
||||
diff->icon = "";
|
||||
diff->icon = L"";
|
||||
|
||||
icon *hs = memalloc(sizeof(icon));
|
||||
strcpy(hs->name, "hs");
|
||||
hs->icon = "";
|
||||
hs->icon = L"";
|
||||
|
||||
icon *log = memalloc(sizeof(icon));
|
||||
strcpy(log->name, "log");
|
||||
log->icon = "";
|
||||
log->icon = L"";
|
||||
|
||||
icon *rb = memalloc(sizeof(icon));
|
||||
strcpy(rb->name, "rb");
|
||||
rb->icon = "";
|
||||
rb->icon = L"";
|
||||
|
||||
icon *iso = memalloc(sizeof(icon));
|
||||
strcpy(iso->name, "iso");
|
||||
iso->icon = "";
|
||||
iso->icon = L"";
|
||||
|
||||
icon *lua = memalloc(sizeof(icon));
|
||||
strcpy(lua->name, "lua");
|
||||
lua->icon = "";
|
||||
lua->icon = L"";
|
||||
|
||||
icon *license = memalloc(sizeof(icon));
|
||||
strcpy(license->name, "LICENSE");
|
||||
license->icon = "";
|
||||
license->icon = L"";
|
||||
|
||||
icon *gitignore = memalloc(sizeof(icon));
|
||||
strcpy(gitignore->name, "gitignore");
|
||||
gitignore->icon = "";
|
||||
gitignore->icon = L"";
|
||||
|
||||
hashtable_add(c);
|
||||
hashtable_add(h);
|
||||
|
@ -139,7 +140,7 @@ void hashtable_init(void)
|
|||
hashtable_add(gitignore);
|
||||
}
|
||||
|
||||
void hashtable_print(void)
|
||||
void hashtable_print()
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
|
@ -147,7 +148,7 @@ void hashtable_print(void)
|
|||
if (hash_table[i] == NULL) {
|
||||
printf("%i. ---\n", i);
|
||||
} else {
|
||||
printf("%i. | Name %s | Icon %s\n", i, hash_table[i]->name, hash_table[i]->icon);
|
||||
printf("%i. | Name %s | Icon %ls\n", i, hash_table[i]->name, hash_table[i]->icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
7
icons.h
7
icons.h
|
@ -2,18 +2,19 @@
|
|||
#define ICONS_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#define MAX_NAME 30
|
||||
#define TABLE_SIZE 100
|
||||
|
||||
typedef struct {
|
||||
char name[MAX_NAME];
|
||||
char *icon;
|
||||
wchar_t *icon;
|
||||
} icon;
|
||||
|
||||
unsigned int hash(char *name);
|
||||
void hashtable_init(void);
|
||||
void hashtable_print(void);
|
||||
void hashtable_init();
|
||||
void hashtable_print();
|
||||
bool hashtable_add(icon *p);
|
||||
icon *hashtable_search(char *name);
|
||||
|
||||
|
|
17
util.c
17
util.c
|
@ -1,6 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
void die(char *reason)
|
||||
{
|
||||
|
@ -20,12 +21,22 @@ void *memalloc(size_t size)
|
|||
|
||||
void *estrdup(void *ptr)
|
||||
{
|
||||
void *dup = strdup(ptr);
|
||||
if (!dup) {
|
||||
void *duped = strdup(ptr);
|
||||
if (!duped) {
|
||||
perror("ccc");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return dup;
|
||||
return duped;
|
||||
}
|
||||
|
||||
void *ewcsdup(void *ptr)
|
||||
{
|
||||
void *duped = wcsdup(ptr);
|
||||
if (!duped) {
|
||||
perror("ccc");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return duped;
|
||||
}
|
||||
|
||||
void *rememalloc(void *ptr, size_t size)
|
||||
|
|
Loading…
Reference in a new issue