From ad33876c73bc565e903f288d649a9a38a081be7c Mon Sep 17 00:00:00 2001 From: Alexander Zhylin Date: Thu, 23 Apr 2026 16:43:22 +0300 Subject: [PATCH] Multiline name (not finished) --- src/utils/utf8.c | 47 +++++++++++++++++++++++------ src/utils/utf8.h | 7 +++-- src/widget_core/widget_core.c | 8 +++-- src/windows/file_list.c | 57 ++++++++++++++++++++--------------- src/windows/fs_file_list.c | 4 +-- 5 files changed, 81 insertions(+), 42 deletions(-) diff --git a/src/utils/utf8.c b/src/utils/utf8.c index 18d19cc..375cb4d 100644 --- a/src/utils/utf8.c +++ b/src/utils/utf8.c @@ -13,8 +13,22 @@ size_t u_utf8_code_points_count(const char *s) { return count; } -int64_t u_utf8_conver_to_wide(const char *utf8_str, wchar_t **restrict wide_str, - size_t *restrict len) { +const char *u_utf8_wind_n(const char *s, int n) { + size_t count = 0; + const char *_s = s; + while (*_s) { + count += (*_s++ & 0xC0) != 0x80; + if (count == n) + break; + } + if (s == _s) + return NULL; + return _s; +} + +int64_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) size_t wide_len = u_utf8_code_points_count(utf8_str); // Get required length (-1 on error) @@ -30,13 +44,28 @@ int64_t u_utf8_conver_to_wide(const char *utf8_str, wchar_t **restrict wide_str, return 0; } -int64_t u_utf8_curs_printw(WINDOW *win, int64_t y, int64_t x, char *const utf8_str, int max_len) { - wchar_t *wname = NULL; +int64_t u_utf8_curs_printw(WINDOW *win, int64_t *y, int64_t *x, + const char *utf8_str, int max_len, bool multi_line) { + wchar_t *wline = NULL; size_t nsize = 0; - u_utf8_conver_to_wide(utf8_str, &wname, &nsize); - /* mvwaddwstr(win, y, x, wname); */ - wmove(win,(y),(x)); - waddnwstr(win, wname, max_len); - free(wname); + int64_t _x = *x; + int64_t _y = *y; + u_utf8_convert_to_wide(utf8_str, &wline, &nsize); + size_t s_rest = nsize; + mvwaddnwstr(win, _y, _x, wline, max_len); + + if (multi_line) { + s_rest -= max_len; + for (int i = 1; s_rest > 0; s_rest -= max_len, i++) { + _y++; + _x = *x; + mvwaddnwstr(win, _y, _x, wline + max_len*i, max_len); + } + } + + *y = _y; + *x = _x; + + free(wline); return nsize; } diff --git a/src/utils/utf8.h b/src/utils/utf8.h index cb6acba..0198f7b 100644 --- a/src/utils/utf8.h +++ b/src/utils/utf8.h @@ -5,9 +5,10 @@ #include #include -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, +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, size_t *restrict len); -int64_t u_utf8_curs_printw(WINDOW *win, int64_t y, int64_t x, char *const utf8_str, int max_len); +int64_t u_utf8_curs_printw(WINDOW *win, int64_t *y, int64_t *x, const char* utf8_str, int max_len, bool multi_line); #endif \ No newline at end of file diff --git a/src/widget_core/widget_core.c b/src/widget_core/widget_core.c index 8e8976a..bba277d 100644 --- a/src/widget_core/widget_core.c +++ b/src/widget_core/widget_core.c @@ -80,11 +80,13 @@ void PRINT_TEXT(WINDOW *win, char *l_buf, char *text, int64_t i, l_buf[c_line_len] = '\0'; utf8len = u_utf8_code_points_count(l_buf); if ((attrs & PMT_ALIGN_CENTER) == PMT_ALIGN_CENTER) { - u_utf8_curs_printw(win, line_v_pos, (win_width - utf8len) / 2, l_buf, -1); + int64_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) { - u_utf8_curs_printw(win, line_v_pos, (win_width - max_line_len) / 2, l_buf, -1); + int64_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); + u_utf8_curs_printw(win, &line_v_pos, &x, l_buf, -1, false); } } diff --git a/src/windows/file_list.c b/src/windows/file_list.c index 15acf72..64fa59a 100644 --- a/src/windows/file_list.c +++ b/src/windows/file_list.c @@ -223,7 +223,7 @@ void w_fl_reset(w_ui_file_list_t *fl_ui) { void w_fl_draw(w_ui_file_list_t *fui) { int32_t sz_y, sz_x; - int32_t p_y, p_x; + int64_t p_y, p_x; WINDOW *win = fui->win_list; getmaxyx(win, sz_y, sz_x); @@ -261,7 +261,7 @@ void w_fl_draw(w_ui_file_list_t *fui) { active_el = el; } p_x = 1; - p_x += u_utf8_curs_printw(win, p_y, p_x, el->name, sz_x - 1); + p_x += u_utf8_curs_printw(win, &p_y, &p_x, el->name, sz_x - 1, false); int pad = sz_x - p_x; if (pad >= 0) { mvwprintw(win, p_y, p_x, "%*s", pad, ""); @@ -295,29 +295,6 @@ void w_fl_draw(w_ui_file_list_t *fui) { char p_info[64]; - /* Draw file info [right side] */ - { - uint32_t p_y = 1; - p_x = 1; - WINDOW *i_win = fui->win_info; - wclear(i_win); - box(fui->win_info, 0, 0); - - /* Write to the right side the information about the file */ - if (active_el != NULL) { - char size_text[64]; - size_to_text(active_el->size, size_text); - - mvwprintw(i_win, p_y++, p_x, "Size: %s", size_text); - mvwprintw(i_win, p_y++, p_x, "Owner: %s", active_el->owner); - if (active_el->description != NULL) { - mvwprintw(i_win, p_y++, p_x, "Description: "); - w_print_multiline_text(i_win, active_el->description, sz_x, p_y, p_x, - 0); - } - } - } - /* Search bar */ p_x = 1; wattrset(win, A_BOLD); @@ -347,5 +324,35 @@ void w_fl_draw(w_ui_file_list_t *fui) { mvwprintw(win, p_y, p_x, "%*s%s%*s", l_pad, "", p_info, l_pad, ""); } } + + /* Draw file info [right side] */ + { + int64_t p_y = 1; + p_x = 1; + WINDOW *i_win = fui->win_info; + wclear(i_win); + box(fui->win_info, 0, 0); + + /* Write to the right side the information about the file */ + if (active_el != NULL) { + char size_text[64]; + + mvwprintw(i_win, p_y, p_x, "Name: "); + + p_x = 8; /* 7 (size of "Name: ") + 1 */ + u_utf8_curs_printw(i_win, &p_y, &p_x, active_el->name, sz_x - p_x, true); + p_x = 1; + + size_to_text(active_el->size, size_text); + mvwprintw(i_win, p_y++, p_x, "Size: %s", size_text); + mvwprintw(i_win, p_y++, p_x, "Owner: %s", active_el->owner); + if (active_el->description != NULL) { + mvwprintw(i_win, p_y++, p_x, "Description: "); + w_print_multiline_text(i_win, active_el->description, sz_x, p_y, p_x, + 0); + } + } + } + wattroff(win, A_BOLD); } \ No newline at end of file diff --git a/src/windows/fs_file_list.c b/src/windows/fs_file_list.c index 76a808c..c810699 100644 --- a/src/windows/fs_file_list.c +++ b/src/windows/fs_file_list.c @@ -357,7 +357,7 @@ void w_lfl_reset(w_lfl_ui_t *fl_ui) { fl_ui->current_idx = 0; } void w_lfl_draw(w_lfl_ui_t *fui) { int32_t sz_y, sz_x; - int32_t p_y, p_x; + int64_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) @@ -381,7 +381,7 @@ void w_lfl_draw(w_lfl_ui_t *fui) { wattrset(win, A_BOLD | A_REVERSE); } p_x = 1; - p_x += u_utf8_curs_printw(win, p_y, p_x, el->name, sz_x_f-1); + p_x += u_utf8_curs_printw(win, &p_y, &p_x, el->name, sz_x_f-1, false); int pad = sz_x_f - p_x; if (pad >= 0) { mvwprintw(win, p_y, p_x, "%*s", pad, "");