1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-02 08:57:19 -04:00

[dialogs] _node

This commit is contained in:
Witold Filipczyk 2022-03-18 19:22:38 +01:00
parent fb0bd72743
commit b2c7566544
6 changed files with 129 additions and 51 deletions

View File

@ -135,7 +135,7 @@ download_dialog_layouter(struct dialog_data *dlg_data)
int url_len; int url_len;
char *url; char *url;
struct download *download = &file_download->download; struct download *download = &file_download->download;
struct color_pair *dialog_text_color = get_bfu_color(term, "dialog.text"); unsigned int dialog_text_color_node = get_bfu_color_node(term, "dialog.text");
char *msg = get_download_msg(download, term, 1, 1, "\n"); char *msg = get_download_msg(download, term, 1, 1, "\n");
int show_meter = (download_is_progressing(download) int show_meter = (download_is_progressing(download)
&& download->progress->size >= 0); && download->progress->size >= 0);
@ -166,8 +166,8 @@ download_dialog_layouter(struct dialog_data *dlg_data)
int_lower_bound(&w, DOWN_DLG_MIN); int_lower_bound(&w, DOWN_DLG_MIN);
} }
dlg_format_text_do(dlg_data, url, 0, &y, w, &rw, dlg_format_text_do_node(dlg_data, url, 0, &y, w, &rw,
dialog_text_color, ALIGN_LEFT, 1); dialog_text_color_node, ALIGN_LEFT, 1);
y++; y++;
if (show_meter) y += 2; if (show_meter) y += 2;
@ -175,8 +175,8 @@ download_dialog_layouter(struct dialog_data *dlg_data)
#ifdef CONFIG_BITTORRENT #ifdef CONFIG_BITTORRENT
if (bittorrent) y += 2; if (bittorrent) y += 2;
#endif #endif
dlg_format_text_do(dlg_data, msg, 0, &y, w, &rw, dlg_format_text_do_node(dlg_data, msg, 0, &y, w, &rw,
dialog_text_color, ALIGN_LEFT, 1); dialog_text_color_node, ALIGN_LEFT, 1);
y++; y++;
dlg_format_buttons(dlg_data, dlg_data->widgets_data, dlg_format_buttons(dlg_data, dlg_data->widgets_data,
@ -199,25 +199,25 @@ download_dialog_layouter(struct dialog_data *dlg_data)
y = dlg_data->box.y + DIALOG_TB + 1; y = dlg_data->box.y + DIALOG_TB + 1;
x = dlg_data->box.x + DIALOG_LB; x = dlg_data->box.x + DIALOG_LB;
dlg_format_text_do(dlg_data, url, x, &y, w, NULL, dlg_format_text_do_node(dlg_data, url, x, &y, w, NULL,
dialog_text_color, ALIGN_LEFT, 0); dialog_text_color_node, ALIGN_LEFT, 0);
if (show_meter) { if (show_meter) {
y++; y++;
draw_progress_bar(download->progress, term, x, y, w, NULL, NULL); draw_progress_bar_node(download->progress, term, x, y, w, NULL, 0);
y++; y++;
} }
#ifdef CONFIG_BITTORRENT #ifdef CONFIG_BITTORRENT
if (bittorrent) { if (bittorrent) {
y++; y++;
draw_bittorrent_piece_progress(download, term, x, y, w, NULL, NULL); draw_bittorrent_piece_progress_node(download, term, x, y, w, NULL, 0);
y++; y++;
} }
#endif #endif
y++; y++;
dlg_format_text_do(dlg_data, msg, x, &y, w, NULL, dlg_format_text_do_node(dlg_data, msg, x, &y, w, NULL,
dialog_text_color, ALIGN_LEFT, 0); dialog_text_color_node, ALIGN_LEFT, 0);
y++; y++;
dlg_format_buttons(dlg_data, dlg_data->widgets_data, dlg_format_buttons(dlg_data, dlg_data->widgets_data,
@ -378,7 +378,7 @@ draw_file_download(struct listbox_item *item, struct listbox_context *context,
struct file_download *file_download = (struct file_download *)item->udata; struct file_download *file_download = (struct file_download *)item->udata;
struct download *download = &file_download->download; struct download *download = &file_download->download;
const char *stylename; const char *stylename;
struct color_pair *color; unsigned int color_node;
char *text; char *text;
int length; int length;
int trimmedlen; int trimmedlen;
@ -391,7 +391,7 @@ draw_file_download(struct listbox_item *item, struct listbox_context *context,
: ((item->marked) ? "menu.marked" : ((item->marked) ? "menu.marked"
: "menu.normal"); : "menu.normal");
color = get_bfu_color(context->term, stylename); color_node = get_bfu_color_node(context->term, stylename);
text = get_file_download_text(item, context->term); text = get_file_download_text(item, context->term);
if (!text) return; if (!text) return;
@ -404,9 +404,9 @@ draw_file_download(struct listbox_item *item, struct listbox_context *context,
trimmedlen = int_min(length, width - 3); trimmedlen = int_min(length, width - 3);
} }
draw_text(context->term, x, y, text, trimmedlen, 0, color); draw_text_node(context->term, x, y, text, trimmedlen, 0, color_node);
if (trimmedlen < length) { if (trimmedlen < length) {
draw_text(context->term, x + trimmedlen, y, "...", 3, 0, color); draw_text_node(context->term, x + trimmedlen, y, "...", 3, 0, color_node);
trimmedlen += 3; trimmedlen += 3;
} }
@ -427,7 +427,7 @@ draw_file_download(struct listbox_item *item, struct listbox_context *context,
x += width - meter; x += width - meter;
draw_progress_bar(download->progress, context->term, x, y, meter, NULL, NULL); draw_progress_bar_node(download->progress, context->term, x, y, meter, NULL, 0);
} }
static struct listbox_ops_messages download_messages = { static struct listbox_ops_messages download_messages = {

View File

@ -104,6 +104,7 @@ get_progress_msg(struct progress *progress, struct terminal *term,
return get_progress_msg_2(progress, term, wide, full, separator, _("Received", term)); return get_progress_msg_2(progress, term, wide, full, separator, _("Received", term));
} }
#if 0
void void
draw_progress_bar(struct progress *progress, struct terminal *term, draw_progress_bar(struct progress *progress, struct terminal *term,
int x, int y, int width, int x, int y, int width,
@ -154,3 +155,55 @@ draw_progress_bar(struct progress *progress, struct terminal *term,
draw_text(term, x, y, text, width, 0, NULL); draw_text(term, x, y, text, width, 0, NULL);
} }
#endif
void
draw_progress_bar_node(struct progress *progress, struct terminal *term,
int x, int y, int width,
char *text, unsigned int meter_color_node)
{
/* Note : values > 100% are theorically possible and were seen. */
int percent = 0;
struct el_box barprogress;
if (progress->size > 0)
percent = (int) ((longlong) 100 * progress->pos / progress->size);
/* Draw the progress meter part "[### ]" */
if (!text && width > 2) {
width -= 2;
draw_text_node(term, x++, y, "[", 1, 0, 0);
draw_text_node(term, x + width, y, "]", 1, 0, 0);
}
if (!meter_color_node) meter_color_node = get_bfu_color_node(term, "dialog.meter");
set_box(&barprogress,
x, y, int_min(width * percent / 100, width), 1);
draw_box_node(term, &barprogress, ' ', 0, meter_color_node);
/* On error, will print '?' only, should not occur. */
if (text) {
width = int_min(width, strlen(text));
} else if (width > 1) {
static char s[] = "????"; /* Reduce or enlarge at will. */
unsigned int slen = 0;
int max = int_min(sizeof(s), width) - 1;
if (ulongcat(s, &slen, percent, max, 0)) {
s[0] = '?';
slen = 1;
}
s[slen++] = '%';
/* Draw the percentage centered in the progress meter */
x += (1 + width - slen) / 2;
assert(slen <= width);
width = slen;
text = s;
}
draw_text_node(term, x, y, text, width, 0, 0);
}

View File

@ -17,12 +17,21 @@ char *
get_upload_progress_msg(struct progress *progress, struct terminal *term, get_upload_progress_msg(struct progress *progress, struct terminal *term,
int wide, int full, const char *separator); int wide, int full, const char *separator);
#if 0
/* Draws a progress bar meter or progress coloured text depending on whether /* Draws a progress bar meter or progress coloured text depending on whether
* @text is NULL. If @meter_color is NULL dialog.meter color is used. */ * @text is NULL. If @meter_color is NULL dialog.meter color is used. */
void void
draw_progress_bar(struct progress *progress, struct terminal *term, draw_progress_bar(struct progress *progress, struct terminal *term,
int x, int y, int width, int x, int y, int width,
char *text, struct color_pair *meter_color); char *text, struct color_pair *meter_color);
#endif
/* Draws a progress bar meter or progress coloured text depending on whether
* @text is NULL. If @meter_color is NULL dialog.meter color is used. */
void
draw_progress_bar_node(struct progress *progress, struct terminal *term,
int x, int y, int width,
char *text, unsigned int meter_color_node);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -173,7 +173,7 @@ display_status_bar(struct session *ses, struct terminal *term, int tabs_count)
unsigned int tab_info_len = 0; unsigned int tab_info_len = 0;
struct download *download = get_current_download(ses); struct download *download = get_current_download(ses);
struct session_status *status = &ses->status; struct session_status *status = &ses->status;
struct color_pair *text_color = NULL; unsigned int text_color_node = 0;
int msglen; int msglen;
struct el_box box; struct el_box box;
@ -240,7 +240,7 @@ display_status_bar(struct session *ses, struct terminal *term, int tabs_count)
} }
set_box(&box, 0, term->height - 1, term->width, 1); set_box(&box, 0, term->height - 1, term->width, 1);
draw_box(term, &box, ' ', 0, get_bfu_color(term, "status.status-bar")); draw_box_node(term, &box, ' ', 0, get_bfu_color_node(term, "status.status-bar"));
if (!status->show_tabs_bar && tabs_count > 1) { if (!status->show_tabs_bar && tabs_count > 1) {
char tab_info[8]; char tab_info[8];
@ -251,19 +251,19 @@ display_status_bar(struct session *ses, struct terminal *term, int tabs_count)
tab_info[tab_info_len++] = ' '; tab_info[tab_info_len++] = ' ';
tab_info[tab_info_len] = '\0'; tab_info[tab_info_len] = '\0';
text_color = get_bfu_color(term, "status.status-text"); text_color_node = get_bfu_color_node(term, "status.status-text");
draw_text(term, 0, term->height - 1, tab_info, tab_info_len, draw_text_node(term, 0, term->height - 1, tab_info, tab_info_len,
0, text_color); 0, text_color_node);
} }
if (!msg) return; if (!msg) return;
if (!text_color) if (!text_color_node)
text_color = get_bfu_color(term, "status.status-text"); text_color_node = get_bfu_color_node(term, "status.status-text");
msglen = strlen(msg); msglen = strlen(msg);
draw_text(term, 0 + tab_info_len, term->height - 1, draw_text_node(term, 0 + tab_info_len, term->height - 1,
msg, msglen, 0, text_color); msg, msglen, 0, text_color_node);
mem_free(msg); mem_free(msg);
if (download_is_progressing(download) && download->progress->size > 0) { if (download_is_progressing(download) && download->progress->size > 0) {
@ -278,20 +278,20 @@ display_status_bar(struct session *ses, struct terminal *term, int tabs_count)
width = int_max(0, xend - msglen - tab_info_len - 1); width = int_max(0, xend - msglen - tab_info_len - 1);
if (width < 6) return; if (width < 6) return;
int_upper_bound(&width, 20); int_upper_bound(&width, 20);
draw_progress_bar(download->progress, term, draw_progress_bar_node(download->progress, term,
xend - width, term->height - 1, width, xend - width, term->height - 1, width,
NULL, NULL); NULL, 0);
} }
} }
static inline void static inline void
display_tab_bar(struct session *ses, struct terminal *term, int tabs_count) display_tab_bar(struct session *ses, struct terminal *term, int tabs_count)
{ {
struct color_pair *normal_color = get_bfu_color(term, "tabs.normal"); unsigned int normal_color_node = get_bfu_color_node(term, "tabs.normal");
struct color_pair *selected_color = get_bfu_color(term, "tabs.selected"); unsigned int selected_color_node = get_bfu_color_node(term, "tabs.selected");
struct color_pair *loading_color = get_bfu_color(term, "tabs.loading"); unsigned int loading_color_node = get_bfu_color_node(term, "tabs.loading");
struct color_pair *fresh_color = get_bfu_color(term, "tabs.unvisited"); unsigned int fresh_color_node = get_bfu_color_node(term, "tabs.unvisited");
struct color_pair *tabsep_color = get_bfu_color(term, "tabs.separator"); unsigned int tabsep_color_node = get_bfu_color_node(term, "tabs.separator");
struct session_status *status = &ses->status; struct session_status *status = &ses->status;
int tab_width = int_max(1, term->width / tabs_count); int tab_width = int_max(1, term->width / tabs_count);
int tab_total_width = tab_width * tabs_count; int tab_total_width = tab_width * tabs_count;
@ -305,7 +305,7 @@ display_tab_bar(struct session *ses, struct terminal *term, int tabs_count)
for (tab_num = 0; tab_num < tabs_count; tab_num++) { for (tab_num = 0; tab_num < tabs_count; tab_num++) {
struct download *download = NULL; struct download *download = NULL;
struct color_pair *color = normal_color; unsigned int color_node = normal_color_node;
struct window *tab = get_tab_by_number(term, tab_num); struct window *tab = get_tab_by_number(term, tab_num);
struct document_view *doc_view; struct document_view *doc_view;
struct session *tab_ses = (struct session *)tab->data; struct session *tab_ses = (struct session *)tab->data;
@ -331,21 +331,21 @@ display_tab_bar(struct session *ses, struct terminal *term, int tabs_count)
} }
if (tab_num) { if (tab_num) {
draw_char(term, box.x, box.y, BORDER_SVLINE, draw_char_node(term, box.x, box.y, BORDER_SVLINE,
SCREEN_ATTR_FRAME, tabsep_color); SCREEN_ATTR_FRAME, tabsep_color_node);
box.x++; box.x++;
} }
if (tab_num == term->current_tab) { if (tab_num == term->current_tab) {
color = selected_color; color_node = selected_color_node;
} else { } else {
download = get_current_download(tab_ses); download = get_current_download(tab_ses);
if (download && !is_in_state(download->state, S_OK)) { if (download && !is_in_state(download->state, S_OK)) {
color = loading_color; color_node = loading_color_node;
} else if (!tab_ses || !tab_ses->status.visited) { } else if (!tab_ses || !tab_ses->status.visited) {
color = fresh_color; color_node = fresh_color_node;
} }
if (!download_is_progressing(download) if (!download_is_progressing(download)
@ -354,12 +354,12 @@ display_tab_bar(struct session *ses, struct terminal *term, int tabs_count)
} }
box.width = actual_tab_width + 1; box.width = actual_tab_width + 1;
draw_box(term, &box, ' ', 0, color); draw_box_node(term, &box, ' ', 0, color_node);
if (download) { if (download) {
draw_progress_bar(download->progress, term, draw_progress_bar_node(download->progress, term,
box.x, box.y, actual_tab_width, box.x, box.y, actual_tab_width,
msg, NULL); msg, 0);
} else { } else {
int msglen; int msglen;
#ifdef CONFIG_UTF8 #ifdef CONFIG_UTF8
@ -372,7 +372,7 @@ display_tab_bar(struct session *ses, struct terminal *term, int tabs_count)
#endif /* CONFIG_UTF8 */ #endif /* CONFIG_UTF8 */
msglen = int_min(strlen(msg), actual_tab_width); msglen = int_min(strlen(msg), actual_tab_width);
draw_text(term, box.x, box.y, msg, msglen, 0, color); draw_text_node(term, box.x, box.y, msg, msglen, 0, color_node);
} }
tab->xpos = box.x; tab->xpos = box.x;
@ -405,7 +405,7 @@ display_title_bar(struct session *ses, struct terminal *term)
struct el_box box; struct el_box box;
set_box(&box, 0, 0, term->width, 1); set_box(&box, 0, 0, term->width, 1);
draw_box(term, &box, ' ', 0, get_bfu_color(term, "title.title-bar")); draw_box_node(term, &box, ' ', 0, get_bfu_color_node(term, "title.title-bar"));
} }
doc_view = current_frame(ses); doc_view = current_frame(ses);
@ -472,8 +472,8 @@ display_title_bar(struct session *ses, struct terminal *term)
#endif /* CONFIG_UTF8 */ #endif /* CONFIG_UTF8 */
x = int_max(term->width - 1 - title.length, 0); x = int_max(term->width - 1 - title.length, 0);
draw_text(term, x, 0, title.source, title.length, 0, draw_text_node(term, x, 0, title.source, title.length, 0,
get_bfu_color(term, "title.title-text")); get_bfu_color_node(term, "title.title-text"));
} }
done_string(&title); done_string(&title);

View File

@ -452,10 +452,17 @@ get_bittorrent_message(struct download *download, struct terminal *term,
return string.source; return string.source;
} }
#if 0
void void
draw_bittorrent_piece_progress(struct download *download, struct terminal *term, draw_bittorrent_piece_progress(struct download *download, struct terminal *term,
int x, int y, int width, char *text, int x, int y, int width, char *text,
struct color_pair *color) struct color_pair *color)
#endif
void
draw_bittorrent_piece_progress_node(struct download *download, struct terminal *term,
int x, int y, int width, char *text,
unsigned int color_node)
{ {
struct bittorrent_connection *bittorrent; struct bittorrent_connection *bittorrent;
uint32_t piece; uint32_t piece;
@ -482,7 +489,7 @@ draw_bittorrent_piece_progress(struct download *download, struct terminal *term,
return; return;
// if (!color) color = get_bfu_color(term, "dialog.meter"); // if (!color) color = get_bfu_color(term, "dialog.meter");
if (!color) node_number = get_bfu_color_node(term, "dialog.meter"); if (!color_node) node_number = get_bfu_color_node(term, "dialog.meter");
if (bittorrent->meta.pieces <= width) { if (bittorrent->meta.pieces <= width) {
int chars_per_piece = width / bittorrent->meta.pieces; int chars_per_piece = width / bittorrent->meta.pieces;
@ -505,12 +512,13 @@ draw_bittorrent_piece_progress(struct download *download, struct terminal *term,
} else { } else {
int pieces_per_char = bittorrent->meta.pieces / width; int pieces_per_char = bittorrent->meta.pieces / width;
int remainder = bittorrent->meta.pieces % width; int remainder = bittorrent->meta.pieces % width;
struct color_pair inverted; /// struct color_pair inverted;
unsigned int inverted_node = get_bfu_color_node(term, "dialog.meter");
uint32_t completed = 0, remaining = 0; uint32_t completed = 0, remaining = 0;
int steps = pieces_per_char + !!remainder; int steps = pieces_per_char + !!remainder;
inverted.background = color->foreground; /// inverted.background = color->foreground;
inverted.foreground = color->background; /// inverted.foreground = color->background;
for (piece = 0; piece < bittorrent->meta.pieces; piece++) { for (piece = 0; piece < bittorrent->meta.pieces; piece++) {
if (bittorrent->cache->entries[piece].completed) if (bittorrent->cache->entries[piece].completed)
@ -537,8 +545,8 @@ draw_bittorrent_piece_progress(struct download *download, struct terminal *term,
} }
else if (completed) /* > 0% */ else if (completed) /* > 0% */
draw_char(term, x, y, BORDER_SVLINE, draw_char_node(term, x, y, BORDER_SVLINE,
SCREEN_ATTR_FRAME, &inverted); SCREEN_ATTR_FRAME, inverted_node);
x++; x++;
if (remainder > 0) remainder--; if (remainder > 0) remainder--;

View File

@ -19,10 +19,18 @@ char *
get_bittorrent_message(struct download *download, struct terminal *term, get_bittorrent_message(struct download *download, struct terminal *term,
int wide, int full, const char *separator); int wide, int full, const char *separator);
#if 0
void void
draw_bittorrent_piece_progress(struct download *download, struct terminal *term, draw_bittorrent_piece_progress(struct download *download, struct terminal *term,
int x, int y, int width, char *text, int x, int y, int width, char *text,
struct color_pair *meter_color); struct color_pair *meter_color);
#endif
void
draw_bittorrent_piece_progress_node(struct download *download, struct terminal *term,
int x, int y, int width, char *text,
unsigned int meter_color_node);
void set_bittorrent_files_for_deletion(struct download *download); void set_bittorrent_files_for_deletion(struct download *download);
void set_bittorrent_notify_on_completion(struct download *download, struct terminal *term); void set_bittorrent_notify_on_completion(struct download *download, struct terminal *term);