diff --git a/TODO.md b/TODO.md index e0f9c8d..a5ed23d 100644 --- a/TODO.md +++ b/TODO.md @@ -1,11 +1,11 @@ # TODO: ## Current: -- [ ] Rewrite cancel download. Use packages and check every time for a confirmation to continue download - [ ] File upload multiline description (window) - [ ] Sorting in the file list - [ ] Resume download - [ ] Separate common structures in the common.h +- [x] Rewrite cancel download. Use packages and check every time for a confirmation to continue download - [x] Show download/upload progress in percentages - [x] Break line automatically in modal widgets - [x] Cancel upload/download diff --git a/src/connection.c b/src/connection.c index 38a4870..71cf921 100644 --- a/src/connection.c +++ b/src/connection.c @@ -31,7 +31,7 @@ bool connect_to_server(app_t *app) { return false; } app->query_args->state = S_WAIT_SERVER; - app->params->is_connected = TRUE; + app->params->is_connected = true; app->query_args->sd = app->params->sd; app_draw_bars(app); return true; diff --git a/src/windows/main_window.c b/src/windows/main_window.c index 71d5f41..dda4ff9 100644 --- a/src/windows/main_window.c +++ b/src/windows/main_window.c @@ -4,6 +4,7 @@ #include "main_window.h" #include "file_list.h" #include "fs_file_list.h" +#include "text_edit.h" void main_window_set(app_t *app, enum main_window_type type) { if (app->main_ui.ui != NULL) { @@ -19,6 +20,7 @@ void main_window_set(app_t *app, enum main_window_type type) { w_lfl_init_win(app); break; case mw_f_desc: + w_te_init_win(app); break; default: break; @@ -34,6 +36,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); break; } app_draw_bbar(app); @@ -48,6 +51,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)); break; } MAIN_UI_RESET(app); diff --git a/src/windows/text_edit.c b/src/windows/text_edit.c new file mode 100644 index 0000000..9795808 --- /dev/null +++ b/src/windows/text_edit.c @@ -0,0 +1,140 @@ +/* SPDX-License-Identifier: MIT */ +/* Copyright (c) 2026 Oleksandr Zhylin */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "text_edit.h" +#include "widget_core.h" + +static void w_te_cb(w_cb_args_t *args) { + app_t *app = args->app; + int32_t key = *((int32_t *)args->data); + w_te_ui_t *fui = app->query_args->main_ui->ui; + switch (key) { + case '\n': + // TODO: new line case + break; + case '\b': + // TODO: new line case + break; + default: + fui->text[fui->text_len++] = key; + fui->text[fui->text_len] = 0; + } +} + +static void w_te_cb_refresh(void *data) { + app_t *app = (app_t *)data; + if (app->main_ui.type != mw_f_desc) { + return; + } + w_te_ui_t *fui = app->main_ui.ui; + wnoutrefresh(fui->win); +} + +static struct action_key action_keys[] = { + {.key = "Esc", .title = "Back", .code = '\33'}, + {.key = "F9", .title = "Quit", .code = KEY_F(9)}, +}; + +static int32_t process_user_input(app_t *app, w_cb_args_t *d_args) { + int32_t c; + w_te_ui_t *fui = (w_te_ui_t *)app->query_args->main_ui->ui; + c = wgetch(app->win); + switch (c) { + case KEY_F(9): + app_destroy(app, 0); + return OK; + case 'D': + case 'd': + // case '\33': /* ESC key */ + // if (!app->modal.is_initiated) { + // server_send_string(app->query_args, "file list %d %d\n", + // fui->max_lines - 1, 1); + // main_window_set(app, mw_fl_server); + // d_args->element = app->main_ui.ui; + // break; + // } + default: + d_args->data = (void *)&c; + app->active_callback(d_args); + break; + } + return OK; +} + +void w_te_reset_app(void *app); + +w_te_ui_t *w_te_init_win(app_t *app) { + w_te_ui_t *fui = malloc(sizeof(w_te_ui_t)); + app->main_ui.ui = fui; + app->main_ui.type = mw_f_desc; + app->main_ui.cb_ui_refresh = w_te_cb_refresh; + app->main_ui.b_keys = action_keys; + app->main_ui.b_keys_len = 2; + app->main_ui.cb_b_press = (w_cb_press_t)process_user_input; + app->main_ui.reset = w_te_reset_app; + app->main_ui.draw = (draw_f_t *)w_te_draw; + app->active_callback = w_te_cb; + fui->w.callback = w_te_cb; + w_init(&(fui->w), NULL, &(app->win), ""); + + fui->w.sz.x = getmaxx(app->win); + fui->w.sz.y = getmaxy(app->win); + fui->w.parent_win = &(app->win); + /* * INIT UI * */ + + /* define the width for each sub window */ + int32_t left_w_x = app->coordinates.max_x / 10 * 5; + int32_t right_w_x = app->coordinates.max_x - left_w_x - 2; + return fui; +} + +void w_te_reset(w_te_ui_t *fl_ui) { + fl_ui->text[0] = 0; + fl_ui->scroll_pos = 0; + fl_ui->text_len = 0; +} + +void w_te_reset_app(void *app) { + app_t *_app = app; + w_te_ui_t *fl_ui = (w_te_ui_t *)_app->main_ui.ui; + w_te_reset(fl_ui); +} + +void w_te_draw(w_te_ui_t *fui) { + int32_t sz_y, sz_x; + int32_t p_y, p_x; + WINDOW *win = fui->win; + getmaxyx(win, sz_y, sz_x); + int32_t sz_y_f = sz_y - 1; // actual size (without box) + int32_t sz_x_f = sz_x - 1; // actual size (without box) + + p_y = 1; + p_x = 1; + + for (int i = 0; i < fui->w.sz.y; i++) { + mvwaddnwstr(win, p_y, p_x, fui->text + fui->w.sz.x * i, fui->w.sz.x); + } + + box(fui->win, 0, 0); + p_x = 1; + + wattroff(win, A_BOLD); + curs_set(false); +} + +void w_te_destroy(w_te_ui_t **fui) { + w_te_ui_t *f = *fui; + free(*fui); + *fui = NULL; +} \ No newline at end of file diff --git a/src/windows/text_edit.h b/src/windows/text_edit.h new file mode 100644 index 0000000..14a503d --- /dev/null +++ b/src/windows/text_edit.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: MIT */ +/* Copyright (c) 2026 Oleksandr Zhylin */ + +#ifndef W_TEXT_EDIT_H /* LOCAL FILE LIST */ +#define W_TEXT_EDIT_H + +#include "../app.h" +#include +#include +#include +#include +#include +#include + +typedef struct { + w_t w; + WINDOW *win; + wchar_t text[INBUFSIZE * 10]; + int text_len; + int scroll_pos; + void *file_pt; // 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); + +#endif \ No newline at end of file