void script_buffer_display_detail_script (struct t_script_repo *script) { struct tm *tm; char str_time[1024]; char *labels[] = { N_("Script"), N_("Version"), N_("Version loaded"), N_("Author"), N_("License"), N_("Description"), N_("Tags"), N_("Status"), N_("Date added"), N_("Date updated"), N_("URL"), N_("MD5"), N_("Requires"), N_("Min WeeChat"), N_("Max WeeChat"), NULL }; int i, length, max_length, line; struct t_weelist *list; struct t_weelist_item *ptr_item; max_length = 0; for (i = 0; labels[i]; i++) { length = weechat_utf8_strlen_screen (_(labels[i])); if (length > max_length) max_length = length; } line = 0; weechat_printf_y (script_buffer, line + 1, "%s: %s%s%s.%s", script_buffer_detail_label (_(labels[line]), max_length), weechat_color (weechat_config_string (script_config_color_text_name)), script->name, weechat_color (weechat_config_string (script_config_color_text_extension)), script_extension[script->language]); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s%s", script_buffer_detail_label (_(labels[line]), max_length), weechat_color (weechat_config_string (script_config_color_text_version)), script->version); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s%s", script_buffer_detail_label (_(labels[line]), max_length), weechat_color (weechat_config_string (script_config_color_text_version_loaded)), (script->version_loaded) ? script->version_loaded : "-"); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s <%s>", script_buffer_detail_label (_(labels[line]), max_length), script->author, script->mail); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), script->license); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), script->description); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), script->tags); line++; if ((script->popularity == 0) && (script->status == 0)) { weechat_printf_y (script_buffer, line + 1, "%s: -", script_buffer_detail_label (_(labels[line]), max_length)); } else { weechat_printf_y (script_buffer, line + 1, "%s: %s%s (%s)", script_buffer_detail_label (_(labels[line]), max_length), script_repo_get_status_for_display (script, "*iaHrN", 1), weechat_color ("chat"), script_repo_get_status_desc_for_display (script, "*iaHrN")); } line++; tm = localtime (&script->date_added); strftime (str_time, sizeof (str_time), "%Y-%m-%d %H:%M:%S", tm); weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), str_time); line++; tm = localtime (&script->date_updated); strftime (str_time, sizeof (str_time), "%Y-%m-%d %H:%M:%S", tm); weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), str_time); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), script->url); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), script->md5sum); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), (script->requirements) ? script->requirements : "-"); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), (script->min_weechat) ? script->min_weechat : "-"); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), (script->max_weechat) ? script->max_weechat : "-"); line++; if (script->status & SCRIPT_STATUS_RUNNING) { list = script_buffer_get_script_usage (script); if (list) { line++; weechat_printf_y (script_buffer, line + 1, _("Script has defined:")); i = 0; ptr_item = weechat_list_get (list, 0); while (ptr_item) { line++; weechat_printf_y (script_buffer, line + 1, " %s", weechat_list_string (ptr_item)); ptr_item = weechat_list_next (ptr_item); i++; } if (i == 0) { line++; weechat_printf_y (script_buffer, line + 1, " %s", _("(nothing)")); } line++; weechat_list_free (list); } } script_buffer_detail_script_last_line = line + 2; script_buffer_detail_script_line_diff = -1; }
void script_buffer_display_line_script (int line, struct t_script_repo *script) { char str_line[16384], str_item[1024], str_color_name[256], str_color[32]; char str_format[256], str_date[64], str_key[2], utf_char[16], *tags; const char *columns, *ptr_col; int char_size, *ptr_max_length, max_length, num_spaces, unknown; struct tm *tm; snprintf (str_color_name, sizeof (str_color_name), "%s,%s", (line == script_buffer_selected_line) ? weechat_config_string (script_config_color_text_selected) : weechat_config_string (script_config_color_text), (line == script_buffer_selected_line) ? weechat_config_string (script_config_color_text_bg_selected) : weechat_config_string (script_config_color_text_bg)); snprintf (str_color, sizeof (str_color), "%s", weechat_color (str_color_name)); columns = weechat_config_string (script_config_look_columns); ptr_col = columns; str_line[0] = '\0'; while (ptr_col[0]) { unknown = 0; str_item[0] = '\0'; num_spaces = 0; char_size = weechat_utf8_char_size (ptr_col); memcpy (utf_char, ptr_col, char_size); utf_char[char_size] = '\0'; if (utf_char[0] == '%') { ptr_col += char_size; char_size = weechat_utf8_char_size (ptr_col); memcpy (utf_char, ptr_col, char_size); utf_char[char_size] = '\0'; str_key[0] = ptr_col[0]; str_key[1] = '\0'; ptr_max_length = weechat_hashtable_get (script_repo_max_length_field, str_key); max_length = (ptr_max_length) ? *ptr_max_length : 0; num_spaces = max_length; switch (utf_char[0]) { case 'a': /* author */ if (script->author) { num_spaces = max_length - weechat_utf8_strlen_screen (script->author); snprintf (str_item, sizeof (str_item), "%s", script->author); } break; case 'd': /* description */ if (script->description) { num_spaces = max_length - weechat_utf8_strlen_screen (script->description); snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_description_selected : script_config_color_text_description)), script->description); } break; case 'D': /* date added */ if (script->date_added > 0) { tm = localtime (&script->date_added); strftime (str_date, sizeof (str_date), "%Y-%m-%d", tm); snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_date_selected : script_config_color_text_date)), str_date); } else num_spaces = 10; break; case 'e': /* file extension */ if (script->language >= 0) { num_spaces = max_length - weechat_utf8_strlen_screen (script_extension[script->language]); snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_extension_selected : script_config_color_text_extension)), script_extension[script->language]); } break; case 'l': /* language */ if (script->language >= 0) { num_spaces = max_length - weechat_utf8_strlen_screen (script_language[script->language]); snprintf (str_item, sizeof (str_item), "%s", script_language[script->language]); } break; case 'L': /* license */ if (script->license) { num_spaces = max_length - weechat_utf8_strlen_screen (script->license); snprintf (str_item, sizeof (str_item), "%s", script->license); } break; case 'n': /* name + extension */ if (script->name_with_extension) { num_spaces = max_length - weechat_utf8_strlen_screen (script->name_with_extension); snprintf (str_item, sizeof (str_item), "%s%s%s.%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_name_selected : script_config_color_text_name)), script->name, weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_extension_selected : script_config_color_text_extension)), script_extension[script->language]); } break; case 'N': /* name (without extension) */ if (script->name) { num_spaces = max_length - weechat_utf8_strlen_screen (script->name); snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_name_selected : script_config_color_text_name)), script->name); } break; case 'r': /* requirements */ if (script->requirements) { num_spaces = max_length - weechat_utf8_strlen_screen (script->requirements); snprintf (str_item, sizeof (str_item), "%s", script->requirements); } break; case 's': /* status */ snprintf (str_item, sizeof (str_item), "%s", script_repo_get_status_for_display (script, "*iaHrN", 0)); break; case 't': /* tags */ if (script->tags) { num_spaces = max_length - weechat_utf8_strlen_screen (script->tags); tags = weechat_string_replace (script->tags, ",", " "); if (tags) { snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_tags_selected : script_config_color_text_tags)), tags); free (tags); } } break; case 'u': /* date updated */ if (script->date_updated > 0) { tm = localtime (&script->date_updated); strftime (str_date, sizeof (str_date), "%Y-%m-%d", tm); snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_date_selected : script_config_color_text_date)), str_date); } else num_spaces = 10; break; case 'v': /* version */ if (script->version) { num_spaces = max_length - weechat_utf8_strlen_screen (script->version); snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_version_selected : script_config_color_text_version)), script->version); } break; case 'V': /* version loaded */ if (script->version_loaded) { num_spaces = max_length - weechat_utf8_strlen_screen (script->version_loaded); snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_version_loaded_selected : script_config_color_text_version_loaded)), script->version_loaded); } break; case 'w': /* min_weechat */ if (script->min_weechat) { num_spaces = max_length - weechat_utf8_strlen_screen (script->min_weechat); snprintf (str_item, sizeof (str_item), "%s", script->min_weechat); } break; case 'W': /* max_weechat */ if (script->max_weechat) { num_spaces = max_length - weechat_utf8_strlen_screen (script->max_weechat); snprintf (str_item, sizeof (str_item), "%s", script->max_weechat); } break; case '%': /* "%%" will display a single "%" */ snprintf (str_item, sizeof (str_item), "%s%%", weechat_color (weechat_config_string (script_config_color_text_delimiters))); break; default: unknown = 1; break; } } else { snprintf (str_item, sizeof (str_item), "%s%s", weechat_color (weechat_config_string (script_config_color_text_delimiters)), utf_char); } if (!unknown) { if (str_item[0]) { strcat (str_line, str_color); strcat (str_line, str_item); } if (num_spaces > 0) { snprintf (str_format, sizeof (str_format), "%%-%ds", num_spaces); snprintf (str_item, sizeof (str_item), str_format, " "); strcat (str_line, str_item); } } ptr_col += char_size; } weechat_printf_y (script_buffer, line, "%s", str_line); }
void exec_end_command (struct t_exec_cmd *exec_cmd, int return_code) { struct t_gui_buffer *ptr_buffer; struct t_hashtable *hashtable; char str_number[32], *output; int i, buffer_type; if (exec_cmd->hsignal) { hashtable = weechat_hashtable_new (32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, NULL, NULL); if (hashtable) { weechat_hashtable_set (hashtable, "command", exec_cmd->command); snprintf (str_number, sizeof (str_number), "%d", exec_cmd->number); weechat_hashtable_set (hashtable, "number", str_number); weechat_hashtable_set (hashtable, "name", exec_cmd->name); output = exec_decode_color (exec_cmd, exec_cmd->output[EXEC_STDOUT]); weechat_hashtable_set (hashtable, "out", output); if (output) free (output); output = exec_decode_color (exec_cmd, exec_cmd->output[EXEC_STDERR]); weechat_hashtable_set (hashtable, "err", output); if (output) free (output); snprintf (str_number, sizeof (str_number), "%d", return_code); weechat_hashtable_set (hashtable, "rc", str_number); weechat_hook_hsignal_send (exec_cmd->hsignal, hashtable); weechat_hashtable_free (hashtable); } } else { ptr_buffer = weechat_buffer_search ("==", exec_cmd->buffer_full_name); /* display the last line of output (if not ending with '\n') */ exec_display_line (exec_cmd, ptr_buffer, EXEC_STDOUT, exec_cmd->output[EXEC_STDOUT]); exec_display_line (exec_cmd, ptr_buffer, EXEC_STDERR, exec_cmd->output[EXEC_STDERR]); /* * display return code (only if command is not detached, if output is * NOT sent to buffer, and if command is not piped) */ if (exec_cmd->display_rc && !exec_cmd->detached && !exec_cmd->output_to_buffer && !exec_cmd->pipe_command) { buffer_type = weechat_buffer_get_integer (ptr_buffer, "type"); if (return_code >= 0) { if (buffer_type == 1) { weechat_printf_y (ptr_buffer, -1, ("%s: end of command %d (\"%s\"), " "return code: %d"), EXEC_PLUGIN_NAME, exec_cmd->number, exec_cmd->command, return_code); } else { weechat_printf_date_tags ( ptr_buffer, 0, "exec_rc", _("%s: end of command %d (\"%s\"), " "return code: %d"), EXEC_PLUGIN_NAME, exec_cmd->number, exec_cmd->command, return_code); } } else { if (buffer_type == 1) { weechat_printf_y (ptr_buffer, -1, _("%s: unexpected end of command %d " "(\"%s\")"), EXEC_PLUGIN_NAME, exec_cmd->number, exec_cmd->command); } else { weechat_printf_date_tags ( ptr_buffer, 0, "exec_rc", _("%s: unexpected end of command %d " "(\"%s\")"), EXEC_PLUGIN_NAME, exec_cmd->number, exec_cmd->command); } } } } /* (re)set some variables after the end of command */ exec_cmd->hook = NULL; exec_cmd->pid = 0; exec_cmd->end_time = time (NULL); exec_cmd->return_code = return_code; for (i = 0; i < 2; i++) { if (exec_cmd->output[i]) { free (exec_cmd->output[i]); exec_cmd->output[i] = NULL; } exec_cmd->output_size[i] = 0; } /* schedule a timer to remove the executed command */ if (weechat_config_integer (exec_config_command_purge_delay) >= 0) { weechat_hook_timer (1 + (1000 * weechat_config_integer (exec_config_command_purge_delay)), 0, 1, &exec_timer_delete_cb, exec_cmd, NULL); } }
void exec_display_line (struct t_exec_cmd *exec_cmd, struct t_gui_buffer *buffer, int out, const char *line) { char *line_color, *line_color2, *line2, str_number[32], str_tags[1024]; const char *ptr_line_color; int length; if (!exec_cmd || !line) return; /* * if output is sent to the buffer, the buffer must exist * (we don't send output by default to core buffer) */ if (exec_cmd->output_to_buffer && !exec_cmd->pipe_command && !buffer) return; /* decode colors */ line_color = exec_decode_color (exec_cmd, line); if (!line_color) return; exec_cmd->output_line_nb++; if (exec_cmd->pipe_command) { if (strstr (exec_cmd->pipe_command, "$line")) { /* replace $line by line content */ line2 = weechat_string_replace (exec_cmd->pipe_command, "$line", line_color); if (line2) { weechat_command (buffer, line2); free (line2); } } else { /* add line at the end of command, after a space */ length = strlen (exec_cmd->pipe_command) + 1 + strlen (line_color) + 1; line2 = malloc (length); if (line2) { snprintf (line2, length, "%s %s", exec_cmd->pipe_command, line_color); weechat_command (buffer, line2); free (line2); } } } else if (exec_cmd->output_to_buffer) { if (exec_cmd->line_numbers) { length = 32 + strlen (line_color) + 1; line2 = malloc (length); if (line2) { snprintf (line2, length, "%d. %s", exec_cmd->output_line_nb, line_color); weechat_command (buffer, line2); free (line2); } } else { if (exec_cmd->output_to_buffer_exec_cmd) ptr_line_color = line_color; else ptr_line_color = weechat_string_input_for_buffer (line_color); if (ptr_line_color) { weechat_command (buffer, (ptr_line_color[0]) ? ptr_line_color : " "); } else { length = 1 + strlen (line_color) + 1; line_color2 = malloc (length); if (line_color2) { snprintf (line_color2, length, "%c%s", line_color[0], line_color); weechat_command (buffer, (line_color2[0]) ? line_color2 : " "); free (line_color2); } } } } else { snprintf (str_number, sizeof (str_number), "%d", exec_cmd->number); snprintf (str_tags, sizeof (str_tags), "exec_%s,exec_cmd_%s", (out == EXEC_STDOUT) ? "stdout" : "stderr", (exec_cmd->name) ? exec_cmd->name : str_number); if (weechat_buffer_get_integer (buffer, "type") == 1) { snprintf (str_number, sizeof (str_number), "%d. ", exec_cmd->output_line_nb); weechat_printf_y (buffer, -1, "%s%s", (exec_cmd->line_numbers) ? str_number : " ", line_color); } else { snprintf (str_number, sizeof (str_number), "%d\t", exec_cmd->output_line_nb); weechat_printf_date_tags ( buffer, 0, str_tags, "%s%s", (exec_cmd->line_numbers) ? str_number : " \t", line_color); } } free (line_color); }
void relay_buffer_refresh (const char *hotlist) { struct t_relay_client *ptr_client, *client_selected; char str_color[256], str_status[64], str_date_start[128], str_date_end[128]; char *str_recv, *str_sent; int i, length, line; struct tm *date_tmp; if (relay_buffer) { weechat_buffer_clear (relay_buffer); line = 0; client_selected = relay_client_search_by_number (relay_buffer_selected_line); weechat_printf_y (relay_buffer, 0, "%s%s%s%s%s%s%s", weechat_color("green"), _("Actions (letter+enter):"), weechat_color("lightgreen"), /* disconnect */ (client_selected && !RELAY_CLIENT_HAS_ENDED(client_selected)) ? _(" [D] Disconnect") : "", /* remove */ (client_selected && RELAY_CLIENT_HAS_ENDED(client_selected)) ? _(" [R] Remove") : "", /* purge old */ _(" [P] Purge finished"), /* quit */ _(" [Q] Close this buffer")); for (ptr_client = relay_clients; ptr_client; ptr_client = ptr_client->next_client) { snprintf (str_color, sizeof (str_color), "%s,%s", (line == relay_buffer_selected_line) ? weechat_config_string (relay_config_color_text_selected) : weechat_config_string (relay_config_color_text), weechat_config_string (relay_config_color_text_bg)); snprintf (str_status, sizeof (str_status), "%s", _(relay_client_status_string[ptr_client->status])); length = weechat_utf8_strlen_screen (str_status); if (length < 20) { for (i = 0; i < 20 - length; i++) { strcat (str_status, " "); } } str_date_start[0] = '\0'; date_tmp = localtime (&(ptr_client->start_time)); if (date_tmp) { strftime (str_date_start, sizeof (str_date_start), "%a, %d %b %Y %H:%M:%S", date_tmp); } str_date_end[0] = '-'; str_date_end[1] = '\0'; if (ptr_client->end_time > 0) { date_tmp = localtime (&(ptr_client->end_time)); if (date_tmp) { strftime (str_date_end, sizeof (str_date_end), "%a, %d %b %Y %H:%M:%S", date_tmp); } } str_recv = weechat_string_format_size (ptr_client->bytes_recv); str_sent = weechat_string_format_size (ptr_client->bytes_sent); /* first line with status, description and bytes recv/sent */ weechat_printf_y (relay_buffer, (line * 2) + 2, _("%s%s[%s%s%s%s] %s, received: %s, sent: %s"), weechat_color(str_color), (line == relay_buffer_selected_line) ? "*** " : " ", weechat_color(weechat_config_string (relay_config_color_status[ptr_client->status])), str_status, weechat_color ("reset"), weechat_color (str_color), ptr_client->desc, (str_recv) ? str_recv : "?", (str_sent) ? str_sent : "?"); /* second line with start/end time */ weechat_printf_y (relay_buffer, (line * 2) + 3, _("%s%-26s started on: %s, ended on: %s"), weechat_color(str_color), " ", str_date_start, str_date_end); if (str_recv) free (str_recv); if (str_sent) free (str_sent); line++; } if (hotlist) weechat_buffer_set (relay_buffer, "hotlist", hotlist); } }
void xfer_buffer_refresh (const char *hotlist) { struct t_xfer *ptr_xfer, *xfer_selected; char str_color[256], suffix[32], status[64], date[128], eta[128]; char str_ip[128], str_hash[128]; char *progress_bar, *str_pos, *str_total, *str_bytes_per_sec; int i, length, line, progress_bar_size, num_bars; unsigned long long pos, pct_complete; struct tm *date_tmp; if (xfer_buffer) { weechat_buffer_clear (xfer_buffer); line = 0; xfer_selected = xfer_search_by_number (xfer_buffer_selected_line); weechat_printf_y (xfer_buffer, 0, "%s%s%s%s%s%s%s%s", weechat_color ("green"), _("Actions (letter+enter):"), weechat_color ("lightgreen"), /* accept */ (xfer_selected && XFER_IS_RECV(xfer_selected->type) && (xfer_selected->status == XFER_STATUS_WAITING)) ? _(" [A] Accept") : "", /* cancel */ (xfer_selected && !XFER_HAS_ENDED(xfer_selected->status)) ? _(" [C] Cancel") : "", /* remove */ (xfer_selected && XFER_HAS_ENDED(xfer_selected->status)) ? _(" [R] Remove") : "", /* purge old */ _(" [P] Purge finished"), /* quit */ _(" [Q] Close this buffer")); for (ptr_xfer = xfer_list; ptr_xfer; ptr_xfer = ptr_xfer->next_xfer) { suffix[0] = '\0'; if (ptr_xfer->filename_suffix >= 0) { snprintf (suffix, sizeof (suffix), " (.%d)", ptr_xfer->filename_suffix); } snprintf (str_color, sizeof (str_color), "%s,%s", (line == xfer_buffer_selected_line) ? weechat_config_string (xfer_config_color_text_selected) : weechat_config_string (xfer_config_color_text), weechat_config_string (xfer_config_color_text_bg)); str_ip[0] = '\0'; if (ptr_xfer->remote_address_str) { snprintf (str_ip, sizeof (str_ip), " (%s)", ptr_xfer->remote_address_str); } str_hash[0] = '\0'; if (ptr_xfer->hash_target && ptr_xfer->hash_handle && (ptr_xfer->hash_status != XFER_HASH_STATUS_UNKNOWN) && ((ptr_xfer->status == XFER_STATUS_ACTIVE) || (ptr_xfer->status == XFER_STATUS_DONE) || (ptr_xfer->status == XFER_STATUS_HASHING))) { snprintf (str_hash, sizeof (str_hash), " (%s)", _(xfer_hash_status_string[ptr_xfer->hash_status])); } /* display first line with remote nick, filename and plugin name/id */ weechat_printf_y (xfer_buffer, (line * 2) + 2, "%s%s%-24s %s%s%s%s (%s.%s)%s%s", weechat_color (str_color), (line == xfer_buffer_selected_line) ? "*** " : " ", ptr_xfer->remote_nick, (XFER_IS_FILE(ptr_xfer->type)) ? "\"" : "", (XFER_IS_FILE(ptr_xfer->type)) ? ptr_xfer->filename : _("xfer chat"), (XFER_IS_FILE(ptr_xfer->type)) ? "\"" : "", suffix, ptr_xfer->plugin_name, ptr_xfer->plugin_id, str_ip, str_hash); snprintf (status, sizeof (status), "%s", _(xfer_status_string[ptr_xfer->status])); length = weechat_utf8_strlen_screen (status); if (length < 20) { for (i = 0; i < 20 - length; i++) { strcat (status, " "); } } if (XFER_IS_CHAT(ptr_xfer->type)) { /* display second line for chat with status and date */ date[0] = '\0'; date_tmp = localtime (&(ptr_xfer->start_time)); if (date_tmp) { if (strftime (date, sizeof (date), "%a, %d %b %Y %H:%M:%S", date_tmp) == 0) date[0] = '\0'; } weechat_printf_y (xfer_buffer, (line * 2) + 3, "%s%s%s %s%s%s%s%s", weechat_color (str_color), (line == xfer_buffer_selected_line) ? "*** " : " ", (XFER_IS_SEND(ptr_xfer->type)) ? "<<--" : "-->>", weechat_color (weechat_config_string (xfer_config_color_status[ptr_xfer->status])), status, weechat_color ("reset"), weechat_color (str_color), date); } else { /* build progress bar */ pos = (ptr_xfer->pos <= ptr_xfer->size) ? ptr_xfer->pos : ptr_xfer->size; progress_bar = NULL; progress_bar_size = weechat_config_integer (xfer_config_look_progress_bar_size); if (progress_bar_size > 0) { progress_bar = malloc (1 + progress_bar_size + 1 + 1 + 1); strcpy (progress_bar, "["); if (ptr_xfer->size == 0) { if (ptr_xfer->status == XFER_STATUS_DONE) num_bars = progress_bar_size; else num_bars = 0; } else num_bars = (int)(((float)(pos)/(float)(ptr_xfer->size)) * (float)progress_bar_size); for (i = 0; i < num_bars - 1; i++) { strcat (progress_bar, "="); } if (num_bars > 0) strcat (progress_bar, ">"); for (i = 0; i < progress_bar_size - num_bars; i++) { strcat (progress_bar, " "); } strcat (progress_bar, "] "); } /* computes percentage */ if (ptr_xfer->size == 0) { if (ptr_xfer->status == XFER_STATUS_DONE) pct_complete = 100; else pct_complete = 0; } else pct_complete = (unsigned long long)(((float)(pos)/(float)(ptr_xfer->size)) * 100); /* position, total and bytes per second */ str_pos = weechat_string_format_size (pos); str_total = weechat_string_format_size (ptr_xfer->size); str_bytes_per_sec = weechat_string_format_size (ptr_xfer->bytes_per_sec); /* ETA */ eta[0] = '\0'; if (ptr_xfer->status == XFER_STATUS_ACTIVE) { snprintf (eta, sizeof (eta), "%s: %.2llu:%.2llu:%.2llu - ", _("ETA"), ptr_xfer->eta / 3600, (ptr_xfer->eta / 60) % 60, ptr_xfer->eta % 60); } /* display second line for file with status, progress bar and estimated time */ weechat_printf_y (xfer_buffer, (line * 2) + 3, "%s%s%s %s%s%s%s%3llu%% %s / %s (%s%s/s)", weechat_color (str_color), (line == xfer_buffer_selected_line) ? "*** " : " ", (XFER_IS_SEND(ptr_xfer->type)) ? "<<--" : "-->>", weechat_color (weechat_config_string (xfer_config_color_status[ptr_xfer->status])), status, weechat_color (str_color), (progress_bar) ? progress_bar : "", pct_complete, (str_pos) ? str_pos : "?", (str_total) ? str_total : "?", eta, str_bytes_per_sec); if (progress_bar) free (progress_bar); if (str_pos) free (str_pos); if (str_total) free (str_total); if (str_bytes_per_sec) free (str_bytes_per_sec); } line++; } weechat_buffer_set (xfer_buffer, "hotlist", hotlist); } }