mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
If you're pasting text to channel and some of it starts with /, Irssi
will send the "/command" to channel if it doesn't exist (instead of just printing "unknown command"). git-svn-id: http://svn.irssi.org/repos/irssi/trunk@419 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
eee71a093a
commit
4475a04841
@ -30,6 +30,8 @@
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
#define PASTE_CHECK_SPEED 200 /* 0.2 sec */
|
||||
|
||||
static int ret_texts[] = {
|
||||
IRCTXT_OPTION_UNKNOWN,
|
||||
IRCTXT_OPTION_AMBIGUOUS,
|
||||
@ -51,6 +53,9 @@ static int ret_texts[] = {
|
||||
static const char *current_cmdline;
|
||||
static int hide_output;
|
||||
|
||||
static GTimeVal time_command_last, time_command_now;
|
||||
static int last_command_cmd, command_cmd;
|
||||
|
||||
static int commands_compare(COMMAND_REC *rec, COMMAND_REC *rec2)
|
||||
{
|
||||
if (rec->category == NULL && rec2->category != NULL)
|
||||
@ -284,11 +289,19 @@ static void event_command(const char *data)
|
||||
{
|
||||
const char *cmdchar;
|
||||
|
||||
/* save current command line */
|
||||
current_cmdline = data;
|
||||
|
||||
/* for detecting if we're pasting text */
|
||||
time_command_last = time_command_now;
|
||||
last_command_cmd = command_cmd;
|
||||
|
||||
g_get_current_time(&time_command_now);
|
||||
command_cmd = strchr(settings_get_str("cmdchars"), *data) != NULL;
|
||||
|
||||
/* /^command hides the output of the command */
|
||||
cmdchar = strchr(settings_get_str("cmdchars"), *data);
|
||||
if (cmdchar != NULL && (data[1] == '^' || (data[1] == *cmdchar && data[2] == '^'))) {
|
||||
/* /^command hides the output of the command */
|
||||
hide_output = TRUE;
|
||||
signal_add_first("print text stripped", (SIGNAL_FUNC) sig_stop);
|
||||
signal_add_first("print text", (SIGNAL_FUNC) sig_stop);
|
||||
@ -306,12 +319,15 @@ static void event_command_last(const char *data)
|
||||
|
||||
static void event_default_command(const char *data, void *server, WI_ITEM_REC *item)
|
||||
{
|
||||
const char *ptr;
|
||||
const char *cmdchars, *ptr;
|
||||
char *cmd, *p;
|
||||
long diff;
|
||||
|
||||
cmdchars = settings_get_str("cmdchars");
|
||||
|
||||
ptr = data;
|
||||
while (*ptr != '\0' && *ptr != ' ') {
|
||||
if (strchr(settings_get_str("cmdchars"), *ptr)) {
|
||||
if (strchr(cmdchars, *ptr)) {
|
||||
/* command character inside command .. we probably
|
||||
want to send this text to channel. for example
|
||||
when pasting a path /usr/bin/xxx. */
|
||||
@ -321,6 +337,16 @@ static void event_default_command(const char *data, void *server, WI_ITEM_REC *i
|
||||
ptr++;
|
||||
}
|
||||
|
||||
/* maybe we're copy+pasting text? check how long it was since the
|
||||
last line */
|
||||
diff = get_timeval_diff(&time_command_now, &time_command_last);
|
||||
if (item != NULL && !last_command_cmd && diff < PASTE_CHECK_SPEED) {
|
||||
signal_emit("send text", 3, current_cmdline, active_win->active_server, active_win->active);
|
||||
command_cmd = FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
/* get the command part of the line, send "error command" signal */
|
||||
cmd = g_strdup(data);
|
||||
p = strchr(cmd, ' ');
|
||||
if (p != NULL) *p = '\0';
|
||||
@ -348,6 +374,9 @@ void fe_core_commands_init(void)
|
||||
{
|
||||
hide_output = FALSE;
|
||||
|
||||
command_cmd = FALSE;
|
||||
memset(&time_command_now, 0, sizeof(GTimeVal));
|
||||
|
||||
command_bind("help", NULL, (SIGNAL_FUNC) cmd_help);
|
||||
command_bind("echo", NULL, (SIGNAL_FUNC) cmd_echo);
|
||||
command_bind("version", NULL, (SIGNAL_FUNC) cmd_version);
|
||||
|
@ -996,6 +996,7 @@ void irc_commands_init(void)
|
||||
command_bind("lusers", NULL, (SIGNAL_FUNC) command_self);
|
||||
command_bind("map", NULL, (SIGNAL_FUNC) command_self);
|
||||
command_bind("motd", NULL, (SIGNAL_FUNC) command_self);
|
||||
command_bind("rehash", NULL, (SIGNAL_FUNC) command_self);
|
||||
command_bind("stats", NULL, (SIGNAL_FUNC) command_self);
|
||||
command_bind("time", NULL, (SIGNAL_FUNC) command_self);
|
||||
command_bind("trace", NULL, (SIGNAL_FUNC) command_self);
|
||||
@ -1069,6 +1070,7 @@ void irc_commands_deinit(void)
|
||||
command_unbind("lusers", (SIGNAL_FUNC) command_self);
|
||||
command_unbind("map", (SIGNAL_FUNC) command_self);
|
||||
command_unbind("motd", (SIGNAL_FUNC) command_self);
|
||||
command_unbind("rehash", (SIGNAL_FUNC) command_self);
|
||||
command_unbind("stats", (SIGNAL_FUNC) command_self);
|
||||
command_unbind("time", (SIGNAL_FUNC) command_self);
|
||||
command_unbind("trace", (SIGNAL_FUNC) command_self);
|
||||
|
Loading…
Reference in New Issue
Block a user