diff --git a/src/app.c b/src/app.c index 789c5c6..5f37273 100644 --- a/src/app.c +++ b/src/app.c @@ -11,10 +11,12 @@ #include #include #include +#include void ac_file(WINDOW *win, int is_action_w); app_t *app_init(app_t *app) { + app->top_text = NULL; /* get values from terminal size */ int32_t y_max, x_max; getmaxyx(stdscr, y_max, x_max); @@ -34,13 +36,6 @@ app_t *app_init(app_t *app) { app->modal.win = NULL; app->modal.is_initiated = 0; - /* print top and bottom bars */ - app->main_ui.b_keys_len = 0; - app_draw_bars(app); - - /* here goes box borders */ - app_draw_borders(app); - /* NULL to main_ui */ MAIN_UI_RESET(app); @@ -108,15 +103,17 @@ void app_draw_bars(app_t *app) { mvwprintw(app->win, app->coordinates.cur_y - 2, i, " "); } - /* add content to the top bar */ - if (app->params && app->params->is_connected) { + if (app->top_text != NULL) { + mvwaddnwstr(app->win, 1, 2, app->top_text, wcslen(app->top_text)); + } else if (app->params && app->params->is_connected) { int32_t ip_address = app->params->addr; u_char ip_addr[4]; mempcpy(ip_addr, &ip_address, 4); sprintf(top_text, "Connected to %u.%u.%u.%u, user: %s", ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3], app->params->uname); + mvwprintw(app->win, 1, 2, "%s", top_text); } - mvwprintw(app->win, 1, 2, "%s", top_text); + wattroff(app->win, A_REVERSE); /* add content to the bottom bar */ diff --git a/src/app.h b/src/app.h index 4e72f20..0b57f74 100644 --- a/src/app.h +++ b/src/app.h @@ -24,6 +24,7 @@ typedef struct { file_args_t *file_args; void (*active_callback)(w_cb_args_t *args); void *active_widget; + wchar_t *top_text; main_window_t main_ui; } app_t; diff --git a/src/main.c b/src/main.c index ce1c16c..847b872 100644 --- a/src/main.c +++ b/src/main.c @@ -44,7 +44,6 @@ int main(int argc, char **argv) { app.query_args = &q_args; main_window_set(&app, mw_fl_server); - /* init client to connect to the server */ app.params->sd = init_client(); diff --git a/src/main_dev_widget.c b/src/main_dev_widget.c index 9ab67ec..459393d 100644 --- a/src/main_dev_widget.c +++ b/src/main_dev_widget.c @@ -23,7 +23,6 @@ int32_t m_id = 0; - void mini_loop(app_t *app) { w_cb_args_t d_args = { .app = app, .element = NULL, .data = NULL, .resp_data.code = cbrc_none}; @@ -34,25 +33,24 @@ void mini_loop(app_t *app) { app_draw_modal(app); main_window_draw(app); app_refresh(app); - + FD_ZERO(&readfds); FD_SET(STDIN_FILENO, &readfds); int maxfd = STDIN_FILENO; - + int sr = select(maxfd + 1, &readfds, NULL, NULL, NULL); - + if (sr == -1) { /* perror("select"); */ exit(3); } - + if (app->main_ui.cb_b_press != NULL && app->modal.is_initiated == false) { if (ERR == app->main_ui.cb_b_press(app, &d_args)) { w_alert("error while processing user input"); } } } - } int main(void) { @@ -62,22 +60,23 @@ int main(void) { params_t params; p_file_t file; + init_query_args(&q_args, app.params); + app.params = ¶ms; app.query_args = &q_args; app.file_args = &fargs; + + app_init_nc(); + init_params(¶ms); + w_alert_init(&app); + app_init(&app); + q_args.file = &file; app.query_args->main_ui = &(app.main_ui); - file.name = "Test file #1"; params.is_connected = false; app.modal.is_initiated = false; - - app_init_nc(); - app_init(&app); - init_params(¶ms); - init_query_args(&q_args, app.params); - w_alert_init(&app); - app_init(&app); + main_window_set(&app, mw_f_desc); mini_loop(&app); exit(0); diff --git a/src/windows/main_window.c b/src/windows/main_window.c index dda4ff9..52245c7 100644 --- a/src/windows/main_window.c +++ b/src/windows/main_window.c @@ -25,6 +25,7 @@ void main_window_set(app_t *app, enum main_window_type type) { default: break; } + app_draw_bars(app); } void main_window_draw(app_t *app) { @@ -36,7 +37,7 @@ void main_window_draw(app_t *app) { w_lfl_draw((w_lfl_ui_t *)app->main_ui.ui); break; case mw_f_desc: - w_te_draw((w_te_ui_t *) app->main_ui.ui); + w_te_draw((w_te_ui_t *)app->main_ui.ui); break; } app_draw_bbar(app); @@ -51,7 +52,7 @@ void main_window_destroy(app_t *app) { w_lfl_destroy((w_lfl_ui_t **)&(app->main_ui.ui)); break; case mw_f_desc: - w_te_destroy((w_te_ui_t **) &(app->main_ui.ui)); + w_te_destroy((w_te_ui_t **)&(app->main_ui.ui)); break; } MAIN_UI_RESET(app); diff --git a/src/windows/text_edit.c b/src/windows/text_edit.c index fdef631..aa2b56c 100644 --- a/src/windows/text_edit.c +++ b/src/windows/text_edit.c @@ -7,7 +7,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -16,6 +18,8 @@ #include "text_edit.h" #include "widget_core.h" +/* TODO: create dynamic array of endline positions */ + static void w_te_cb(w_cb_args_t *args) { app_t *app = args->app; int32_t key = *((int32_t *)args->data); @@ -25,6 +29,15 @@ static void w_te_cb(w_cb_args_t *args) { case KEY_DL: fui->text[fui->text_len--] = 0; break; + case KEY_UP: + fui->cur_shift_pos.y--; + wchar_t *nl_ptr = NULL; + wchar_t *line_start = fui->text; + + break; + case KEY_DOWN: + fui->cur_shift_pos.y++; + break; default: fui->text[fui->text_len++] = key; fui->text[fui->text_len] = 0; @@ -74,6 +87,8 @@ static int32_t process_user_input(app_t *app, w_cb_args_t *d_args) { void w_te_reset_app(void *app); w_te_ui_t *w_te_init_win(app_t *app) { + wchar_t top_text[INBUFSIZE]; + int top_text_len = 0; w_te_ui_t *fui = malloc(sizeof(w_te_ui_t)); app->main_ui.ui = fui; app->main_ui.type = mw_f_desc; @@ -86,19 +101,24 @@ w_te_ui_t *w_te_init_win(app_t *app) { app->active_callback = w_te_cb; fui->w.callback = w_te_cb; w_init(&(fui->w), NULL, &(app->win), ""); - + fui->file_ptr = app->query_args->file; fui->w.sz.x = getmaxx(app->win); fui->w.sz.y = getmaxy(app->win); fui->w.parent_win = &(app->win); /* * INIT UI * */ fui->win = newwin(fui->w.sz.y - 4, fui->w.sz.x - 2, 2, 1); + top_text_len = + swprintf(top_text, INBUFSIZE, L"Description: %s", fui->file_ptr->name); + app->top_text = malloc(sizeof(wchar_t) * (top_text_len + 1)); + wcsncpy(app->top_text, top_text, top_text_len); + app->top_text[top_text_len] = 0; return fui; } void w_te_reset(w_te_ui_t *fl_ui) { fl_ui->text[0] = 0; - fl_ui->cur_pos.x = 0; - fl_ui->cur_pos.y = 0; + fl_ui->cur_shift_pos.x = 0; + fl_ui->cur_shift_pos.y = 0; fl_ui->text_len = 0; } @@ -132,20 +152,26 @@ void w_te_draw(w_te_ui_t *fui) { wchar_t *nl_ptr = wcschr(cur_ptr, '\n'); if (nl_ptr == NULL) { - mvwaddnwstr(win, p_y++, p_x, cur_ptr, fui->text_len); + mvwaddnwstr(win, p_y, p_x, cur_ptr, fui->text_len); + p_x += fui->text_len; } else { while (true) { mvwaddnwstr(win, p_y++, p_x, cur_ptr, nl_ptr - cur_ptr); cur_ptr = nl_ptr + 1; nl_ptr = wcschr(cur_ptr, '\n'); if (nl_ptr == NULL) { - mvwaddnwstr(win, p_y++, p_x, cur_ptr, wcslen(cur_ptr)); + int tlen = wcslen(cur_ptr); + mvwaddnwstr(win, p_y, p_x, cur_ptr, tlen); + p_x += tlen; break; } } } - fui->cur_pos.y = i; + fui->cur_abs_pos.y = p_y; + fui->cur_abs_pos.x = p_x; + + wmove(win, fui->cur_abs_pos.y + fui->cur_shift_pos.y, fui->cur_abs_pos.x + fui->cur_shift_pos.x); p_x = 1; diff --git a/src/windows/text_edit.h b/src/windows/text_edit.h index 6e8a529..75db0ad 100644 --- a/src/windows/text_edit.h +++ b/src/windows/text_edit.h @@ -5,29 +5,34 @@ #define W_TEXT_EDIT_H #include "../app.h" -#include -#include -#include #include +#include #include #include +#include +#include typedef struct { - w_t w; - WINDOW *win; - wchar_t text[INBUFSIZE * 10]; - int text_len; - struct { - int x; - int y; - } cur_pos; - void *file_pt; // TODO: уточнить + w_t w; + WINDOW *win; + wchar_t text[INBUFSIZE * 10]; + int text_len; + int text_cur_pos; + struct { + int x; + int y; + } cur_shift_pos; + struct { + int x; + int y; + } cur_abs_pos; + p_file_t *file_ptr; // TODO: уточнить } w_te_ui_t; -void w_te_draw(w_te_ui_t *fl_ui); -void w_te_destroy(w_te_ui_t **fui); -void w_te_reset(w_te_ui_t *fl_ui); -w_te_ui_t *w_te_init(WINDOW **win, w_t *w_parent); -w_te_ui_t *w_te_init_win(app_t *app); +void w_te_draw(w_te_ui_t *fl_ui); +void w_te_destroy(w_te_ui_t **fui); +void w_te_reset(w_te_ui_t *fl_ui); +w_te_ui_t *w_te_init(WINDOW **win, w_t *w_parent); +w_te_ui_t *w_te_init_win(app_t *app); #endif \ No newline at end of file