From e764964a3ce88d9b89dc3f5c62bd23dc6eadf994 Mon Sep 17 00:00:00 2001 From: Alexander Zhylin Date: Wed, 13 May 2026 17:28:10 +0300 Subject: [PATCH] ui: Input: fix non-Latin letters --- .qtcreator/project.json | 6 + .qtcreator/project.json.user | 214 +++++++++++++++++++++++++++++++++ TODO.md | 6 +- src/app.c | 6 +- src/common.h | 4 +- src/file_processor.c | 18 +-- src/main.c | 2 +- src/main.h | 6 +- src/modals/login_credentials.c | 1 - src/query.c | 1 + src/server.c | 6 +- src/utils/d_array.c | 6 +- src/utils/d_array.h | 8 +- src/utils/utf8.c | 8 +- src/utils/utf8.h | 4 +- src/widget/button.c | 6 +- src/widget/button.h | 4 +- src/widget/checkbox.c | 6 +- src/widget/checkbox.h | 2 +- src/widget/dialogue.c | 12 +- src/widget/group.h | 8 +- src/widget/input.c | 41 +++++-- src/widget/input.h | 11 +- src/widget/progress_bar.c | 6 +- src/widget/progress_bar.h | 2 +- src/widget_core/widget_core.c | 44 +++---- src/widget_core/widget_core.h | 32 ++--- src/windows/file_list.c | 26 ++-- src/windows/file_list.h | 10 +- src/windows/fs_file_list.c | 6 +- 30 files changed, 377 insertions(+), 135 deletions(-) create mode 100644 .qtcreator/project.json create mode 100644 .qtcreator/project.json.user diff --git a/.qtcreator/project.json b/.qtcreator/project.json new file mode 100644 index 0000000..6bdef87 --- /dev/null +++ b/.qtcreator/project.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://download.qt.io/official_releases/qtcreator/latest/installer_source/jsonschemas/project.json", + "files.exclude": [ + ".qtcreator/project.json.user" + ] +} diff --git a/.qtcreator/project.json.user b/.qtcreator/project.json.user new file mode 100644 index 0000000..d3d43f0 --- /dev/null +++ b/.qtcreator/project.json.user @@ -0,0 +1,214 @@ + + + + + + EnvironmentId + {8f62499a-75db-4638-afeb-c6cb03c6bf59} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + true + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 0 + 80 + true + true + 1 + 0 + false + true + false + 2 + true + true + 0 + 8 + true + false + 1 + false + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + false + + + 0 + true + + true + true + Builtin.DefaultTidyAndClazy + 11 + true + + + + true + + 0 + + + + ProjectExplorer.Project.Target.0 + + Desktop + true + Desktop + Desktop + {7319c3ef-71cf-4230-8aba-dab489ab735e} + 0 + 0 + 0 + + /home/alexander/Projects/bbs-client-cli/build + + 0 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + 0 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + По умолчанию + WorkspaceProject.BuildConfiguration + 0 + 0 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + 0 + true + + + 2 + + false + -e cpu-cycles --call-graph dwarf,4096 -F 250 + /home/alexander/Projects/bbs-client-cli/build/src/zbbs-client-tui + + ProjectExplorer.CustomExecutableRunConfiguration + + true + + -h 127.0.0.1 -u zheiling --pass dobkin + true + true + true + /home/alexander/Projects/bbs-client-cli + %{RunConfig:Executable:Path} + + 1 + + 1 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + 0 + true + + + 2 + + false + -e cpu-cycles --call-graph dwarf,4096 -F 250 + /home/alexander/Projects/bbs-client-cli/build/src/zbbs-client-tui + + ProjectExplorer.CustomExecutableRunConfiguration + + true + + -h 127.0.0.1 -u zheiling --pass dobkin + true + true + true + /home/alexander/Projects/bbs-client-cli + %{RunConfig:Executable:Path} + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + Version + 22 + + diff --git a/TODO.md b/TODO.md index 53dcc00..c03a9c2 100644 --- a/TODO.md +++ b/TODO.md @@ -1,13 +1,13 @@ # TODO: ## Current: -- [ ] Input: fix non-Latin letters -- [ ] Get rid of unsigned integers +- [ ] File upload multiline description (window) +- [x] Input: fix non-Latin letters - [ ] Separate common structures in the common.h - [ ] Sorting in the file list -- [ ] File upload multiline description (window) - [ ] More intuitive navigation between nested groups (by pressing left and right buttons) - [ ] Cancel upload/download +- [x] Get rid of unsigned integers - [x] Check registration / enter server name again - [x] PageUp/PageDown key functionality in lists - [x] Permission checkboxes for file upload/edit diff --git a/src/app.c b/src/app.c index fbd6655..111cf0a 100644 --- a/src/app.c +++ b/src/app.c @@ -79,8 +79,8 @@ void app_draw_borders(app_t *app) { box(app->win, 0, 0); } -int64_t print_bottom_menu_option(WINDOW *win, char *key, char *title, int64_t y, - int64_t x, int32_t size) { +int32_t print_bottom_menu_option(WINDOW *win, char *key, char *title, int32_t y, + int32_t x, int32_t size) { int32_t key_len = 0; int32_t title_len = 0; @@ -108,7 +108,7 @@ void app_draw_bars(app_t *app) { /* add content to the top bar */ if (app->params && app->params->is_connected) { - uint32_t ip_address = app->params->addr; + 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], diff --git a/src/common.h b/src/common.h index df46617..d339357 100644 --- a/src/common.h +++ b/src/common.h @@ -7,8 +7,8 @@ #include typedef struct { - uint32_t cur_y, cur_x; - uint32_t max_y, max_x; + int32_t cur_y, cur_x; + int32_t max_y, max_x; } coordinates_t; #define MAIN_UI_RESET(app) \ diff --git a/src/file_processor.c b/src/file_processor.c index 28b15ac..8aa348e 100644 --- a/src/file_processor.c +++ b/src/file_processor.c @@ -31,10 +31,10 @@ fl_item_t *fl_select(fl_item_t *start, int num); void fl_clear(fl_item_t **start, fl_item_t **current); void file_list(file_args_t *f_args, query_args_t *q_args) { - uint32_t qlen; + int32_t qlen; char *query = NULL; static char qbuf[INBUFSIZE * 2]; - static uint32_t qbuf_used = 0; + static int32_t qbuf_used = 0; w_ui_file_list_t *fui = (w_ui_file_list_t *)q_args->main_ui->ui; w_dialogue_t *d = (w_dialogue_t *)q_args->active_dialogue; fui->start = &(f_args->l_start); @@ -46,7 +46,7 @@ void file_list(file_args_t *f_args, query_args_t *q_args) { while ((qlen = query_extract_from_buf(q_args->buf, &(q_args->buf_used), &query))) { if (!strncmp(":END:", query, sizeof(":END:") - 1)) { - sscanf(query, ":END: PAGE %u/%u COUNT: %u/%u\n", &fui->current_page, + sscanf(query, ":END: PAGE %d/%d COUNT: %d/%d\n", &fui->current_page, &fui->pages, &fui->current_count, &fui->full_count); if (d != NULL && d->is_initiated) { d->needs_update = true; @@ -108,7 +108,7 @@ int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args, int32_t idx) { void file_download(file_args_t *f_args, query_args_t *q_args) { fl_item_t *f_selected = &(f_args->f_selected); - static uint32_t it_count = 0; + static int32_t it_count = 0; static size_t it_interval = 0; if (it_interval == 0) { it_interval = (f_selected->size / INBUFSIZE / 100) * 5; /* every 1% */ @@ -118,7 +118,7 @@ void file_download(file_args_t *f_args, query_args_t *q_args) { char answer[256]; static size_t size_rest = 0; - uint32_t progress = (f_selected->size - size_rest) * 100 / f_selected->size; + int32_t progress = (f_selected->size - size_rest) * 100 / f_selected->size; w_pgb_ui_t *pb = (w_pgb_ui_t *)q_args->progress_bar; w_dialogue_t *d = (w_dialogue_t *)q_args->active_dialogue; w_ui_file_list_t *fui = (w_ui_file_list_t *)q_args->main_ui->ui; @@ -126,7 +126,7 @@ void file_download(file_args_t *f_args, query_args_t *q_args) { if (size_rest == 0) size_rest = f_selected->size; - uint32_t qlen = write(f_args->file_d, q_args->buf, q_args->buf_used); + int32_t qlen = write(f_args->file_d, q_args->buf, q_args->buf_used); if (qlen) { it_count++; if (!(it_count % it_interval)) { @@ -151,7 +151,7 @@ void file_download(file_args_t *f_args, query_args_t *q_args) { q_args->notification = malloc(strlen(answer) + 1); strcpy(q_args->notification, answer); free(f_selected->name); - server_send_string(q_args, "file list %u %u\n%n", fui->max_lines, + server_send_string(q_args, "file list %d %d\n%n", fui->max_lines, fui->current_page, &a_len); q_args->state = S_FILE_LIST; } @@ -190,14 +190,14 @@ int32_t file_upload_start(query_args_t *q_args) { } int32_t file_upload(query_args_t *q_args) { - static uint32_t it_count = 0; + static int32_t it_count = 0; static size_t it_interval = 0; if (it_interval == 0) { it_interval = (q_args->file->size / INBUFSIZE / 100) * 5; /* every 1% */ if (it_interval == 0) it_interval = 1; } - uint32_t progress = + int32_t progress = (q_args->file->size - q_args->file->rest) * 100 / q_args->file->size; w_pgb_ui_t *pb = (w_pgb_ui_t *)q_args->progress_bar; w_dialogue_t *d = (w_dialogue_t *)q_args->active_dialogue; diff --git a/src/main.c b/src/main.c index 12e3d45..bfc883f 100644 --- a/src/main.c +++ b/src/main.c @@ -21,7 +21,7 @@ #include "file_list.h" #include "query.h" -uint32_t m_id = 0; +int32_t m_id = 0; int32_t process_user_input(app_t *app, w_cb_args_t *d_args); diff --git a/src/main.h b/src/main.h index 87dd6e4..1500b1f 100644 --- a/src/main.h +++ b/src/main.h @@ -25,7 +25,7 @@ typedef struct params { char *pass; char privileges; int32_t sd; - uint32_t is_connected : 1; + int32_t is_connected : 1; } params_t; enum state { @@ -112,8 +112,8 @@ typedef struct query_args { params_t *params; struct { char *text; - uint64_t capacity; - uint64_t size; + int32_t capacity; + int32_t size; } server_message; main_window_t *main_ui; void *progress_bar; diff --git a/src/modals/login_credentials.c b/src/modals/login_credentials.c index 41dfa85..9acad5a 100644 --- a/src/modals/login_credentials.c +++ b/src/modals/login_credentials.c @@ -18,7 +18,6 @@ void init_login_credentials_modal_cb(w_cb_args_t *args) { app_t *app = args->app; w_dialogue_t *d = (w_dialogue_t *)app->active_widget; memcpy(&d_args, args, sizeof(w_cb_args_t)); - d_args.app = NULL; d_args.element = app->active_widget; w_input_t *in_name = d->g_content->elements[0].element; w_input_t *in_pass = d->g_content->elements[1].element; diff --git a/src/query.c b/src/query.c index 7569c5c..841ea4e 100644 --- a/src/query.c +++ b/src/query.c @@ -113,6 +113,7 @@ void query_loop(app_t *app) { process_query(app); } + /* process user input */ if (FD_ISSET(STDIN_FILENO, &readfds)) { if (app->main_ui.cb_b_press != NULL && app->modal.is_initiated == false) { if (ERR == app->main_ui.cb_b_press(app, &d_args)) { diff --git a/src/server.c b/src/server.c index 37a0b7c..9b89ea3 100644 --- a/src/server.c +++ b/src/server.c @@ -39,7 +39,7 @@ int server_wait_reg_confirm_cb(app_t *app, char *line, int l_len) { w_ui_file_list_t *fui = (w_ui_file_list_t *)q_args->main_ui->ui; if (!strcmp(line, "ok\n")) { - server_send_string(q_args, "file list %u %u\n", fui->max_lines, + server_send_string(q_args, "file list %d %d\n", fui->max_lines, fui->current_page); q_args->state = S_FILE_LIST; w_dialogue_destroy(&(app->modal), app); @@ -58,7 +58,7 @@ int server_wait_reg_confirm_cb(app_t *app, char *line, int l_len) { } int server_print_message_cb(app_t *app, char *line, int l_len) { - int64_t new_capacity; + int32_t new_capacity; query_args_t *q_args = app->query_args; if (q_args->server_message.text == NULL) { q_args->server_message.text = malloc(l_len + 1); @@ -140,7 +140,7 @@ int process_server_command(char *line, int l_len, app_t *app) { /* WELCOME MES */ if (!strncmp(line, "Welcome, ", ws_pos)) { - server_send_string(q_args, "file list %u %u\n", fui->max_lines, + server_send_string(q_args, "file list %d %d\n", fui->max_lines, fui->current_page); q_args->state = S_FILE_LIST; return 0; diff --git a/src/utils/d_array.c b/src/utils/d_array.c index 385ea1b..8a675c9 100644 --- a/src/utils/d_array.c +++ b/src/utils/d_array.c @@ -4,7 +4,7 @@ #include #include -void u_d_arr_ptr_init(d_array_ptr_t *arr, int64_t init_capacity) { +void u_d_arr_ptr_init(d_array_ptr_t *arr, int32_t init_capacity) { arr->capacity = init_capacity; arr->length = 0; arr->arr = malloc(sizeof(void *) * init_capacity); @@ -13,8 +13,8 @@ void u_d_arr_ptr_init(d_array_ptr_t *arr, int64_t init_capacity) { memset(arr->arr, 0, init_capacity); } -void u_d_arr_ptr_add(d_array_ptr_t *arr, void *ptr, int64_t idx) { - int64_t new_capacity = idx * 2; +void u_d_arr_ptr_add(d_array_ptr_t *arr, void *ptr, int32_t idx) { + int32_t new_capacity = idx * 2; if (idx > arr->capacity - 1) { arr->arr = realloc(arr->arr, new_capacity); memset(arr->arr+arr->capacity, 0, arr->capacity - new_capacity); diff --git a/src/utils/d_array.h b/src/utils/d_array.h index e9983c7..a486f90 100644 --- a/src/utils/d_array.h +++ b/src/utils/d_array.h @@ -3,15 +3,15 @@ /* Dynamic array of numbers */ #include typedef struct d_array_ptr_t { - int64_t capacity; - int64_t length; + int32_t capacity; + int32_t length; void **arr; void *fist_el; void *last_el; } d_array_ptr_t; -void u_d_arr_ptr_init(d_array_ptr_t *arr, int64_t init_capacity); -void u_d_arr_ptr_add(d_array_ptr_t *arr, void *ptr, int64_t idx); +void u_d_arr_ptr_init(d_array_ptr_t *arr, int32_t init_capacity); +void u_d_arr_ptr_add(d_array_ptr_t *arr, void *ptr, int32_t idx); void u_d_arr_ptr_free(d_array_ptr_t *arr); #endif \ No newline at end of file diff --git a/src/utils/utf8.c b/src/utils/utf8.c index 1ab4dc0..312f29d 100644 --- a/src/utils/utf8.c +++ b/src/utils/utf8.c @@ -26,7 +26,7 @@ const char *u_utf8_wind_n(const char *s, int n) { return _s; } -int64_t u_utf8_convert_to_wide(const char *utf8_str, +int32_t u_utf8_convert_to_wide(const char *utf8_str, wchar_t **restrict wide_str, size_t *restrict len) { // Step 1: Convert UTF-8 (MBCS) to wchar_t (wide) @@ -44,12 +44,12 @@ int64_t u_utf8_convert_to_wide(const char *utf8_str, return 0; } -int64_t u_utf8_curs_printw(WINDOW *win, int64_t *y, int64_t *x, +int32_t u_utf8_curs_printw(WINDOW *win, int32_t *y, int32_t *x, const char *utf8_str, int max_len, bool multiline) { wchar_t *wline = NULL; size_t nsize = 0; - int64_t _x = *x; - int64_t _y = *y; + int32_t _x = *x; + int32_t _y = *y; u_utf8_convert_to_wide(utf8_str, &wline, &nsize); mvwaddnwstr(win, _y, _x, wline, max_len); diff --git a/src/utils/utf8.h b/src/utils/utf8.h index b38a0c4..490b52f 100644 --- a/src/utils/utf8.h +++ b/src/utils/utf8.h @@ -7,8 +7,8 @@ const char *u_utf8_wind_n(const char *s, int n); size_t u_utf8_code_points_count(const char *s); -int64_t u_utf8_convert_to_wide(const char *utf8_str, wchar_t **restrict wide_str, +int32_t u_utf8_convert_to_wide(const char *utf8_str, wchar_t **restrict wide_str, size_t *restrict len); -int64_t u_utf8_curs_printw(WINDOW *win, int64_t *y, int64_t *x, const char* utf8_str, int max_len, bool multiline); +int32_t u_utf8_curs_printw(WINDOW *win, int32_t *y, int32_t *x, const char* utf8_str, int max_len, bool multiline); #endif \ No newline at end of file diff --git a/src/widget/button.c b/src/widget/button.c index f7e7dd3..4202ef3 100644 --- a/src/widget/button.c +++ b/src/widget/button.c @@ -21,11 +21,11 @@ w_button_t *init_button(WINDOW **win, w_t *w_parent, char *label) { return btn; } -int32_t draw_button(w_button_t *btn, uint32_t active_id) { +int32_t draw_button(w_button_t *btn, int32_t active_id) { char title[DIALOGUE_TITLE + 6]; WINDOW *win = *(btn->w.parent_win); - uint32_t margin_y = btn->w.ps.y + btn->w.m.y; - uint32_t margin_x = btn->w.ps.x + btn->w.m.x; + int32_t margin_y = btn->w.ps.y + btn->w.m.y; + int32_t margin_x = btn->w.ps.x + btn->w.m.x; w_t *w_par = btn->w.w_parent; diff --git a/src/widget/button.h b/src/widget/button.h index 5a05745..0544f2e 100644 --- a/src/widget/button.h +++ b/src/widget/button.h @@ -10,11 +10,11 @@ typedef struct { w_t w; int32_t hotkey; - uint32_t is_disabled : 1; + int32_t is_disabled : 1; } w_button_t; w_button_t *init_button(WINDOW **win, w_t *w_parent, char *label); -int32_t draw_button(w_button_t *btn, uint32_t active_id); +int32_t draw_button(w_button_t *btn, int32_t active_id); void destroy_button(w_button_t *btn); #endif diff --git a/src/widget/checkbox.c b/src/widget/checkbox.c index 918bf0c..c9c9f39 100644 --- a/src/widget/checkbox.c +++ b/src/widget/checkbox.c @@ -36,11 +36,11 @@ w_checkbox_t *w_checkbox_init(WINDOW **win, w_t *w_parent, char *label) { return cbx; } -int32_t w_checkbox_draw(w_checkbox_t *cbx, uint32_t active_id) { +int32_t w_checkbox_draw(w_checkbox_t *cbx, int32_t active_id) { char title[DIALOGUE_TITLE + 6]; WINDOW *win = *(cbx->w.parent_win); - uint32_t margin_y = cbx->w.ps.y + cbx->w.m.y; - uint32_t margin_x = cbx->w.ps.x + cbx->w.m.x; + int32_t margin_y = cbx->w.ps.y + cbx->w.m.y; + int32_t margin_x = cbx->w.ps.x + cbx->w.m.x; w_t *w_par = cbx->w.w_parent; diff --git a/src/widget/checkbox.h b/src/widget/checkbox.h index 590b8c1..c709e95 100644 --- a/src/widget/checkbox.h +++ b/src/widget/checkbox.h @@ -15,7 +15,7 @@ typedef struct { bool w_checkbox_default_key_action(w_cb_args_t *args); w_checkbox_t *w_checkbox_init(WINDOW **win, w_t *w_parent, char *label); -int32_t w_checkbox_draw(w_checkbox_t *cbx, uint32_t active_id); +int32_t w_checkbox_draw(w_checkbox_t *cbx, int32_t active_id); void w_checkbox_destroy(w_checkbox_t *cbx); #endif diff --git a/src/widget/dialogue.c b/src/widget/dialogue.c index 62c7966..e86ffe7 100644 --- a/src/widget/dialogue.c +++ b/src/widget/dialogue.c @@ -142,7 +142,7 @@ void w_dialogue_callback_default(w_cb_args_t *args) { void w_dialogue_init(w_dialogue_t *dialogue, const char title[], const char text[], coordinates_t *p_coordinates) { - uint32_t t_size = 0; + int32_t t_size = 0; dialogue->win = 0; dialogue->g_content = NULL; dialogue->w.sz.x = 0; @@ -222,12 +222,12 @@ int32_t w_dialogue_draw(w_dialogue_t *d) { w_g_el_t *ae_ptr = NULL; /* active element */ /* count dimensions */ - uint32_t x = 1; /* when uses box */ - uint32_t y = 1; /* when uses box */ + int32_t x = 1; /* when uses box */ + int32_t y = 1; /* when uses box */ /* analyze text content */ - uint32_t line_count = 0; - uint32_t line_max_len = 0; + int32_t line_count = 0; + int32_t line_max_len = 0; line_max_len = w_get_max_line_len(d->text, &line_count); y += line_count; y += 2; /* margin for text */ @@ -265,7 +265,7 @@ int32_t w_dialogue_draw(w_dialogue_t *d) { } /* title */ - const uint32_t title_mx_pos = (d->w.sz.x - strlen(d->w.title)) / 2; + const int32_t title_mx_pos = (d->w.sz.x - strlen(d->w.title)) / 2; box(d->win, 0, 0); mvwprintw(d->win, 0, title_mx_pos - 1, " "); mvwprintw(d->win, 0, title_mx_pos, "%s", d->w.title); diff --git a/src/widget/group.h b/src/widget/group.h index a0eb9e0..418f25d 100644 --- a/src/widget/group.h +++ b/src/widget/group.h @@ -13,10 +13,10 @@ typedef struct group_el_init_t { bool is_default; bool is_hidden_value; char label[DIALOGUE_TITLE]; - uint32_t length; + int32_t length; enum w_g_dir direction; union { - int64_t num; + int32_t num; } val; struct group_el_init_t *children; } w_group_el_init_t; @@ -25,8 +25,8 @@ typedef struct group_t { w_t w; w_g_el_t *elements; enum w_g_dir direction; - uint32_t count; - uint32_t first_id, last_id; + int32_t count; + int32_t first_id, last_id; struct group_t *parent_group; } w_group_t; diff --git a/src/widget/input.c b/src/widget/input.c index 753044f..0cc18ae 100644 --- a/src/widget/input.c +++ b/src/widget/input.c @@ -8,13 +8,17 @@ #include "../app.h" #include "input.h" +#include #include bool w_input_default_key_action(w_cb_args_t *args) { int32_t key = *((int32_t *)args->data); w_g_el_t *g_el = args->active_el; w_input_t *input = g_el->element; - int64_t start_pos = 0; + int32_t start_pos = 0; + wchar_t w_key[2]; + app_t *app = args->app; + char long_key[3]; switch (key) { case KEY_BACKSPACE: @@ -30,14 +34,27 @@ bool w_input_default_key_action(w_cb_args_t *args) { } break; default: + if (input->value_len == input->max_len) break; + long_key[0] = key; + if ((key & 0xC0) == 0xC0) { + long_key[1] = wgetch(app->win); + long_key[2] = '\0'; + } else { + long_key[1] = '\0'; + } + mbstowcs(w_key, (const char *)&long_key, 2); if (input->cur_pos > 0) { start_pos = input->value_len++ - input->cur_pos; memmove(input->value + start_pos + 1, input->value + start_pos, input->value_len - start_pos); input->value[start_pos] = key; + input->w_value[start_pos] = w_key[0]; } else { input->value[input->value_len++] = key; input->value[input->value_len] = '\0'; + + input->w_value[input->value_len - 1] = w_key[0]; + input->w_value[input->value_len] = '\0'; } break; } @@ -46,14 +63,14 @@ bool w_input_default_key_action(w_cb_args_t *args) { } w_input_t *w_input_init(WINDOW **win, w_t *w_parent, char *label, - uint32_t length, uint32_t is_hidden_value) { + int32_t length, int32_t is_hidden_value) { w_input_t *input = malloc(sizeof(w_input_t)); w_init(&(input->w), w_parent, win, label); input->is_disabled = 0; input->w.sz.y = 3; // with borders input->w.sz.x = length + 3; // with borders and extra space for the last element - uint32_t t_len = strlen(input->w.title) + 4; // with borders and space + int32_t t_len = strlen(input->w.title) + 4; // with borders and space if (input->w.sz.x < t_len) input->w.sz.x = t_len; input->w.ps.x = 1; @@ -65,11 +82,11 @@ w_input_t *w_input_init(WINDOW **win, w_t *w_parent, char *label, return input; } -int32_t w_input_draw(w_input_t *input, uint32_t active_id) { +int32_t w_input_draw(w_input_t *input, int32_t active_id) { const char stars[] = "*******************"; WINDOW *win = *(input->w.parent_win); - uint32_t pos_y = input->w.ps.y + input->w.m.y; - uint32_t pos_x = input->w.ps.x + input->w.m.x; + int32_t pos_y = input->w.ps.y + input->w.m.y; + int32_t pos_x = input->w.ps.x + input->w.m.x; /* counts margins of the ancestors of the same window */ w_t *w_par = input->w.w_parent; @@ -108,15 +125,19 @@ int32_t w_input_draw(w_input_t *input, uint32_t active_id) { wattrset(win, COLOR_PAIR(0) | A_BOLD); } + pos_y++; + if (input->is_hidden) { - mvwprintw(win, pos_y + 1, pos_x, "%.*s%*s", (int)input->value_len, stars, + mvwprintw(win, pos_y, pos_x, "%.*s%*s", (int)input->value_len, stars, (int)(input->w.sz.x - input->value_len - 2), ""); } else { - mvwprintw(win, pos_y + 1, pos_x, "%s%*s", input->value, - (int)(input->w.sz.x - input->value_len - 2), ""); + pos_x = 2; + mvwaddnwstr(win, pos_y, pos_x, input->w_value, input->max_len); + mvwprintw(win, pos_y, pos_x + input->value_len, "%*s", + input->w.sz.x - input->value_len - 2, ""); } - input->w.cur.y = pos_y + 1; + input->w.cur.y = pos_y; input->w.cur.x = pos_x + input->value_len - input->cur_pos; wattroff(win, A_BOLD | A_REVERSE); diff --git a/src/widget/input.h b/src/widget/input.h index f2f0310..0ebf5d3 100644 --- a/src/widget/input.h +++ b/src/widget/input.h @@ -10,18 +10,19 @@ typedef struct { w_t w; + wchar_t w_value[INPUT_TEXT]; char value[INPUT_TEXT]; - int64_t cur_pos; /* is relative to the end of a string */ - int64_t value_len; - int64_t max_len; + int32_t cur_pos; /* is relative to the end of a string */ + int32_t value_len; + int32_t max_len; bool is_disabled; bool is_hidden; } w_input_t; bool w_input_default_key_action(w_cb_args_t *args); w_input_t *w_input_init(WINDOW **win, w_t *w_parent, char *label, - uint32_t size, uint32_t is_hidden_value); -int32_t w_input_draw(w_input_t *input, uint32_t active_id); + int32_t size, int32_t is_hidden_value); +int32_t w_input_draw(w_input_t *input, int32_t active_id); void w_input_destroy(w_input_t *input); #endif \ No newline at end of file diff --git a/src/widget/progress_bar.c b/src/widget/progress_bar.c index 28b5a45..f40f5c7 100644 --- a/src/widget/progress_bar.c +++ b/src/widget/progress_bar.c @@ -20,8 +20,8 @@ w_pgb_ui_t *w_pgb_ui_init(WINDOW **win, w_t *w_parent) { void w_pgb_ui_draw(w_pgb_ui_t *pb) { WINDOW *win = *(pb->w.w_parent->parent_win); - uint32_t margin_y = pb->w.ps.y + pb->w.w_parent->ps.y; - uint32_t margin_x = pb->w.ps.x + pb->w.w_parent->ps.x + 1; + int32_t margin_y = pb->w.ps.y + pb->w.w_parent->ps.y; + int32_t margin_x = pb->w.ps.x + pb->w.w_parent->ps.x + 1; wattrset(win, COLOR_PAIR(modal_color_pair)); @@ -29,7 +29,7 @@ void w_pgb_ui_draw(w_pgb_ui_t *pb) { float procent = pb->procent; procent /= 100; - uint32_t filled_num = procent * pb->w.sz.x; + int32_t filled_num = procent * pb->w.sz.x; if (filled_num > 2) { filled_num -= 2; } diff --git a/src/widget/progress_bar.h b/src/widget/progress_bar.h index 8adcbf6..869ad74 100644 --- a/src/widget/progress_bar.h +++ b/src/widget/progress_bar.h @@ -8,7 +8,7 @@ typedef struct { w_t w; - uint32_t procent; + int32_t procent; char text[24]; } w_pgb_ui_t; diff --git a/src/widget_core/widget_core.c b/src/widget_core/widget_core.c index bba277d..41b347e 100644 --- a/src/widget_core/widget_core.c +++ b/src/widget_core/widget_core.c @@ -13,7 +13,7 @@ #include #include -extern uint32_t m_id; +extern int32_t m_id; void w_init(w_t *w, w_t *w_parent, WINDOW **win, char *title) { w->id = m_id++; @@ -35,11 +35,11 @@ void w_init(w_t *w, w_t *w_parent, WINDOW **win, char *title) { strcpy(w->title, title); } -int32_t w_get_max_line_len(const char *text, uint32_t *line_count) { - uint32_t nl_pos = 0; /* new line position */ - uint32_t c_len = 0; /* current line length */ - uint32_t m_len = 0; /* max length */ - uint32_t line_num = 1; +int32_t w_get_max_line_len(const char *text, int32_t *line_count) { + int32_t nl_pos = 0; /* new line position */ + int32_t c_len = 0; /* current line length */ + int32_t m_len = 0; /* max length */ + int32_t line_num = 1; for (int i = 0; text[i] != '\0'; i++, c_len++) { if (text[i] == '\n') { if (i - nl_pos > c_len || !m_len) { @@ -72,41 +72,41 @@ int32_t w_get_max_line_len(const char *text, uint32_t *line_count) { } */ -void PRINT_TEXT(WINDOW *win, char *l_buf, char *text, int64_t i, - int64_t c_line_len, int64_t win_width, int64_t line_v_pos, - int64_t attrs, int64_t x, int64_t max_line_len) { - int64_t utf8len = 0; +void PRINT_TEXT(WINDOW *win, char *l_buf, char *text, int32_t i, + int32_t c_line_len, int32_t win_width, int32_t line_v_pos, + int32_t attrs, int32_t x, int32_t max_line_len) { + int32_t utf8len = 0; strncpy(l_buf, text + i - c_line_len, c_line_len); l_buf[c_line_len] = '\0'; utf8len = u_utf8_code_points_count(l_buf); if ((attrs & PMT_ALIGN_CENTER) == PMT_ALIGN_CENTER) { - int64_t _x = (win_width - utf8len) / 2; + int32_t _x = (win_width - utf8len) / 2; u_utf8_curs_printw(win, &line_v_pos, &_x, l_buf, -1, false); } else if (attrs & PMT_POS_CENTER) { - int64_t _x = (win_width - max_line_len) / 2; + int32_t _x = (win_width - max_line_len) / 2; u_utf8_curs_printw(win, &line_v_pos, &_x, l_buf, -1, false); } else { u_utf8_curs_printw(win, &line_v_pos, &x, l_buf, -1, false); } } -uint32_t w_print_multiline_text(WINDOW *win, const char *_text, - const uint32_t win_width, const uint32_t y, - const uint32_t x, const uint16_t attrs) { +int32_t w_print_multiline_text(WINDOW *win, const char *_text, + const int32_t win_width, const int32_t y, + const int32_t x, const int16_t attrs) { - uint16_t line_v_pos = y; - int64_t c_line_len = 0; - int64_t m_line_len = 0; - int64_t i = 0; + int16_t line_v_pos = y; + int32_t c_line_len = 0; + int32_t m_line_len = 0; + int32_t i = 0; char l_buf[DIALOGUE_TEXT]; char *text = malloc(strlen(_text) + 1); strcpy(text, _text); - uint l_size = 0; - for (uint m = 0; text[m] != '\0'; m++) { + int l_size = 0; + for (int m = 0; text[m] != '\0'; m++) { if (text[m] != '\n') { if (l_size >= win_width) { - uint j = m; + int j = m; while (text[j] != ' ') { j--; } diff --git a/src/widget_core/widget_core.h b/src/widget_core/widget_core.h index 37a75af..829d5ee 100644 --- a/src/widget_core/widget_core.h +++ b/src/widget_core/widget_core.h @@ -35,13 +35,13 @@ struct w_val_t { enum w_val_type type; union { void *ptr; - int64_t num; + int32_t num; } val; }; typedef struct { - int64_t id; - int64_t idx; /* element index in the group */ + int32_t id; + int32_t idx; /* element index in the group */ void *element; enum w_type type; enum w_g_type g_type; @@ -75,23 +75,23 @@ typedef void (*w_cb_t)(w_cb_args_t *args); typedef int32_t (*w_cb_press_t)(void *app, void *data); typedef struct w_t { - int64_t id; + int32_t id; char title[DIALOGUE_TITLE]; struct { - int64_t y; - int64_t x; + int32_t y; + int32_t x; } cur; /* cursor position */ struct { - int64_t y; - int64_t x; + int32_t y; + int32_t x; } sz; /* size */ struct { - int64_t y; - int64_t x; + int32_t y; + int32_t x; } m; /* margin (relative to the parent) */ struct { - int64_t y; - int64_t x; + int32_t y; + int32_t x; } ps; /* position (relative to the window) */ WINDOW *const *parent_win; struct w_t *w_parent; @@ -104,9 +104,9 @@ enum w_pmt_attrs { }; void w_init(w_t *w, w_t *w_parent, WINDOW **win, char *title); -int32_t w_get_max_line_len(const char *text, uint32_t *line_count); -uint32_t w_print_multiline_text(WINDOW *win, const char *text, - const uint32_t win_width, const uint32_t y, - const uint32_t x, const uint16_t attrs); +int32_t w_get_max_line_len(const char *text, int32_t *line_count); +int32_t w_print_multiline_text(WINDOW *win, const char *text, + const int32_t win_width, const int32_t y, + const int32_t x, const int16_t attrs); #endif \ No newline at end of file diff --git a/src/windows/file_list.c b/src/windows/file_list.c index e2d9bcf..31c0e14 100644 --- a/src/windows/file_list.c +++ b/src/windows/file_list.c @@ -44,7 +44,7 @@ static void w_fl_cb(w_cb_args_t *args) { fui->search_key->slen = 0; sprintf(q_prefix, "file list"); } - server_send_string(app->query_args, "%s %u %u\n", q_prefix, + server_send_string(app->query_args, "%s %d %d\n", q_prefix, fui->max_lines, 1); w_fl_reset(fui); } else { @@ -60,7 +60,7 @@ static void w_fl_cb(w_cb_args_t *args) { fui->current_idx++; } else if (fui->current_page < fui->pages) { app->query_args->state = S_FILE_LIST; - server_send_string(app->query_args, "%s %u %u\n", q_prefix, + server_send_string(app->query_args, "%s %d %d\n", q_prefix, fui->max_lines, fui->current_page + 1); w_fl_reset(fui); break; @@ -72,7 +72,7 @@ static void w_fl_cb(w_cb_args_t *args) { fui->current_idx--; } else if (fui->current_page > 1) { app->query_args->state = S_FILE_LIST; - server_send_string(app->query_args, "%s %u %u\n", q_prefix, + server_send_string(app->query_args, "%s %d %d\n", q_prefix, fui->max_lines, fui->current_page - 1); w_fl_reset(fui); fui->activate_last = true; @@ -83,7 +83,7 @@ static void w_fl_cb(w_cb_args_t *args) { case KEY_NPAGE: if (fui->current_page < fui->pages) { app->query_args->state = S_FILE_LIST; - server_send_string(app->query_args, "%s %u %u\n", q_prefix, + server_send_string(app->query_args, "%s %d %d\n", q_prefix, fui->max_lines, fui->current_page + 1); w_fl_reset(fui); break; @@ -93,7 +93,7 @@ static void w_fl_cb(w_cb_args_t *args) { case KEY_PPAGE: if (fui->current_page > 1) { app->query_args->state = S_FILE_LIST; - server_send_string(app->query_args, "%s %u %u\n", q_prefix, + server_send_string(app->query_args, "%s %d %d\n", q_prefix, fui->max_lines, fui->current_page - 1); w_fl_reset(fui); fui->activate_last = true; @@ -107,7 +107,7 @@ static void w_fl_cb(w_cb_args_t *args) { fui->search_key->slen = 0; sprintf(q_prefix, "file list"); app->query_args->state = S_FILE_LIST; - server_send_string(app->query_args, "%s %u %u\n", q_prefix, fui->max_lines, + server_send_string(app->query_args, "%s %d %d\n", q_prefix, fui->max_lines, 1); w_fl_reset(fui); case '\n': @@ -196,8 +196,8 @@ void *w_fl_init(app_t *app) { /* * INIT UI * */ /* define the width for each sub window */ - int64_t left_w_x = app->coordinates.max_x / 10 * 5; - int64_t right_w_x = app->coordinates.max_x - left_w_x - 2; + int32_t left_w_x = app->coordinates.max_x / 10 * 5; + int32_t right_w_x = app->coordinates.max_x - left_w_x - 2; /* create the list window */ fui->win_list = newwin(app->coordinates.max_y - 4, left_w_x, 2, 1); @@ -234,7 +234,7 @@ void w_fl_reset_app(void *app) { void w_fl_draw(w_ui_file_list_t *fui) { int32_t sz_y, sz_x; - int64_t p_y, p_x; + int32_t p_y, p_x; WINDOW *win = fui->win_list; getmaxyx(win, sz_y, sz_x); @@ -314,8 +314,8 @@ void w_fl_draw(w_ui_file_list_t *fui) { curs_set(true); wmove(win, p_y, p_x + p_len); } else { - uint32_t l_pad = 0; - sprintf(p_info, "P: %u/%u F: %u L: %u%n", fui->current_page, fui->pages, + int32_t l_pad = 0; + sprintf(p_info, "P: %d/%d F: %d L: %d%n", fui->current_page, fui->pages, fui->current_count, fui->full_count, &p_len); if (fui->search_key->slen > 0) { @@ -325,7 +325,7 @@ void w_fl_draw(w_ui_file_list_t *fui) { l_pad = fui->search_key->slen + 2; mvwprintw(win, p_y, p_x + l_pad, " %.*s", sz_x - l_pad, p_info); } else { - sprintf(p_info, "page: %u/%u files: %u left: %u%n", fui->current_page, + sprintf(p_info, "page: %d/%d files: %d left: %d%n", fui->current_page, fui->pages, fui->current_count, fui->full_count, &p_len); l_pad = (sz_x - p_len) / 2; if (!(l_pad % 2)) { @@ -337,7 +337,7 @@ void w_fl_draw(w_ui_file_list_t *fui) { /* Draw file info [right side] */ { - int64_t p_y = 1; + int32_t p_y = 1; p_x = 1; WINDOW *i_win = fui->win_info; wclear(i_win); diff --git a/src/windows/file_list.h b/src/windows/file_list.h index f3310d6..6f833ee 100644 --- a/src/windows/file_list.h +++ b/src/windows/file_list.h @@ -14,11 +14,11 @@ typedef struct { fl_item_t **current; fl_item_t **start; int32_t current_idx; - uint32_t current_count; - uint32_t full_count; - uint32_t pages; - uint32_t current_page; - uint32_t max_lines; + int32_t current_count; + int32_t full_count; + int32_t pages; + int32_t current_page; + int32_t max_lines; WINDOW *win_info; WINDOW *win_list; bstring search_key; diff --git a/src/windows/fs_file_list.c b/src/windows/fs_file_list.c index ba6848b..c99549e 100644 --- a/src/windows/fs_file_list.c +++ b/src/windows/fs_file_list.c @@ -333,7 +333,7 @@ static int32_t process_user_input(app_t *app, w_cb_args_t *d_args) { case 'd': case '\33': /* ESC key */ if (!app->modal.is_initiated) { - server_send_string(app->query_args, "file list %u %u\n", + 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; @@ -410,7 +410,7 @@ void w_lfl_reset_app(void *app) { void w_lfl_draw(w_lfl_ui_t *fui) { int32_t sz_y, sz_x; - int64_t p_y, p_x; + int32_t p_y, p_x; WINDOW *win = fui->win_list; getmaxyx(win, sz_y, sz_x); int32_t sz_y_f = sz_y - 1; // actual size (without box) @@ -453,7 +453,7 @@ void w_lfl_draw(w_lfl_ui_t *fui) { /* Draw file info [right side] */ { - int64_t p_y = 1; + int32_t p_y = 1; p_x = 1; WINDOW *i_win = fui->win_info; wclear(i_win);