Multiline name (not finished)
This commit is contained in:
+38
-9
@@ -13,8 +13,22 @@ size_t u_utf8_code_points_count(const char *s) {
|
|||||||
return count;
|
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 *restrict len) {
|
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)
|
// Step 1: Convert UTF-8 (MBCS) to wchar_t (wide)
|
||||||
size_t wide_len =
|
size_t wide_len =
|
||||||
u_utf8_code_points_count(utf8_str); // Get required length (-1 on error)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
wchar_t *wname = NULL;
|
const char *utf8_str, int max_len, bool multi_line) {
|
||||||
|
wchar_t *wline = NULL;
|
||||||
size_t nsize = 0;
|
size_t nsize = 0;
|
||||||
u_utf8_conver_to_wide(utf8_str, &wname, &nsize);
|
int64_t _x = *x;
|
||||||
/* mvwaddwstr(win, y, x, wname); */
|
int64_t _y = *y;
|
||||||
wmove(win,(y),(x));
|
u_utf8_convert_to_wide(utf8_str, &wline, &nsize);
|
||||||
waddnwstr(win, wname, max_len);
|
size_t s_rest = nsize;
|
||||||
free(wname);
|
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;
|
return nsize;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -5,9 +5,10 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
size_t u_utf8_code_points_count(const char *s);
|
const char *u_utf8_wind_n(const char *s, int n);
|
||||||
int64_t u_utf8_convert_to_wide(const char *utf8_str, wchar_t **restrict wide_str,
|
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);
|
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
|
#endif
|
||||||
@@ -80,11 +80,13 @@ void PRINT_TEXT(WINDOW *win, char *l_buf, char *text, int64_t i,
|
|||||||
l_buf[c_line_len] = '\0';
|
l_buf[c_line_len] = '\0';
|
||||||
utf8len = u_utf8_code_points_count(l_buf);
|
utf8len = u_utf8_code_points_count(l_buf);
|
||||||
if ((attrs & PMT_ALIGN_CENTER) == PMT_ALIGN_CENTER) {
|
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) {
|
} 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 {
|
} 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
@@ -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) {
|
void w_fl_draw(w_ui_file_list_t *fui) {
|
||||||
int32_t sz_y, sz_x;
|
int32_t sz_y, sz_x;
|
||||||
int32_t p_y, p_x;
|
int64_t p_y, p_x;
|
||||||
WINDOW *win = fui->win_list;
|
WINDOW *win = fui->win_list;
|
||||||
getmaxyx(win, sz_y, sz_x);
|
getmaxyx(win, sz_y, sz_x);
|
||||||
|
|
||||||
@@ -261,7 +261,7 @@ void w_fl_draw(w_ui_file_list_t *fui) {
|
|||||||
active_el = el;
|
active_el = el;
|
||||||
}
|
}
|
||||||
p_x = 1;
|
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;
|
int pad = sz_x - p_x;
|
||||||
if (pad >= 0) {
|
if (pad >= 0) {
|
||||||
mvwprintw(win, p_y, p_x, "%*s", pad, "");
|
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];
|
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 */
|
/* Search bar */
|
||||||
p_x = 1;
|
p_x = 1;
|
||||||
wattrset(win, A_BOLD);
|
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, "");
|
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);
|
wattroff(win, A_BOLD);
|
||||||
}
|
}
|
||||||
@@ -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) {
|
void w_lfl_draw(w_lfl_ui_t *fui) {
|
||||||
int32_t sz_y, sz_x;
|
int32_t sz_y, sz_x;
|
||||||
int32_t p_y, p_x;
|
int64_t p_y, p_x;
|
||||||
WINDOW *win = fui->win_list;
|
WINDOW *win = fui->win_list;
|
||||||
getmaxyx(win, sz_y, sz_x);
|
getmaxyx(win, sz_y, sz_x);
|
||||||
int32_t sz_y_f = sz_y - 1; // actual size (without box)
|
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);
|
wattrset(win, A_BOLD | A_REVERSE);
|
||||||
}
|
}
|
||||||
p_x = 1;
|
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;
|
int pad = sz_x_f - p_x;
|
||||||
if (pad >= 0) {
|
if (pad >= 0) {
|
||||||
mvwprintw(win, p_y, p_x, "%*s", pad, "");
|
mvwprintw(win, p_y, p_x, "%*s", pad, "");
|
||||||
|
|||||||
Reference in New Issue
Block a user