merge with lastest commit
This commit is contained in:
commit
0699fc2200
1 changed files with 22 additions and 15 deletions
37
ccc.c
37
ccc.c
|
@ -9,7 +9,7 @@
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#define ESC 0x1B
|
#define ESC 0x1B /* \e or \033 */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
WINDOW *window;
|
WINDOW *window;
|
||||||
|
@ -29,15 +29,20 @@ void draw_border_title(WINDOW *window, bool active);
|
||||||
/* global variables */
|
/* global variables */
|
||||||
unsigned int focus = 0;
|
unsigned int focus = 0;
|
||||||
int current_selection = 0;
|
int current_selection = 0;
|
||||||
int halfx;
|
int half_width;
|
||||||
WIN_STRUCT windows[2];
|
WIN_STRUCT windows[2];
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
char cwd[PATH_MAX];
|
||||||
|
|
||||||
// check if it is interactive shell
|
// check if it is interactive shell
|
||||||
if (!isatty(STDIN_FILENO))
|
if (!isatty(STDIN_FILENO))
|
||||||
die("ccc: No tty detected. ccc requires an interactive shell to run.\n");
|
die("ccc: No tty detected. ccc requires an interactive shell to run.\n");
|
||||||
|
|
||||||
|
/* set window name */
|
||||||
|
printf("%c]2;ccc: %s%c", ESC, getcwd(cwd, sizeof(cwd)), ESC);
|
||||||
|
|
||||||
initscr();
|
initscr();
|
||||||
noecho();
|
noecho();
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
@ -56,7 +61,7 @@ int main(int argc, char** argv)
|
||||||
init_pair(2, COLOR_CYAN, COLOR_BLACK); // active color
|
init_pair(2, COLOR_CYAN, COLOR_BLACK); // active color
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
halfx = COLS / 2;
|
half_width = COLS / 2;
|
||||||
init_windows();
|
init_windows();
|
||||||
list_cwd_files();
|
list_cwd_files();
|
||||||
highlight_current_line();
|
highlight_current_line();
|
||||||
|
@ -123,13 +128,15 @@ void list_cwd_files()
|
||||||
if (dp != NULL)
|
if (dp != NULL)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while ((ep = readdir(dp)) != NULL) {
|
while ((ep = readdir(dp)) != NULL)
|
||||||
char *filename = strdup(ep->d_name); // duplicate file name to char*
|
{
|
||||||
|
char *filename = strdup(ep->d_name);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
{
|
{
|
||||||
// memory allocation failed
|
// memory allocation failed
|
||||||
perror("ccc");
|
perror("ccc");
|
||||||
exit(EXIT_FAILURE);
|
fprintf(stderr, "ccc: Cannot read filename %s.", filename);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
// can't be strncmp as that filter out dotfiles
|
// can't be strncmp as that filter out dotfiles
|
||||||
if (strcmp(filename, ".") && strcmp(ep->d_name, ".."))
|
if (strcmp(filename, ".") && strcmp(ep->d_name, ".."))
|
||||||
|
@ -201,8 +208,8 @@ void init_windows()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// create windows
|
// create windows
|
||||||
WINDOW *directory = newwin(LINES, halfx, 0, 0);
|
WINDOW *directory = newwin(LINES, half_width, 0, 0);
|
||||||
WINDOW *preview = newwin(LINES, halfx, 0, halfx);
|
WINDOW *preview = newwin(LINES, half_width, 0, half_width);
|
||||||
|
|
||||||
// draw border around windows
|
// draw border around windows
|
||||||
draw_border_title(directory, true);
|
draw_border_title(directory, true);
|
||||||
|
@ -210,11 +217,11 @@ void init_windows()
|
||||||
|
|
||||||
/* window location y, x */
|
/* window location y, x */
|
||||||
windows[0] = (WIN_STRUCT) { directory, 0, 0, 0 };
|
windows[0] = (WIN_STRUCT) { directory, 0, 0, 0 };
|
||||||
windows[1] = (WIN_STRUCT) { preview, 1, 0, halfx };
|
windows[1] = (WIN_STRUCT) { preview, 1, 0, half_width };
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* draw the border of the window depends on it is active or not
|
* Draw the border of the window depends on it is active or not
|
||||||
*/
|
*/
|
||||||
void draw_border_title(WINDOW *window, bool active)
|
void draw_border_title(WINDOW *window, bool active)
|
||||||
{
|
{
|
||||||
|
@ -226,17 +233,17 @@ void draw_border_title(WINDOW *window, bool active)
|
||||||
}
|
}
|
||||||
// draw top border
|
// draw top border
|
||||||
mvwaddch(window, 0, 0, ACS_ULCORNER); // upper left corner
|
mvwaddch(window, 0, 0, ACS_ULCORNER); // upper left corner
|
||||||
mvwhline(window, 0, 1, ACS_HLINE, halfx - 2); // top horizontal line
|
mvwhline(window, 0, 1, ACS_HLINE, half_width - 2); // top horizontal line
|
||||||
mvwaddch(window, 0, halfx - 1, ACS_URCORNER); // upper right corner
|
mvwaddch(window, 0, half_width - 1, ACS_URCORNER); // upper right corner
|
||||||
|
|
||||||
// draw side border
|
// draw side border
|
||||||
mvwvline(window, 1, 0, ACS_VLINE, LINES - 2); // left vertical line
|
mvwvline(window, 1, 0, ACS_VLINE, LINES - 2); // left vertical line
|
||||||
mvwvline(window, 1, halfx - 1, ACS_VLINE, LINES - 2); // right vertical line
|
mvwvline(window, 1, half_width - 1, ACS_VLINE, LINES - 2); // right vertical line
|
||||||
|
|
||||||
// draw bottom border
|
// draw bottom border
|
||||||
mvwaddch(window, LINES - 1, 0, ACS_LLCORNER); // lower left corner
|
mvwaddch(window, LINES - 1, 0, ACS_LLCORNER); // lower left corner
|
||||||
mvwhline(window, LINES - 1, 1, ACS_HLINE, halfx - 2); // bottom horizontal line
|
mvwhline(window, LINES - 1, 1, ACS_HLINE, half_width - 2); // bottom horizontal line
|
||||||
mvwaddch(window, LINES - 1, halfx - 1, ACS_LRCORNER); // lower right corner
|
mvwaddch(window, LINES - 1, half_width - 1, ACS_LRCORNER); // lower right corner
|
||||||
|
|
||||||
// turn color off after turning it on
|
// turn color off after turning it on
|
||||||
if (active) {
|
if (active) {
|
||||||
|
|
Loading…
Reference in a new issue