1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-27 13:26:38 +02:00

irc: add option -export in command /list, add option irc.look.list_buffer_format_export

This commit is contained in:
Sébastien Helleu
2024-06-09 23:15:26 +02:00
parent fb86ddc770
commit 8824ff7d6c
20 changed files with 566 additions and 32 deletions
+35 -2
View File
@@ -3548,6 +3548,36 @@ IRC_COMMAND_CALLBACK(list)
irc_list_join_channel (ptr_server);
return WEECHAT_RC_OK;
}
if ((argc > 0) && (weechat_strcmp (argv[1], "-export") == 0))
{
WEECHAT_COMMAND_MIN_ARGS(3, argv[1]);
IRC_COMMAND_CHECK_SERVER("list", 1, 1);
if (!ptr_server->list->buffer)
{
weechat_printf (
ptr_server->buffer,
_("%s%s: list buffer is not displayed"),
weechat_prefix ("error"), IRC_PLUGIN_NAME);
return WEECHAT_RC_OK;
}
if (weechat_arraylist_size (ptr_server->list->channels) == 0)
{
weechat_printf (
ptr_server->buffer,
_("%s%s: no channels displayed on list buffer"),
weechat_prefix ("error"), IRC_PLUGIN_NAME);
return WEECHAT_RC_OK;
}
if (!irc_list_export (ptr_server, argv_eol[2]))
{
weechat_printf (
ptr_server->buffer,
_("%s%s: error exporting channels to file \"%s\""),
weechat_prefix ("error"), IRC_PLUGIN_NAME, argv_eol[2]);
return WEECHAT_RC_OK;
}
return WEECHAT_RC_OK;
}
for (i = 1; i < argc; i++)
{
@@ -7507,7 +7537,8 @@ irc_command_init ()
" || -up|-down [<number>]"
" || -left|-right [<percent>]"
" || -go <line>|end"
" || -join"),
" || -join "
" || -export <filename>"),
WEECHAT_CMD_ARGS_DESC(
N_("server: send to this server (internal name)"),
N_("regex: POSIX extended regular expression used to filter results "
@@ -7523,6 +7554,7 @@ irc_command_init ()
N_("raw[-go]: select a line by number, first line number is 0 "
"(\"end\" to select the last line)"),
N_("raw[-join]: join the channel on the selected line"),
N_("raw[-export]: export list of channels to a file"),
"",
N_("For keys, input and mouse actions on the buffer, "
"see key bindings in User's guide."),
@@ -7558,7 +7590,8 @@ irc_command_init ()
" || -left 10|20|30|40|50|60|70|80|90|100"
" || -right 10|20|30|40|50|60|70|80|90|100"
" || -go 0|end"
" || -join",
" || -join"
" || -export %(filename)",
&irc_command_list, NULL, NULL);
weechat_hook_command (
"lusers",
+10
View File
@@ -95,6 +95,7 @@ struct t_config_option *irc_config_look_item_nick_modes = NULL;
struct t_config_option *irc_config_look_item_nick_prefix = NULL;
struct t_config_option *irc_config_look_join_auto_add_chantype = NULL;
struct t_config_option *irc_config_look_list_buffer = NULL;
struct t_config_option *irc_config_look_list_buffer_format_export = NULL;
struct t_config_option *irc_config_look_list_buffer_scroll_horizontal = NULL;
struct t_config_option *irc_config_look_list_buffer_sort = NULL;
struct t_config_option *irc_config_look_list_buffer_topic_strip_colors = NULL;
@@ -3406,6 +3407,15 @@ irc_config_init ()
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL);
irc_config_look_list_buffer_format_export = weechat_config_new_option (
irc_config_file, irc_config_section_look,
"list_buffer_format_export", "string",
N_("format of each channel exported in a file "
"(note: content is evaluated, see /help list)"),
NULL, 0, 0, "${name} (${users}): \"${topic}\"", NULL, 0,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL);
irc_config_look_list_buffer_scroll_horizontal = weechat_config_new_option (
irc_config_file, irc_config_section_look,
"list_buffer_scroll_horizontal", "integer",
+1
View File
@@ -130,6 +130,7 @@ extern struct t_config_option *irc_config_look_item_nick_modes;
extern struct t_config_option *irc_config_look_item_nick_prefix;
extern struct t_config_option *irc_config_look_join_auto_add_chantype;
extern struct t_config_option *irc_config_look_list_buffer;
extern struct t_config_option *irc_config_look_list_buffer_format_export;
extern struct t_config_option *irc_config_look_list_buffer_scroll_horizontal;
extern struct t_config_option *irc_config_look_list_buffer_sort;
extern struct t_config_option *irc_config_look_list_buffer_topic_strip_colors;
+78
View File
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include "../weechat-plugin.h"
@@ -1054,6 +1055,83 @@ irc_list_hsignal_redirect_list_cb (const void *pointer,
return WEECHAT_RC_OK;
}
/*
* Exports channels currently displayed in /list buffer.
*
* Returns:
* 1: export OK
* 0: error
*/
int
irc_list_export (struct t_irc_server *server, const char *filename)
{
int num_filter_channels, i;
char *filename2, *line;
FILE *file;
struct t_irc_list_channel *ptr_channel;
struct t_hashtable *hashtable_pointers, *hashtable_extra_vars;
if (!server || !server->list->buffer)
return 0;
filename2 = weechat_string_expand_home (filename);
if (!filename2)
return 0;
file = fopen (filename2, "w");
if (!file)
{
free (filename2);
return 0;
}
fchmod (fileno (file), 0600);
hashtable_pointers = weechat_hashtable_new (
8,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_POINTER,
NULL, NULL);
hashtable_extra_vars = weechat_hashtable_new (
128,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL, NULL);
weechat_hashtable_set (hashtable_pointers, "irc_server", server);
num_filter_channels = weechat_arraylist_size (server->list->filter_channels);
for (i = 0; i < num_filter_channels; i++)
{
ptr_channel = (struct t_irc_list_channel *)weechat_arraylist_get (
server->list->filter_channels, i);
if (!ptr_channel)
continue;
weechat_hashtable_set (hashtable_pointers, "irc_list_channel", ptr_channel);
irc_list_add_channel_in_hashtable (hashtable_extra_vars, ptr_channel);
line = weechat_string_eval_expression (
weechat_config_string (irc_config_look_list_buffer_format_export),
hashtable_pointers,
hashtable_extra_vars,
NULL);
if (line && line[0])
fprintf (file, "%s\n", line);
free (line);
}
fclose (file);
weechat_hashtable_free (hashtable_pointers);
weechat_hashtable_free (hashtable_extra_vars);
free (filename2);
return 1;
}
/*
* Resets lists used by list buffer.
*/
+1
View File
@@ -67,6 +67,7 @@ extern int irc_list_hsignal_redirect_list_cb (const void *pointer,
void *data,
const char *signal,
struct t_hashtable *hashtable);
extern int irc_list_export (struct t_irc_server *server, const char *filename);
extern void irc_list_reset (struct t_irc_server *server);
extern struct t_irc_list *irc_list_alloc ();
extern void irc_list_free_data (struct t_irc_server *server);