summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2000-07-02 19:22:30 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2000-07-02 19:22:30 +0000
commit4475a04841a2844260f56f7bec8d77b92fa5104a (patch)
tree3cd6cea0ccc4478e73baaff54fd13b27a14340a0 /src
parenteee71a093a7052f146b20da1272b75679ea9bea2 (diff)
downloadirssi-4475a04841a2844260f56f7bec8d77b92fa5104a.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/fe-common/core/fe-core-commands.c35
-rw-r--r--src/irc/core/irc-commands.c2
2 files changed, 34 insertions, 3 deletions
diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c
index 36517bc2..7f5b4506 100644
--- a/src/fe-common/core/fe-core-commands.c
+++ b/src/fe-common/core/fe-core-commands.c
@@ -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);
diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c
index aa7f9a27..62eb546c 100644
--- a/src/irc/core/irc-commands.c
+++ b/src/irc/core/irc-commands.c
@@ -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);