Multiline name (not finished)

This commit is contained in:
2026-04-23 16:43:22 +03:00
parent 13c8aab021
commit ad33876c73
5 changed files with 81 additions and 42 deletions
+37 -8
View File
@@ -13,7 +13,21 @@ 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,
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 =
@@ -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;
}
+2 -1
View File
@@ -5,9 +5,10 @@
#include <stddef.h>
#include <stdint.h>
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
+5 -3
View File
@@ -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);
}
}
+32 -25
View File
@@ -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);
}
+2 -2
View File
@@ -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, "");