merge upstream
This commit is contained in:
commit
437f0e8cf5
4 changed files with 77 additions and 34 deletions
2
Makefile
2
Makefile
|
@ -36,5 +36,3 @@ uninstall:
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(TARGET)
|
$(RM) $(TARGET)
|
||||||
|
|
||||||
ccc.o: $(CONF)
|
|
||||||
|
|
52
ccc.c
52
ccc.c
|
@ -77,8 +77,15 @@ int main(int argc, char** argv)
|
||||||
start_color();
|
start_color();
|
||||||
}
|
}
|
||||||
|
|
||||||
init_pair(1, COLOR_BLUE, -1); /* foreground, background */
|
/* colors */
|
||||||
init_pair(2, COLOR_CYAN, -1); /* active color */
|
init_pair(1, COLOR_BLACK, -1); /* */
|
||||||
|
init_pair(2, COLOR_RED, -1); /* */
|
||||||
|
init_pair(3, COLOR_GREEN, -1); /* LNK */
|
||||||
|
init_pair(4, COLOR_YELLOW, -1); /* BLK */
|
||||||
|
init_pair(5, COLOR_BLUE, -1); /* DIR */
|
||||||
|
init_pair(6, COLOR_MAGENTA, -1); /* */
|
||||||
|
init_pair(7, COLOR_CYAN, -1); /* */
|
||||||
|
init_pair(8, COLOR_WHITE, -1); /* REG */
|
||||||
|
|
||||||
half_width = COLS / 2;
|
half_width = COLS / 2;
|
||||||
init_windows();
|
init_windows();
|
||||||
|
@ -258,6 +265,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
<<<<<<< HEAD
|
||||||
* change directory in window
|
* change directory in window
|
||||||
*/
|
*/
|
||||||
void change_dir(const char *buf)
|
void change_dir(const char *buf)
|
||||||
|
@ -373,7 +381,7 @@ long add_file_stat(char *filepath, int ftype)
|
||||||
if (stat(filepath, &file_stat) == -1) {
|
if (stat(filepath, &file_stat) == -1) {
|
||||||
/* can't be triggered ? */
|
/* can't be triggered ? */
|
||||||
if (errno == EACCES) {
|
if (errno == EACCES) {
|
||||||
return add_file(filepath, "", "");
|
return add_file(filepath, "", "", 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,7 +398,7 @@ long add_file_stat(char *filepath, int ftype)
|
||||||
nftw(filepath, &get_directory_size, 15, FTW_PHYS);
|
nftw(filepath, &get_directory_size, 15, FTW_PHYS);
|
||||||
bytes = total_dir_size;
|
bytes = total_dir_size;
|
||||||
}
|
}
|
||||||
/* max 25 chars due to long, space, suffix and nul */
|
/* max 25 chars due to long, space, suffix and null */
|
||||||
char *size = memalloc(25 * sizeof(char));
|
char *size = memalloc(25 * sizeof(char));
|
||||||
int unit = 0;
|
int unit = 0;
|
||||||
const char* units[] = {" B", "KiB", "MiB", "GiB", "TiB", "PiB"};
|
const char* units[] = {" B", "KiB", "MiB", "GiB", "TiB", "PiB"};
|
||||||
|
@ -401,22 +409,32 @@ long add_file_stat(char *filepath, int ftype)
|
||||||
/* 4 sig fig, limiting characters to have better format */
|
/* 4 sig fig, limiting characters to have better format */
|
||||||
sprintf(size, "%-6.4g %-3s", bytes, units[unit]);
|
sprintf(size, "%-6.4g %-3s", bytes, units[unit]);
|
||||||
|
|
||||||
/* get file type */
|
/* get file type and color */
|
||||||
char *type = memalloc(4 * sizeof(char)); /* 3 chars for type */
|
char *type = memalloc(4 * sizeof(char)); /* 4 chars for type */
|
||||||
|
int color;
|
||||||
if (S_ISDIR(file_stat.st_mode)) {
|
if (S_ISDIR(file_stat.st_mode)) {
|
||||||
strcpy(type, "DIR"); /* directory */
|
strcpy(type, "DIR"); /* directory type */
|
||||||
|
color = 5; /* blue color */
|
||||||
} else if (S_ISREG(file_stat.st_mode)) {
|
} else if (S_ISREG(file_stat.st_mode)) {
|
||||||
strcpy(type, "REG"); /* regular file */
|
strcpy(type, "REG"); /* regular file */
|
||||||
|
color = 8; /* white color */
|
||||||
} else if (S_ISLNK(file_stat.st_mode)) {
|
} else if (S_ISLNK(file_stat.st_mode)) {
|
||||||
strcpy(type, "LNK"); /* symbolic link */
|
strcpy(type, "LNK"); /* symbolic link */
|
||||||
|
color = 3; /* green color */
|
||||||
} else if (S_ISCHR(file_stat.st_mode)) {
|
} else if (S_ISCHR(file_stat.st_mode)) {
|
||||||
strcpy(type, "CHR"); /* character device */
|
strcpy(type, "CHR"); /* character device */
|
||||||
|
color = 8; /* white color */
|
||||||
} else if (S_ISSOCK(file_stat.st_mode)) {
|
} else if (S_ISSOCK(file_stat.st_mode)) {
|
||||||
strcpy(type, "SOC"); /* socket */
|
strcpy(type, "SOC"); /* socket */
|
||||||
|
color = 8; /* white color */
|
||||||
} else if (S_ISBLK(file_stat.st_mode)) {
|
} else if (S_ISBLK(file_stat.st_mode)) {
|
||||||
strcpy(type, "BLK"); /* block device */
|
strcpy(type, "BLK"); /* block device */
|
||||||
|
color = 4; /* yellow color */
|
||||||
} else if (S_ISFIFO(file_stat.st_mode)) {
|
} else if (S_ISFIFO(file_stat.st_mode)) {
|
||||||
strcpy(type, "FIF"); /* FIFO */
|
strcpy(type, "FIF"); /* FIFO */
|
||||||
|
color = 8; /* white color */
|
||||||
|
} else {
|
||||||
|
color = 8; /* white color */
|
||||||
}
|
}
|
||||||
/* don't know how to handle socket, block device, character device and FIFO */
|
/* don't know how to handle socket, block device, character device and FIFO */
|
||||||
|
|
||||||
|
@ -432,7 +450,7 @@ long add_file_stat(char *filepath, int ftype)
|
||||||
free(time);
|
free(time);
|
||||||
free(size);
|
free(size);
|
||||||
|
|
||||||
long index = add_file(filepath, total_stat, type);
|
long index = add_file(filepath, total_stat, type, color);
|
||||||
|
|
||||||
free(total_stat);
|
free(total_stat);
|
||||||
free(type);
|
free(type);
|
||||||
|
@ -472,7 +490,7 @@ void highlight_current_line()
|
||||||
for (long i = overflow; i < range; i++) {
|
for (long i = overflow; i < range; i++) {
|
||||||
if ((overflow == 0 && i == current_selection) || (overflow != 0 && i == current_selection)) {
|
if ((overflow == 0 && i == current_selection) || (overflow != 0 && i == current_selection)) {
|
||||||
wattron(directory_content, A_REVERSE);
|
wattron(directory_content, A_REVERSE);
|
||||||
wattron(directory_content, COLOR_PAIR(1));
|
wattron(directory_content, COLOR_PAIR(5));
|
||||||
|
|
||||||
/* update the panel */
|
/* update the panel */
|
||||||
wclear(panel);
|
wclear(panel);
|
||||||
|
@ -480,12 +498,18 @@ void highlight_current_line()
|
||||||
}
|
}
|
||||||
/* print the actual filename and stats */
|
/* print the actual filename and stats */
|
||||||
char *line = get_line(i);
|
char *line = get_line(i);
|
||||||
|
int color = get_color(i);
|
||||||
|
|
||||||
|
/* print the whole directory with colors */
|
||||||
|
wattron(directory_content, COLOR_PAIR(color));
|
||||||
if (overflow > 0)
|
if (overflow > 0)
|
||||||
mvwprintw(directory_content, line_count, 0, "%s", line);
|
mvwprintw(directory_content, line_count, 0, "%s", line);
|
||||||
else
|
else
|
||||||
mvwprintw(directory_content, i, 0, "%s", line);
|
mvwprintw(directory_content, i, 0, "%s", line);
|
||||||
|
|
||||||
wattroff(directory_content, A_REVERSE);
|
wattroff(directory_content, A_REVERSE);
|
||||||
wattroff(directory_content, COLOR_PAIR(1));
|
wattroff(directory_content, COLOR_PAIR(color));
|
||||||
|
wattroff(directory_content, COLOR_PAIR(5));
|
||||||
free(line);
|
free(line);
|
||||||
line_count++;
|
line_count++;
|
||||||
}
|
}
|
||||||
|
@ -595,9 +619,9 @@ void draw_border_title(WINDOW *window, bool active)
|
||||||
{
|
{
|
||||||
/* turn on color depends on active */
|
/* turn on color depends on active */
|
||||||
if (active) {
|
if (active) {
|
||||||
wattron(window, COLOR_PAIR(2));
|
wattron(window, COLOR_PAIR(7));
|
||||||
} else {
|
} else {
|
||||||
wattron(window, COLOR_PAIR(1));
|
wattron(window, COLOR_PAIR(5));
|
||||||
}
|
}
|
||||||
/* draw top border */
|
/* draw top border */
|
||||||
mvwaddch(window, 0, 0, ACS_ULCORNER); /* upper left corner */
|
mvwaddch(window, 0, 0, ACS_ULCORNER); /* upper left corner */
|
||||||
|
@ -616,9 +640,9 @@ void draw_border_title(WINDOW *window, bool active)
|
||||||
|
|
||||||
/* turn color off after turning it on */
|
/* turn color off after turning it on */
|
||||||
if (active) {
|
if (active) {
|
||||||
wattroff(window, COLOR_PAIR(2));
|
wattroff(window, COLOR_PAIR(7));
|
||||||
} else {
|
} else {
|
||||||
wattroff(window, COLOR_PAIR(1));
|
wattroff(window, COLOR_PAIR(5));
|
||||||
}
|
}
|
||||||
wrefresh(window); /* Refresh the window to see the colored border and title */
|
wrefresh(window); /* Refresh the window to see the colored border and title */
|
||||||
}
|
}
|
||||||
|
|
38
file.c
38
file.c
|
@ -9,7 +9,7 @@ typedef struct file {
|
||||||
char *path;
|
char *path;
|
||||||
char *stats;
|
char *stats;
|
||||||
char *type;
|
char *type;
|
||||||
/* put some more useful stat here */
|
int color;
|
||||||
struct file *next;
|
struct file *next;
|
||||||
} file;
|
} file;
|
||||||
|
|
||||||
|
@ -65,20 +65,24 @@ void clear_marked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long add_file(char *filepath, char *stats, char *type)
|
long add_file(char *filepath, char *stats, char *type, int color)
|
||||||
{
|
{
|
||||||
file *current = files;
|
file *current = files;
|
||||||
file *new_file = memalloc(sizeof(file));
|
file *new_file = memalloc(sizeof(file));
|
||||||
char *buf = strdup(filepath);
|
char *buf = strdup(filepath);
|
||||||
char *buf2 = strdup(stats);
|
char *buf2 = strdup(stats);
|
||||||
char *buf3 = strdup(type);
|
char *buf3 = strdup(type);
|
||||||
if (buf == NULL || buf2 == NULL || buf3 == NULL) {
|
int buf4 = color;
|
||||||
|
|
||||||
|
if (buf == NULL || buf2 == NULL || buf3 == NULL)
|
||||||
perror("ccc");
|
perror("ccc");
|
||||||
}
|
|
||||||
new_file->path = buf;
|
new_file->path = buf;
|
||||||
new_file->stats = buf2;
|
new_file->stats = buf2;
|
||||||
new_file->type = buf3;
|
new_file->type = buf3;
|
||||||
|
new_file->color = buf4;
|
||||||
new_file->next = NULL;
|
new_file->next = NULL;
|
||||||
|
|
||||||
if (current == NULL) {
|
if (current == NULL) {
|
||||||
files = new_file;
|
files = new_file;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -146,6 +150,20 @@ char *get_filepath(long index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_color(long index)
|
||||||
|
{
|
||||||
|
file *file = get_file(index);
|
||||||
|
if (file != NULL) {
|
||||||
|
int color = file->color;
|
||||||
|
if (!color) {
|
||||||
|
perror("ccc");
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
} else {
|
||||||
|
return 8; /* white */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Construct a formatted line for display
|
* Construct a formatted line for display
|
||||||
*/
|
*/
|
||||||
|
@ -154,14 +172,16 @@ char *get_line(long index)
|
||||||
file *file = get_file(index);
|
file *file = get_file(index);
|
||||||
if (file != NULL) {
|
if (file != NULL) {
|
||||||
char *name = strdup(file->path);
|
char *name = strdup(file->path);
|
||||||
name = basename(name);
|
|
||||||
char *stats = strdup(file->stats);
|
char *stats = strdup(file->stats);
|
||||||
if (name == NULL || stats == NULL) {
|
size_t length = strlen(name) + strlen(stats) + 2; /* one for space and one for null */
|
||||||
perror("ccc");
|
|
||||||
}
|
|
||||||
size_t length = strlen(name) + strlen(stats) + 2; /* one for space and one for nul */
|
|
||||||
char *line = memalloc(length * sizeof(char));
|
char *line = memalloc(length * sizeof(char));
|
||||||
|
|
||||||
|
name = basename(name);
|
||||||
|
if (name == NULL || stats == NULL)
|
||||||
|
perror("ccc");
|
||||||
|
|
||||||
snprintf(line, length, "%s %s", stats, name);
|
snprintf(line, length, "%s %s", stats, name);
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
5
file.h
5
file.h
|
@ -5,7 +5,7 @@ typedef struct file {
|
||||||
char *path;
|
char *path;
|
||||||
char *stats;
|
char *stats;
|
||||||
char *type;
|
char *type;
|
||||||
// put some more useful stat here
|
int color;
|
||||||
struct file *next;
|
struct file *next;
|
||||||
} file;
|
} file;
|
||||||
|
|
||||||
|
@ -13,10 +13,11 @@ long files_len();
|
||||||
long marked_len();
|
long marked_len();
|
||||||
void clear_files();
|
void clear_files();
|
||||||
void clear_marked();
|
void clear_marked();
|
||||||
long add_file(char *filename, char *time, char *type);
|
long add_file(char *filepath, char *stats, char *type, int color);
|
||||||
long add_marked(char *filepath, char *type);
|
long add_marked(char *filepath, char *type);
|
||||||
file *get_file(long index);
|
file *get_file(long index);
|
||||||
char *get_filepath(long index);
|
char *get_filepath(long index);
|
||||||
|
int get_color(long index);
|
||||||
char *get_line(long index);
|
char *get_line(long index);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue