ui: Input: fix non-Latin letters
This commit is contained in:
@@ -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],
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@
|
||||
#include <stdint.h>
|
||||
|
||||
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) \
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
|
||||
+3
-3
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
+3
-3
@@ -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;
|
||||
|
||||
+3
-3
@@ -4,7 +4,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
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);
|
||||
|
||||
+4
-4
@@ -3,15 +3,15 @@
|
||||
/* Dynamic array of numbers */
|
||||
#include <stdint.h>
|
||||
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
|
||||
+4
-4
@@ -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);
|
||||
|
||||
|
||||
+2
-2
@@ -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
|
||||
+3
-3
@@ -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;
|
||||
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
+4
-4
@@ -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;
|
||||
|
||||
|
||||
+31
-10
@@ -8,13 +8,17 @@
|
||||
|
||||
#include "../app.h"
|
||||
#include "input.h"
|
||||
#include <wchar.h>
|
||||
#include <widget_core.h>
|
||||
|
||||
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);
|
||||
|
||||
+6
-5
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
typedef struct {
|
||||
w_t w;
|
||||
uint32_t procent;
|
||||
int32_t procent;
|
||||
char text[24];
|
||||
} w_pgb_ui_t;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <string.h>
|
||||
#include <utils.h>
|
||||
|
||||
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--;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
+13
-13
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user