📄 status.c
字号:
/* Sessions status managment *//* $Id: status.c,v 1.95.2.3 2005/05/01 21:00:42 jonas Exp $ */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include <string.h>#include "elinks.h"#include "bfu/dialog.h"#include "cache/cache.h"#include "config/options.h"#include "dialogs/download.h"#include "dialogs/status.h"#include "document/document.h"#include "document/renderer.h"#include "document/view.h"#include "intl/gettext/libintl.h"#include "protocol/uri.h"#include "sched/connection.h"#include "sched/error.h"#include "sched/session.h"#include "terminal/draw.h"#include "terminal/screen.h"#include "terminal/tab.h"#include "terminal/terminal.h"#include "terminal/window.h"#include "util/color.h"#include "util/conv.h"#include "util/error.h"#include "util/memory.h"#include "util/snprintf.h"#include "util/string.h"#include "viewer/text/form.h"#include "viewer/text/link.h"#include "viewer/text/view.h"#define average_speed(progress) \ ((longlong) (progress)->loaded * 10 / ((progress)->elapsed / 100))#define current_speed(progress) \ ((progress)->cur_loaded / (CURRENT_SPD_SEC * SPD_DISP_TIME / 1000))#define estimated_time(progress) \ (((progress)->size - (progress)->pos) \ / ((longlong) (progress)->loaded * 10 / ((progress)->elapsed / 100)) \ * 1000)unsigned char *get_download_msg(struct download *download, struct terminal *term, int wide, int full, unsigned char *separator){ struct string msg; int newlines = separator[strlen(separator) - 1] == '\n'; if (!download_is_progressing(download)) { /* DBG("%d -> %s", download->state, _(get_err_msg(download->state), term)); */ return stracpy(get_err_msg(download->state, term)); } if (!init_string(&msg)) return NULL; /* FIXME: The following is a PITA from the l10n standpoint. A *big* * one, _("of")-like pearls are a nightmare. Format strings need to * be introduced to this fuggy corner of code as well. --pasky */ add_to_string(&msg, _("Received", term)); add_char_to_string(&msg, ' '); add_xnum_to_string(&msg, download->progress->pos); if (download->progress->size >= 0) { add_char_to_string(&msg, ' '); add_to_string(&msg, _("of", term)); add_char_to_string(&msg, ' '); add_xnum_to_string(&msg, download->progress->size); } add_to_string(&msg, separator); if (wide && download->progress->elapsed >= CURRENT_SPD_AFTER * SPD_DISP_TIME) { add_to_string(&msg, _(full ? (newlines ? N_("Average speed") : N_("average speed")) : N_("avg"), term)); } else { add_to_string(&msg, _(newlines ? N_("Speed") : N_("speed"), term)); } add_char_to_string(&msg, ' '); add_xnum_to_string(&msg, average_speed(download->progress)); add_to_string(&msg, "/s"); if (wide && download->progress->elapsed >= CURRENT_SPD_AFTER * SPD_DISP_TIME) { add_to_string(&msg, ", "); add_to_string(&msg, _(full ? N_("current speed") : N_("cur"), term)); add_char_to_string(&msg, ' '), add_xnum_to_string(&msg, current_speed(download->progress)); add_to_string(&msg, "/s"); } if (wide) { /* Do the following only if there is room */ add_to_string(&msg, separator); add_to_string(&msg, _(full ? (newlines ? N_("Elapsed time") : N_("elapsed time")) : N_("ETT"), term)); add_char_to_string(&msg, ' '); add_time_to_string(&msg, download->progress->elapsed); } if (download->progress->size >= 0 && download->progress->loaded > 0) { add_to_string(&msg, ", "); add_to_string(&msg, _(full ? N_("estimated time") : N_("ETA"), term)); add_char_to_string(&msg, ' '); add_time_to_string(&msg, estimated_time(download->progress)); } return msg.source;}#define show_tabs(option, tabs) (((option) > 0) && !((option) == 1 && (tabs) < 2))voidupdate_status(void){ int show_title_bar = get_opt_bool("ui.show_title_bar"); int show_status_bar = get_opt_bool("ui.show_status_bar"); int show_tabs_bar = get_opt_int("ui.tabs.show_bar");#ifdef CONFIG_LEDS int show_leds = get_opt_bool("ui.leds.enable");#endif int set_window_title = get_opt_bool("ui.window_title"); int insert_mode = get_opt_bool("document.browse.forms.insert_mode"); struct session *ses; int tabs = 1; struct terminal *term = NULL; foreach (ses, sessions) { struct session_status *status = &ses->status; int dirty = 0; /* Try to descrease the number of tab calculation using that * tab sessions share the same term. */ if (ses->tab->term != term) { term = ses->tab->term; tabs = number_of_tabs(term); } if (status->force_show_title_bar >= 0) show_title_bar = status->force_show_title_bar; if (status->show_title_bar != show_title_bar) { status->show_title_bar = show_title_bar; dirty = 1; } if (status->force_show_status_bar >= 0) show_status_bar = status->force_show_status_bar; if (status->show_status_bar != show_status_bar) { status->show_status_bar = show_status_bar; dirty = 1; } if (show_tabs(show_tabs_bar, tabs) != status->show_tabs_bar) { status->show_tabs_bar = show_tabs(show_tabs_bar, tabs); dirty = 1; }#ifdef CONFIG_LEDS if (status->show_leds != show_leds) { status->show_leds = show_leds; dirty = 1; }#endif status->set_window_title = set_window_title; /* This more belongs to the current browsing state but ... */ if (!insert_mode) ses->insert_mode = INSERT_MODE_LESS; else if (ses->insert_mode == INSERT_MODE_LESS) ses->insert_mode = INSERT_MODE_OFF; if (!dirty) continue; /* Force the current document to be rerendered so the * document view and document height is updated to fit * into the new dimensions. Related to bug 87. */ render_document_frames(ses, 1); set_screen_dirty(term->screen, 0, term->height); }}static unsigned char *get_current_link_info_and_title(struct session *ses, struct document_view *doc_view){ unsigned char *link_info, *link_title, *ret = NULL; link_info = get_current_link_info(ses, doc_view); if (!link_info) return NULL; link_title = get_current_link_title(doc_view); if (link_title) { assert(*link_title); ret = straconcat(link_info, " - ", link_title, NULL); mem_free(link_info); mem_free(link_title); } if (!ret) ret = link_info; return ret;}static inline voiddisplay_status_bar(struct session *ses, struct terminal *term, int tabs_count){ unsigned char *msg = NULL; 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; int msglen; struct box box;#ifdef CONFIG_MARKS if (ses->kbdprefix.mark != KP_MARK_NOTHING) { switch (ses->kbdprefix.mark) { case KP_MARK_NOTHING: assert(0); break; case KP_MARK_SET: msg = msg_text(term, N_("Enter a mark to set")); break; case KP_MARK_GOTO: msg = msg_text(term, N_("Enter a mark" " to which to jump")); break; } } else#endif if (ses->kbdprefix.repeat_count) { msg = msg_text(term, N_("Keyboard prefix: %d"), ses->kbdprefix.repeat_count); } else if (download) { struct document_view *doc_view = current_frame(ses); /* Show S_INTERRUPTED message *once* but then show links * again as usual. */ /* doc_view->vs may be NULL here in the short interval between * ses_forward() with @loading_in_frame set, disconnecting the * doc_view from vs, and render_document_frames(), detaching * the doc_view. */ if (doc_view && doc_view->vs) { static int last_current_link; int ncl = doc_view->vs->current_link; if (download->state == S_INTERRUPTED && ncl != last_current_link) download->state = S_OK; last_current_link = ncl; if (download->state == S_OK) { if (get_current_link(doc_view)) { msg = get_current_link_info_and_title(ses, doc_view); } else if (ses->navigate_mode == NAVIGATE_CURSOR_ROUTING) { msg = msg_text(term, N_("Cursor position: %dx%d"), ses->tab->x + 1, ses->tab->y + 1); } } } if (!msg) { /* FIXME: improve that, values should depend on * context (leds, digital clock, ...). --Zas */ int full = term->width > 130; int wide = term->width > 80; msg = get_download_msg(download, term, wide, full, ", "); } } set_box(&box, 0, term->height - 1, term->width, 1); draw_box(term, &box, ' ', 0, get_bfu_color(term, "status.status-bar")); if (!status->show_tabs_bar && tabs_count > 1) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -