📄 status.c
字号:
unsigned char tab_info[8]; tab_info[tab_info_len++] = '['; ulongcat(tab_info, &tab_info_len, term->current_tab + 1, 4, 0); tab_info[tab_info_len++] = ']'; 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); } if (!msg) return; if (!text_color) text_color = get_bfu_color(term, "status.status-text"); msglen = strlen(msg); draw_text(term, 0 + tab_info_len, term->height - 1, msg, msglen, 0, text_color); mem_free(msg); if (download_is_progressing(download) && download->progress->size > 0) { int xend = term->width - 1; int width;#ifdef CONFIG_LEDS if (ses->status.show_leds) xend -= term->leds_length;#endif width = int_max(0, xend - msglen - tab_info_len - 1); if (width < 6) return; int_upper_bound(&width, 20); download_progress_bar(term, xend - width, term->height - 1, width, NULL, NULL, download->progress->pos, download->progress->size); }}static inline voiddisplay_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"); struct session_status *status = &ses->status; int tab_width = int_max(1, term->width / tabs_count); int tab_total_width = tab_width * tabs_count; int tab_remain_width = int_max(0, term->width - tab_total_width); int tab_add = int_max(1, (tab_remain_width / tabs_count)); int tab_num; struct box box; set_box(&box, 0, term->height - (status->show_status_bar ? 2 : 1), 0, 1); for (tab_num = 0; tab_num < tabs_count; tab_num++) { struct download *download = NULL; struct color_pair *color = normal_color; struct window *tab = get_tab_by_number(term, tab_num); struct document_view *doc_view; struct session *tab_ses = tab->data; int actual_tab_width = tab_width - 1; unsigned char *msg; /* Adjust tab size to use full term width. */ if (tab_remain_width) { actual_tab_width += tab_add; tab_remain_width -= tab_add; } doc_view = tab_ses ? current_frame(tab_ses) : NULL; if (doc_view) { if (doc_view->document->title && *(doc_view->document->title)) msg = doc_view->document->title; else msg = _("Untitled", term); } else { msg = _("No document", term); } if (tab_num) { draw_char(term, box.x, box.y, BORDER_SVLINE, SCREEN_ATTR_FRAME, tabsep_color); box.x++; } if (tab_num == term->current_tab) { color = selected_color; } else { download = get_current_download(tab_ses); if (download && download->state != S_OK) { color = loading_color; } else if (!tab_ses || !tab_ses->status.visited) { color = fresh_color; } if (!download_is_progressing(download) || download->progress->size <= 0) download = NULL; } box.width = actual_tab_width + 1; draw_box(term, &box, ' ', 0, color); if (download) { download_progress_bar(term, box.x, box.y, actual_tab_width, msg, NULL, download->progress->pos, download->progress->size); } else { int msglen = int_min(strlen(msg), actual_tab_width); draw_text(term, box.x, box.y, msg, msglen, 0, color); } tab->xpos = box.x; tab->width = actual_tab_width; if (tab_num == tabs_count - 1) { /* This is the last tab, and is therefore followed * by a space, not a separator; increment tab->width * to count that space as part of the tab. * -- Miciah */ tab->width++; } box.x += actual_tab_width; }}/* Print page's title and numbering at window top. */static inline voiddisplay_title_bar(struct session *ses, struct terminal *term){ struct document_view *doc_view; struct document *document; struct string title; unsigned char buf[40]; int buflen = 0; int height; struct box box; /* Clear the old title */ set_box(&box, 0, 0, term->width, 1); draw_box(term, &box, ' ', 0, get_bfu_color(term, "title.title-bar")); doc_view = current_frame(ses); if (!doc_view || !doc_view->document) return; if (!init_string(&title)) return; document = doc_view->document; /* Set up the document page info string: '(' %page '/' %pages ')' */ height = doc_view->box.height; if (height < document->height && doc_view->vs) { int pos = doc_view->vs->y + height; int page = 1; int pages = height ? (document->height + height - 1) / height : 1; /* Check if at the end else calculate the page. */ if (pos >= document->height) { page = pages; } else if (height) { page = int_min((pos - height / 2) / height + 1, pages); } buflen = snprintf(buf, sizeof(buf), " (%d/%d)", page, pages); if (buflen < 0) buflen = 0; } if (document->title) { int maxlen = int_max(term->width - 4 - buflen, 0); int titlelen = int_min(strlen(document->title), maxlen); add_bytes_to_string(&title, document->title, titlelen); if (titlelen == maxlen) add_bytes_to_string(&title, "...", 3); } if (buflen > 0) add_bytes_to_string(&title, buf, buflen); if (title.length) { int 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")); } done_string(&title);}static inline voiddisplay_window_title(struct session *ses, struct terminal *term){ static struct session *last_ses; struct session_status *status = &ses->status; unsigned char *doc_title = NULL; unsigned char *title; int titlelen; if (ses->doc_view && ses->doc_view->document && ses->doc_view->document->title && ses->doc_view->document->title[0]) doc_title = ses->doc_view->document->title; title = straconcat("ELinks", doc_title ? " - " : NULL, doc_title, NULL); if (!title) return; titlelen = strlen(title); if (last_ses != ses || !status->last_title || strlen(status->last_title) != titlelen || memcmp(status->last_title, title, titlelen)) { mem_free_set(&status->last_title, title); set_terminal_title(term, title); last_ses = ses; } else { mem_free(title); }}#ifdef CONFIG_LEDSstatic inline voiddisplay_leds(struct session *ses, struct session_status *status){ if (ses->doc_view && ses->doc_view->document && ses->doc_view->document->uri) { struct cache_entry *cached = find_in_cache(ses->doc_view->document->uri); if (cached) { status->ssl_led->value = (cached->ssl_info) ? 'S' : '-'; } else { /* FIXME: We should do this thing better. */ status->ssl_led->value = '?'; } } if (ses->insert_mode == INSERT_MODE_LESS) { status->insert_mode_led->value = 'i'; } else { unsigned char value = ses->insert_mode == INSERT_MODE_ON ? 'I' : '-'; status->insert_mode_led->value = value; } draw_leds(ses);}#endif /* CONFIG_LEDS *//* Print statusbar and titlebar, set terminal title. */voidprint_screen_status(struct session *ses){ struct terminal *term = ses->tab->term; struct session_status *status = &ses->status; int tabs_count = number_of_tabs(term); int ses_tab_is_current = (ses->tab == get_current_tab(term)); if (ses_tab_is_current) { if (status->set_window_title) display_window_title(ses, term); if (status->show_title_bar) display_title_bar(ses, term); if (status->show_status_bar) display_status_bar(ses, term, tabs_count);#ifdef CONFIG_LEDS if (status->show_leds) display_leds(ses, status);#endif if (!ses->status.visited) ses->status.visited = 1; } if (status->show_tabs_bar) { display_tab_bar(ses, term, tabs_count); } redraw_from_window(ses->tab);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -