1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05: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;
char *url;
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");
int show_meter = (download_is_progressing(download)
&& download->progress->size >= 0);
@ -166,8 +166,8 @@ download_dialog_layouter(struct dialog_data *dlg_data)
int_lower_bound(&w, DOWN_DLG_MIN);
}
dlg_format_text_do(dlg_data, url, 0, &y, w, &rw,
dialog_text_color, ALIGN_LEFT, 1);
dlg_format_text_do_node(dlg_data, url, 0, &y, w, &rw,
dialog_text_color_node, ALIGN_LEFT, 1);
y++;
if (show_meter) y += 2;
@ -175,8 +175,8 @@ download_dialog_layouter(struct dialog_data *dlg_data)
#ifdef CONFIG_BITTORRENT
if (bittorrent) y += 2;
#endif
dlg_format_text_do(dlg_data, msg, 0, &y, w, &rw,
dialog_text_color, ALIGN_LEFT, 1);
dlg_format_text_do_node(dlg_data, msg, 0, &y, w, &rw,
dialog_text_color_node, ALIGN_LEFT, 1);
y++;
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;
x = dlg_data->box.x + DIALOG_LB;
dlg_format_text_do(dlg_data, url, x, &y, w, NULL,
dialog_text_color, ALIGN_LEFT, 0);
dlg_format_text_do_node(dlg_data, url, x, &y, w, NULL,
dialog_text_color_node, ALIGN_LEFT, 0);
if (show_meter) {
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++;
}
#ifdef CONFIG_BITTORRENT
if (bittorrent) {
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++;
}
#endif
y++;
dlg_format_text_do(dlg_data, msg, x, &y, w, NULL,
dialog_text_color, ALIGN_LEFT, 0);
dlg_format_text_do_node(dlg_data, msg, x, &y, w, NULL,
dialog_text_color_node, ALIGN_LEFT, 0);
y++;
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 download *download = &file_download->download;
const char *stylename;
struct color_pair *color;
unsigned int color_node;
char *text;
int length;
int trimmedlen;
@ -391,7 +391,7 @@ draw_file_download(struct listbox_item *item, struct listbox_context *context,
: ((item->marked) ? "menu.marked"
: "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);
if (!text) return;
@ -404,9 +404,9 @@ draw_file_download(struct listbox_item *item, struct listbox_context *context,
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) {
draw_text(context->term, x + trimmedlen, y, "...", 3, 0, color);
draw_text_node(context->term, x + trimmedlen, y, "...", 3, 0, color_node);
trimmedlen += 3;
}
@ -427,7 +427,7 @@ draw_file_download(struct listbox_item *item, struct listbox_context *context,
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 = {

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));
}
#if 0
void
draw_progress_bar(struct progress *progress, struct terminal *term,
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);
}
#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,
int wide, int full, const char *separator);
#if 0
/* 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(struct progress *progress, struct terminal *term,
int x, int y, int width,
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
}

View File

@ -173,7 +173,7 @@ display_status_bar(struct session *ses, struct terminal *term, int tabs_count)
unsigned int tab_info_len = 0;
struct download *download = get_current_download(ses);
struct session_status *status = &ses->status;
struct color_pair *text_color = NULL;
unsigned int text_color_node = 0;
int msglen;
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);
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) {
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] = '\0';
text_color = get_bfu_color(term, "status.status-text");
draw_text(term, 0, term->height - 1, tab_info, tab_info_len,
0, text_color);
text_color_node = get_bfu_color_node(term, "status.status-text");
draw_text_node(term, 0, term->height - 1, tab_info, tab_info_len,
0, text_color_node);
}
if (!msg) return;
if (!text_color)
text_color = get_bfu_color(term, "status.status-text");
if (!text_color_node)
text_color_node = get_bfu_color_node(term, "status.status-text");
msglen = strlen(msg);
draw_text(term, 0 + tab_info_len, term->height - 1,
msg, msglen, 0, text_color);
draw_text_node(term, 0 + tab_info_len, term->height - 1,
msg, msglen, 0, text_color_node);
mem_free(msg);
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);
if (width < 6) return;
int_upper_bound(&width, 20);
draw_progress_bar(download->progress, term,
draw_progress_bar_node(download->progress, term,
xend - width, term->height - 1, width,
NULL, NULL);
NULL, 0);
}
}
static inline void
display_tab_bar(struct session *ses, struct terminal *term, int tabs_count)
{
struct color_pair *normal_color = get_bfu_color(term, "tabs.normal");
struct color_pair *selected_color = get_bfu_color(term, "tabs.selected");
struct color_pair *loading_color = get_bfu_color(term, "tabs.loading");
struct color_pair *fresh_color = get_bfu_color(term, "tabs.unvisited");
struct color_pair *tabsep_color = get_bfu_color(term, "tabs.separator");
unsigned int normal_color_node = get_bfu_color_node(term, "tabs.normal");
unsigned int selected_color_node = get_bfu_color_node(term, "tabs.selected");
unsigned int loading_color_node = get_bfu_color_node(term, "tabs.loading");
unsigned int fresh_color_node = get_bfu_color_node(term, "tabs.unvisited");
unsigned int tabsep_color_node = get_bfu_color_node(term, "tabs.separator");
struct session_status *status = &ses->status;
int tab_width = int_max(1, term->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++) {
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 document_view *doc_view;
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) {
draw_char(term, box.x, box.y, BORDER_SVLINE,
SCREEN_ATTR_FRAME, tabsep_color);
draw_char_node(term, box.x, box.y, BORDER_SVLINE,
SCREEN_ATTR_FRAME, tabsep_color_node);
box.x++;
}
if (tab_num == term->current_tab) {
color = selected_color;
color_node = selected_color_node;
} else {
download = get_current_download(tab_ses);
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) {
color = fresh_color;
color_node = fresh_color_node;
}
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;
draw_box(term, &box, ' ', 0, color);
draw_box_node(term, &box, ' ', 0, color_node);
if (download) {
draw_progress_bar(download->progress, term,
draw_progress_bar_node(download->progress, term,
box.x, box.y, actual_tab_width,
msg, NULL);
msg, 0);
} else {
int msglen;
#ifdef CONFIG_UTF8
@ -372,7 +372,7 @@ display_tab_bar(struct session *ses, struct terminal *term, int tabs_count)
#endif /* CONFIG_UTF8 */
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;
@ -405,7 +405,7 @@ display_title_bar(struct session *ses, struct terminal *term)
struct el_box box;
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);
@ -472,8 +472,8 @@ display_title_bar(struct session *ses, struct terminal *term)
#endif /* CONFIG_UTF8 */
x = int_max(term->width - 1 - title.length, 0);
draw_text(term, x, 0, title.source, title.length, 0,
get_bfu_color(term, "title.title-text"));
draw_text_node(term, x, 0, title.source, title.length, 0,
get_bfu_color_node(term, "title.title-text"));
}
done_string(&title);

View File

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

View File

@ -19,10 +19,18 @@ char *
get_bittorrent_message(struct download *download, struct terminal *term,
int wide, int full, const char *separator);
#if 0
void
draw_bittorrent_piece_progress(struct download *download, struct terminal *term,
int x, int y, int width, char *text,
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_notify_on_completion(struct download *download, struct terminal *term);