Minor changes in ccc.c
This commit is contained in:
parent
4b20e61eac
commit
dd4f3cb24a
1 changed files with 21 additions and 14 deletions
35
ccc.c
35
ccc.c
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
#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);
|
||||||
unsigned int focus = 0;
|
unsigned int focus = 0;
|
||||||
int current_selection = 0;
|
int current_selection = 0;
|
||||||
char **files;
|
char **files;
|
||||||
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();
|
||||||
|
@ -120,12 +125,14 @@ 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);
|
char *filename = strdup(ep->d_name);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
@ -225,17 +232,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
|
||||||
if (active) {
|
if (active) {
|
||||||
wattroff(window, COLOR_PAIR(2));
|
wattroff(window, COLOR_PAIR(2));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue