ui: window: file list init
This commit is contained in:
@@ -71,3 +71,4 @@ build
|
|||||||
Downloads
|
Downloads
|
||||||
|
|
||||||
deps.mk
|
deps.mk
|
||||||
|
src/deps.mk
|
||||||
@@ -52,6 +52,8 @@ int main(int argc, char **argv) {
|
|||||||
app->query_args->state = S_WAIT_SERVER;
|
app->query_args->state = S_WAIT_SERVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app->query_args->sd = app->params->sd;
|
||||||
|
|
||||||
query_loop(app);
|
query_loop(app);
|
||||||
clear_params(¶ms);
|
clear_params(¶ms);
|
||||||
destroy_app(app);
|
destroy_app(app);
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ void query_loop(app_t *app) {
|
|||||||
query_args_t *query_args = app->query_args;
|
query_args_t *query_args = app->query_args;
|
||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
int32_t sd = app->params->sd;
|
int32_t sd = app->params->sd;
|
||||||
app->query_args->sd = app->params->sd;
|
|
||||||
size_t qlen;
|
size_t qlen;
|
||||||
int sr;
|
int sr;
|
||||||
static file_args_t file_args;
|
static file_args_t file_args;
|
||||||
|
|||||||
+34
-19
@@ -6,6 +6,7 @@
|
|||||||
// #include "modals/server_message.h"
|
// #include "modals/server_message.h"
|
||||||
// #include "action.h"
|
// #include "action.h"
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -13,42 +14,45 @@
|
|||||||
void ac_file(WINDOW *win, int is_action_w);
|
void ac_file(WINDOW *win, int is_action_w);
|
||||||
|
|
||||||
app_t *init_app() {
|
app_t *init_app() {
|
||||||
// get values from terminal size
|
/* get values from terminal size */
|
||||||
int y_max, x_max;
|
int y_max, x_max;
|
||||||
getmaxyx(stdscr, y_max, x_max);
|
getmaxyx(stdscr, y_max, x_max);
|
||||||
|
|
||||||
// allocate app struct memory
|
/* allocate app struct memory */
|
||||||
app_t *_app = calloc(1, sizeof(app_t));
|
app_t *_app = calloc(1, sizeof(app_t));
|
||||||
|
|
||||||
// associate values for screen size
|
/* associate values for screen size */
|
||||||
_app->coordinates.max_x = _app->coordinates.cur_x = x_max;
|
_app->coordinates.max_x = _app->coordinates.cur_x = x_max;
|
||||||
_app->coordinates.max_y = _app->coordinates.cur_y = y_max;
|
_app->coordinates.max_y = _app->coordinates.cur_y = y_max;
|
||||||
|
|
||||||
_app->win = newwin(_app->coordinates.cur_y, _app->coordinates.cur_x, 0, 0);
|
_app->win = newwin(_app->coordinates.cur_y, _app->coordinates.cur_x, 0, 0);
|
||||||
|
|
||||||
// define the width for each sub window
|
/* define the width for each sub window */
|
||||||
int menu_w_x = x_max / 6;
|
int32_t left_w_x = x_max / 3;
|
||||||
int action_w_x = x_max - menu_w_x - 2;
|
int32_t right_w_x = x_max - left_w_x - 2;
|
||||||
|
|
||||||
// create the menu window
|
/* create the menu window */
|
||||||
_app->left_win = newwin(y_max - 4, menu_w_x, 2, 1);
|
_app->left_win = newwin(y_max - 4, left_w_x, 2, 1);
|
||||||
|
|
||||||
// create the action window
|
/* create the action window */
|
||||||
_app->right_win = newwin(y_max - 4, action_w_x, 2, menu_w_x + 1);
|
_app->right_win = newwin(y_max - 4, right_w_x, 2, left_w_x + 1);
|
||||||
|
|
||||||
// dialogue
|
/* dialogue */
|
||||||
_app->modal.win = NULL;
|
_app->modal.win = NULL;
|
||||||
_app->modal.is_initiated = 0;
|
_app->modal.is_initiated = 0;
|
||||||
|
|
||||||
// print decorative bars
|
/* default win */
|
||||||
|
_app->active_win = aw_left;
|
||||||
|
|
||||||
|
/* print decorative bars */
|
||||||
print_bars(_app);
|
print_bars(_app);
|
||||||
|
|
||||||
// here goes box borders
|
/* here goes box borders */
|
||||||
draw_borders(_app);
|
draw_borders(_app);
|
||||||
|
|
||||||
keypad(_app->win, TRUE);
|
keypad(_app->win, TRUE);
|
||||||
|
|
||||||
// refresh the windows
|
/* refresh the windows */
|
||||||
wnoutrefresh(_app->win);
|
wnoutrefresh(_app->win);
|
||||||
wnoutrefresh(_app->left_win);
|
wnoutrefresh(_app->left_win);
|
||||||
wnoutrefresh(_app->right_win);
|
wnoutrefresh(_app->right_win);
|
||||||
@@ -70,15 +74,17 @@ void init_nc() {
|
|||||||
start_color();
|
start_color();
|
||||||
init_pair(1, COLOR_RED, COLOR_BLACK);
|
init_pair(1, COLOR_RED, COLOR_BLACK);
|
||||||
init_pair(2, COLOR_GREEN, COLOR_BLACK);
|
init_pair(2, COLOR_GREEN, COLOR_BLACK);
|
||||||
init_pair(MODAL_COLOR_PAIR, COLOR_BLUE, COLOR_WHITE);
|
init_pair(modal_color_pair, COLOR_BLUE, COLOR_WHITE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_borders(app_t *app) {
|
void draw_borders(app_t *app) {
|
||||||
clear();
|
clear();
|
||||||
box(app->win, 0, 0);
|
box(app->win, 0, 0);
|
||||||
|
box(app->left_win, 0, 0);
|
||||||
|
box(app->right_win, 0, 0);
|
||||||
|
|
||||||
// refresh the windows
|
/* refresh the windows */
|
||||||
wnoutrefresh(app->win);
|
wnoutrefresh(app->win);
|
||||||
wnoutrefresh(app->left_win);
|
wnoutrefresh(app->left_win);
|
||||||
wnoutrefresh(app->right_win);
|
wnoutrefresh(app->right_win);
|
||||||
@@ -88,22 +94,31 @@ void draw_borders(app_t *app) {
|
|||||||
void print_bars(app_t *app) {
|
void print_bars(app_t *app) {
|
||||||
wattrset(app->win, A_REVERSE);
|
wattrset(app->win, A_REVERSE);
|
||||||
|
|
||||||
// print top and bottom bars
|
/* print top and bottom bars */
|
||||||
for (int i = 1; i < app->coordinates.cur_x - 1; i++) {
|
for (int i = 1; i < app->coordinates.cur_x - 1; i++) {
|
||||||
mvwprintw(app->win, 1, i, " ");
|
mvwprintw(app->win, 1, i, " ");
|
||||||
mvwprintw(app->win, app->coordinates.cur_y - 2, i, " ");
|
mvwprintw(app->win, app->coordinates.cur_y - 2, i, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// add content to the top bar
|
/* add content to the top bar */
|
||||||
mvwprintw(app->win, 1, 2, "example cprint_barsurses app | ");
|
mvwprintw(app->win, 1, 2, "example cprint_barsurses app | ");
|
||||||
mvwprintw(app->win, 1, sizeof "example cprint_barsurses app | " + 1,
|
mvwprintw(app->win, 1, sizeof "example cprint_barsurses app | " + 1,
|
||||||
"size %d, %d", app->coordinates.cur_x, app->coordinates.cur_y);
|
"size %d, %d", app->coordinates.cur_x, app->coordinates.cur_y);
|
||||||
|
|
||||||
// add content to the bottom bar
|
/* add content to the bottom bar */
|
||||||
mvwprintw(app->win, app->coordinates.cur_y - 2, 2, "F1 - Help | F9 - Quit");
|
mvwprintw(app->win, app->coordinates.cur_y - 2, 2, "F1 - Help | F9 - Quit");
|
||||||
|
|
||||||
wattroff(app->win, A_REVERSE);
|
wattroff(app->win, A_REVERSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void draw_file_list(app_t *app) {
|
||||||
|
WINDOW *win = app->left_win;
|
||||||
|
int sz_y, sz_x;
|
||||||
|
getmaxyx(win, sz_y, sz_x);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void app_refresh(app_t *app) {
|
void app_refresh(app_t *app) {
|
||||||
draw_borders(app);
|
draw_borders(app);
|
||||||
|
|
||||||
|
|||||||
+7
-6
@@ -6,15 +6,15 @@
|
|||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MODAL_COLOR_PAIR = 3,
|
modal_color_pair = 3,
|
||||||
MODAL_BORDER_COLOR_PAIR = 4,
|
modal_border_color_pair = 4,
|
||||||
} color;
|
} color;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
none = 0,
|
aw_left,
|
||||||
login = 1,
|
aw_right,
|
||||||
ask_server_addr = 2,
|
aw_modal
|
||||||
} dialogue_e;
|
} active_win_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
WINDOW *win;
|
WINDOW *win;
|
||||||
@@ -26,6 +26,7 @@ typedef struct {
|
|||||||
query_args_t *query_args;
|
query_args_t *query_args;
|
||||||
file_args_t *file_args;
|
file_args_t *file_args;
|
||||||
int32_t read_fd;
|
int32_t read_fd;
|
||||||
|
active_win_t active_win;
|
||||||
} app_t;
|
} app_t;
|
||||||
|
|
||||||
app_t *init_app();
|
app_t *init_app();
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ int32_t draw_button(button_t *btn, uint32_t active_id) {
|
|||||||
|
|
||||||
if (btn->w.id == active_id) {
|
if (btn->w.id == active_id) {
|
||||||
sprintf(title, "[< %s >]", btn->w.title);
|
sprintf(title, "[< %s >]", btn->w.title);
|
||||||
wattrset(win, COLOR_PAIR(MODAL_COLOR_PAIR) | A_BOLD | A_REVERSE);
|
wattrset(win, COLOR_PAIR(modal_color_pair) | A_BOLD | A_REVERSE);
|
||||||
} else {
|
} else {
|
||||||
sprintf(title, "[ %s ]", btn->w.title);
|
sprintf(title, "[ %s ]", btn->w.title);
|
||||||
wattrset(win, COLOR_PAIR(0) | A_REVERSE);
|
wattrset(win, COLOR_PAIR(0) | A_REVERSE);
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ int32_t draw_input(input_t *input, uint32_t active_id) {
|
|||||||
uint32_t margin_y = input->w.m_y + input->w.w_parent->m_y;
|
uint32_t margin_y = input->w.m_y + input->w.w_parent->m_y;
|
||||||
uint32_t margin_x = input->w.m_x + input->w.w_parent->m_x;
|
uint32_t margin_x = input->w.m_x + input->w.w_parent->m_x;
|
||||||
|
|
||||||
wattrset(win, COLOR_PAIR(MODAL_COLOR_PAIR));
|
wattrset(win, COLOR_PAIR(modal_color_pair));
|
||||||
|
|
||||||
mvwhline(win, margin_y, margin_x, 0, input->w.x);
|
mvwhline(win, margin_y, margin_x, 0, input->w.x);
|
||||||
mvwhline(win, margin_y + 2, margin_x, 0, input->w.x);
|
mvwhline(win, margin_y + 2, margin_x, 0, input->w.x);
|
||||||
@@ -50,7 +50,7 @@ int32_t draw_input(input_t *input, uint32_t active_id) {
|
|||||||
margin_x++;
|
margin_x++;
|
||||||
|
|
||||||
if (input->w.id == active_id) {
|
if (input->w.id == active_id) {
|
||||||
wattrset(win, COLOR_PAIR(MODAL_COLOR_PAIR) | A_BOLD | A_REVERSE);
|
wattrset(win, COLOR_PAIR(modal_color_pair) | A_BOLD | A_REVERSE);
|
||||||
} else {
|
} else {
|
||||||
wattrset(win, COLOR_PAIR(0) | A_BOLD);
|
wattrset(win, COLOR_PAIR(0) | A_BOLD);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user