Compare commits

...

17 commits

9 changed files with 1277 additions and 1109 deletions

View file

@ -1,7 +1,6 @@
.POSIX: .POSIX:
.SUFFIXES: .SUFFIXES:
CC = cc
VERSION = 1.0 VERSION = 1.0
TARGET = ccc TARGET = ccc
MANPAGE = $(TARGET).1 MANPAGE = $(TARGET).1
@ -10,9 +9,9 @@ PREFIX ?= /usr/local
BINDIR = $(PREFIX)/bin BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/share/man/man1 MANDIR = $(PREFIX)/share/man/man1
# Flags LDFLAGS != pkg-config --libs libsixel
LDFLAGS = $(shell pkg-config --libs ncursesw) INCFLAGS != pkg-config --cflags libsixel
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) CFLAGS = -Os -march=native -mtune=native -pipe -s -flto -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 $(INCFLAGS)
SRC = ccc.c util.c file.c icons.c SRC = ccc.c util.c file.c icons.c
@ -35,11 +34,11 @@ install: $(TARGET)
chmod 644 $(DESTDIR)$(MANDIR)/$(MANPAGE) chmod 644 $(DESTDIR)$(MANDIR)/$(MANPAGE)
uninstall: uninstall:
$(RM) $(DESTDIR)$(BINDIR)/$(TARGET) rm $(DESTDIR)$(BINDIR)/$(TARGET)
$(RM) $(DESTDIR)$(MANDIR)/$(MANPAGE) rm $(DESTDIR)$(MANDIR)/$(MANPAGE)
clean: clean:
$(RM) $(TARGET) rm $(TARGET)
all: $(TARGET) all: $(TARGET)

View file

@ -13,17 +13,17 @@ Consider this project incomplete and WIP!
| File details | X | | | File details | X | |
| File icons! | X | | | File icons! | X | |
| Searching for files | | | | Searching for files | | |
| Sorting | | | | Sorting | X | |
| Marking and marking operations | | | | Marking and marking operations | | |
| Other operations on files | | | | Other operations on files | | |
| Image previews | | | | Image previews | X | |
| Help | X | | | Help | X | |
| History | | | | History | | |
| Bookmarks | | | | Bookmarks | | |
| Bulk rename | | | | Bulk rename | | |
## Features added that are not in [fff](https://github.com/night0721/fff): ## Features added that are not in [fff](https://github.com/night0721/fff):
- File preview (without highlighting) - File preview
# Usage # Usage
``` ```
@ -93,7 +93,6 @@ p: execute paste/move/delete/bulk_rename
``` ```
# Dependencies # Dependencies
- ncurses
- Any [Nerd Font](https://www.nerdfonts.com/) for file icons (optional, but turned on by default) - Any [Nerd Font](https://www.nerdfonts.com/) for file icons (optional, but turned on by default)
# Building # Building

984
ccc.c

File diff suppressed because it is too large Load diff

View file

@ -19,14 +19,11 @@ In COLS:
0 will make them equal (at the center), 0 will make them equal (at the center),
15 will make files bigger 15 will make files bigger
-15 will make preview bigger */ -15 will make preview bigger */
#define WINDOW_OFFSET 0 #define WINDOW_OFFSET -30
/* Options */ /* 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_HIDDEN true /* show hidden files/dotfiles at startup */
#define SHOW_DETAILS true /* show file details at startup */ #define SHOW_DETAILS false /* show file details at startup */
#define SHOW_ICONS true /* show file icons at startup */ #define SHOW_ICONS true /* show file icons at startup */
/* Calculate directories' sizes RECURSIVELY upon entering /* Calculate directories' sizes RECURSIVELY upon entering
@ -45,13 +42,29 @@ 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 /* Colros */
#define LEFT 0x104 #define GREEN "166;227;161"
#define RIGHT 0x105 #define BLUE "137;180;250"
#define BACKSPACE 0x107 #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
};

21
file.c
View file

@ -1,8 +1,6 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <libgen.h>
#include <wchar.h>
#include "util.h" #include "util.h"
#include "file.h" #include "file.h"
@ -24,8 +22,6 @@ void arraylist_free(ArrayList *list)
free(list->items[i].name); free(list->items[i].name);
if (list->items[i].path != NULL) if (list->items[i].path != NULL)
free(list->items[i].path); free(list->items[i].path);
if (list->items[i].type != NULL)
free(list->items[i].type);
if (list->items[i].stats != NULL) if (list->items[i].stats != NULL)
free(list->items[i].stats); free(list->items[i].stats);
if (list->items[i].icon != NULL) if (list->items[i].icon != NULL)
@ -60,12 +56,12 @@ void arraylist_remove(ArrayList *list, long index)
if (index >= list->length) if (index >= list->length)
return; return;
/* marked stuff doesn't work with this
free(list->items[index].name); free(list->items[index].name);
free(list->items[index].path); free(list->items[index].path);
free(list->items[index].type);
free(list->items[index].stats); free(list->items[index].stats);
free(list->items[index].icon); free(list->items[index].icon);
*/
for (long i = index; i < list->length - 1; i++) for (long i = index; i < list->length - 1; i++)
list->items[i] = list->items[i + 1]; list->items[i] = list->items[i + 1];
@ -75,10 +71,10 @@ void arraylist_remove(ArrayList *list, long index)
/* /*
* Force will not remove duplicate marked files, instead it just skip adding * Force will not remove duplicate marked files, instead it just skip adding
*/ */
void arraylist_add(ArrayList *list, char *name, char *path, char *stats, char *type, wchar_t *icon, int color, bool marked, bool force) void arraylist_add(ArrayList *list, char *name, char *path, char *stats, int type, char *icon, char color[12], bool marked, bool force)
{ {
/* name, path, stats, type, icon, color */ file new_file = { name, path, type, stats, icon };
file new_file = { name, path, type, stats, icon, color }; memcpy(new_file.color, color, 12);
if (list->capacity != list->length) { if (list->capacity != list->length) {
if (marked) { if (marked) {
@ -122,17 +118,16 @@ 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 */ length = name_len + 6; /* 4 for icon, 1 for space and 1 for null */
} }
char *line = memalloc(length * sizeof(char)); char *line = memalloc(length);
line[0] = '\0'; line[0] = '\0';
if (detail) { if (detail) {
strcat(line, file.stats); strcat(line, file.stats);
strcat(line, " "); strcat(line, " ");
} }
if (icons) { if (icons) {
char *tmp = memalloc(8 * sizeof(char)); char *tmp = memalloc(10);
snprintf(tmp, 8, "%ls", file.icon); snprintf(tmp, 10, "%s ", file.icon);
strcat(line, tmp); strcat(line, tmp);
strcat(line, " ");
free(tmp); free(tmp);
} }
strcat(line, file.name); strcat(line, file.name);

19
file.h
View file

@ -2,14 +2,25 @@
#define FILE_H_ #define FILE_H_
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
enum ftypes {
REG,
DRY, /* DIR is taken */
LNK,
CHR,
SOC,
BLK,
FIF
};
typedef struct file { typedef struct file {
char *name; /* basename */ char *name; /* basename */
char *path; /* absolute path */ char *path; /* absolute path */
char *type; int type;
char *stats; char *stats;
wchar_t *icon; char *icon;
int color; char color[12];
} file; } file;
typedef struct ArrayList { typedef struct ArrayList {
@ -22,7 +33,7 @@ ArrayList *arraylist_init(size_t capacity);
void arraylist_free(ArrayList *list); void arraylist_free(ArrayList *list);
long arraylist_search(ArrayList *list, char *filepath, bool bname); long arraylist_search(ArrayList *list, char *filepath, bool bname);
void arraylist_remove(ArrayList *list, long index); void arraylist_remove(ArrayList *list, long index);
void arraylist_add(ArrayList *list, char *filename, char *path, char *stats, char *type, wchar_t *icon, int color, bool marked, bool force); void arraylist_add(ArrayList *list, char *name, char *path, char *stats, int type, char *icon, char color[12], bool marked, bool force);
char *get_line(ArrayList *list, long index, bool detail, bool icons); char *get_line(ArrayList *list, long index, bool detail, bool icons);
#endif #endif

51
icons.c
View file

@ -2,7 +2,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <wchar.h>
#include "icons.h" #include "icons.h"
#include "util.h" #include "util.h"
@ -23,98 +22,98 @@ unsigned int hash(char *name)
return hash_value; return hash_value;
} }
void hashtable_init() void hashtable_init(void)
{ {
for (int i = 0; i < TABLE_SIZE; i++) for (int i = 0; i < TABLE_SIZE; i++)
hash_table[i] = NULL; hash_table[i] = NULL;
icon *c = memalloc(sizeof(icon)); icon *c = memalloc(sizeof(icon));
strcpy(c->name, "c"); strcpy(c->name, "c");
c->icon = L""; c->icon = "";
icon *h = memalloc(sizeof(icon)); icon *h = memalloc(sizeof(icon));
strcpy(h->name, "h"); strcpy(h->name, "h");
h->icon = L""; h->icon = "";
icon *cpp = memalloc(sizeof(icon)); icon *cpp = memalloc(sizeof(icon));
strcpy(cpp->name, "cpp"); strcpy(cpp->name, "cpp");
cpp->icon = L""; cpp->icon = "";
icon *hpp = memalloc(sizeof(icon)); icon *hpp = memalloc(sizeof(icon));
strcpy(hpp->name, "hpp"); strcpy(hpp->name, "hpp");
hpp->icon = L"󰰀"; hpp->icon = "󰰀";
icon *md = memalloc(sizeof(icon)); icon *md = memalloc(sizeof(icon));
strcpy(md->name, "md"); strcpy(md->name, "md");
md->icon = L""; md->icon = "";
icon *py = memalloc(sizeof(icon)); icon *py = memalloc(sizeof(icon));
strcpy(py->name, "py"); strcpy(py->name, "py");
py->icon = L""; py->icon = "";
icon *java = memalloc(sizeof(icon)); icon *java = memalloc(sizeof(icon));
strcpy(java->name, "java"); strcpy(java->name, "java");
java->icon = L""; java->icon = "";
icon *json = memalloc(sizeof(icon)); icon *json = memalloc(sizeof(icon));
strcpy(json->name, "json"); strcpy(json->name, "json");
json->icon = L""; json->icon = "";
icon *js = memalloc(sizeof(icon)); icon *js = memalloc(sizeof(icon));
strcpy(js->name, "js"); strcpy(js->name, "js");
js->icon = L""; js->icon = "";
icon *html = memalloc(sizeof(icon)); icon *html = memalloc(sizeof(icon));
strcpy(html->name, "html"); strcpy(html->name, "html");
html->icon = L""; html->icon = "";
icon *rs = memalloc(sizeof(icon)); icon *rs = memalloc(sizeof(icon));
strcpy(rs->name, "rs"); strcpy(rs->name, "rs");
rs->icon = L""; rs->icon = "";
icon *sh = memalloc(sizeof(icon)); icon *sh = memalloc(sizeof(icon));
strcpy(sh->name, "sh"); strcpy(sh->name, "sh");
sh->icon = L""; sh->icon = "";
icon *go = memalloc(sizeof(icon)); icon *go = memalloc(sizeof(icon));
strcpy(go->name, "go"); strcpy(go->name, "go");
go->icon = L""; go->icon = "";
icon *r = memalloc(sizeof(icon)); icon *r = memalloc(sizeof(icon));
strcpy(r->name, "r"); strcpy(r->name, "r");
r->icon = L""; r->icon = "";
icon *diff = memalloc(sizeof(icon)); icon *diff = memalloc(sizeof(icon));
strcpy(diff->name, "diff"); strcpy(diff->name, "diff");
diff->icon = L""; diff->icon = "";
icon *hs = memalloc(sizeof(icon)); icon *hs = memalloc(sizeof(icon));
strcpy(hs->name, "hs"); strcpy(hs->name, "hs");
hs->icon = L""; hs->icon = "";
icon *log = memalloc(sizeof(icon)); icon *log = memalloc(sizeof(icon));
strcpy(log->name, "log"); strcpy(log->name, "log");
log->icon = L"󱀂"; log->icon = "󱀂";
icon *rb = memalloc(sizeof(icon)); icon *rb = memalloc(sizeof(icon));
strcpy(rb->name, "rb"); strcpy(rb->name, "rb");
rb->icon = L""; rb->icon = "";
icon *iso = memalloc(sizeof(icon)); icon *iso = memalloc(sizeof(icon));
strcpy(iso->name, "iso"); strcpy(iso->name, "iso");
iso->icon = L"󰻂"; iso->icon = "󰻂";
icon *lua = memalloc(sizeof(icon)); icon *lua = memalloc(sizeof(icon));
strcpy(lua->name, "lua"); strcpy(lua->name, "lua");
lua->icon = L""; lua->icon = "";
icon *license = memalloc(sizeof(icon)); icon *license = memalloc(sizeof(icon));
strcpy(license->name, "LICENSE"); strcpy(license->name, "LICENSE");
license->icon = L""; license->icon = "";
icon *gitignore = memalloc(sizeof(icon)); icon *gitignore = memalloc(sizeof(icon));
strcpy(gitignore->name, "gitignore"); strcpy(gitignore->name, "gitignore");
gitignore->icon = L""; gitignore->icon = "";
hashtable_add(c); hashtable_add(c);
hashtable_add(h); hashtable_add(h);
@ -140,7 +139,7 @@ void hashtable_init()
hashtable_add(gitignore); hashtable_add(gitignore);
} }
void hashtable_print() void hashtable_print(void)
{ {
int i = 0; int i = 0;
@ -148,7 +147,7 @@ void hashtable_print()
if (hash_table[i] == NULL) { if (hash_table[i] == NULL) {
printf("%i. ---\n", i); printf("%i. ---\n", i);
} else { } else {
printf("%i. | Name %s | Icon %ls\n", i, hash_table[i]->name, hash_table[i]->icon); printf("%i. | Name %s | Icon %s\n", i, hash_table[i]->name, hash_table[i]->icon);
} }
} }
} }

View file

@ -2,19 +2,18 @@
#define ICONS_H_ #define ICONS_H_
#include <stdbool.h> #include <stdbool.h>
#include <wchar.h>
#define MAX_NAME 30 #define MAX_NAME 30
#define TABLE_SIZE 100 #define TABLE_SIZE 100
typedef struct { typedef struct {
char name[MAX_NAME]; char name[MAX_NAME];
wchar_t *icon; char *icon;
} icon; } icon;
unsigned int hash(char *name); unsigned int hash(char *name);
void hashtable_init(); void hashtable_init(void);
void hashtable_print(); void hashtable_print(void);
bool hashtable_add(icon *p); bool hashtable_add(icon *p);
icon *hashtable_search(char *name); icon *hashtable_search(char *name);

17
util.c
View file

@ -1,7 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <wchar.h>
void die(char *reason) void die(char *reason)
{ {
@ -21,22 +20,12 @@ void *memalloc(size_t size)
void *estrdup(void *ptr) void *estrdup(void *ptr)
{ {
void *duped = strdup(ptr); void *dup = strdup(ptr);
if (!duped) { if (!dup) {
perror("ccc"); perror("ccc");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
return duped; return dup;
}
void *ewcsdup(void *ptr)
{
void *duped = wcsdup(ptr);
if (!duped) {
perror("ccc");
exit(EXIT_FAILURE);
}
return duped;
} }
void *rememalloc(void *ptr, size_t size) void *rememalloc(void *ptr, size_t size)