# HG changeset patch # User Mikael Berthe # Date 1120855637 -3600 # Node ID 1eea0fa0955ecd796f46c1be530d1b6d8c7e691c # Parent c2a7e78d9ff5aaf749b22666e4bf9e8e3ae8f51d Add /bind command * Split process_line() to process_line() + process_command() * Do not expand aliases in multi-line mode * Add /bind command The binding system is ugly (not UTF-8 compatible, I think, and certainly system dependant because it is using ncurses wgetch() values). diff -r c2a7e78d9ff5 -r 1eea0fa0955e mcabber/src/commands.c --- a/mcabber/src/commands.c Fri Jul 08 07:31:24 2005 +0100 +++ b/mcabber/src/commands.c Fri Jul 08 21:47:17 2005 +0100 @@ -47,6 +47,7 @@ void do_move(char *arg); void do_set(char *arg); void do_alias(char *arg); +void do_bind(char *arg); // Global variable for the commands list static GSList *Commands; @@ -74,6 +75,7 @@ { cmd_add("add", "Add a jabber user", COMPL_JID, 0, &do_add); cmd_add("alias", "Add an alias", 0, 0, &do_alias); + cmd_add("bind", "Add an key binding", 0, 0, &do_bind); cmd_add("buffer", "Manipulate current buddy's buffer (chat window)", COMPL_BUFFER, 0, &do_buffer); cmd_add("clear", "Clear the dialog window", 0, 0, &do_clear); @@ -222,39 +224,15 @@ jb_send_msg(jid, msg); } -// process_line(line) -// Process a command/message line. -// If this isn't a command, this is a message and it is sent to the -// currently selected buddy. -int process_line(char *line) +// process_command(line) +// Process a command line. +// Return 255 if this is the /quit command, and 0 for the other commands. +int process_command(char *line) { char *p; char *xpline; cmd *curcmd; - if (!*line) { // User only pressed enter - if (scr_get_multimode()) { - scr_append_multiline(""); - return 0; - } - if (current_buddy) { - scr_set_chatmode(TRUE); - buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); - scr_ShowBuddyWindow(); - } - return 0; - } - - if (*line != '/') { - // This isn't a command - if (scr_get_multimode()) - scr_append_multiline(line); - else - do_say(line); - return 0; - } - - /* It is a command */ // Remove trailing spaces: for (p=line ; *p ; p++) ; @@ -262,7 +240,10 @@ *p = 0; // We do alias expansion here - xpline = expandalias(line); + if (scr_get_multimode() != 2) + xpline = expandalias(line); + else + xpline = line; // No expansion in verbatim multi-line mode // Command "quit"? if ((!strncasecmp(xpline, "/quit", 5)) && (scr_get_multimode() != 2) ) @@ -301,6 +282,39 @@ return 0; } +// process_line(line) +// Process a command/message line. +// If this isn't a command, this is a message and it is sent to the +// currently selected buddy. +// Return 255 if the line is the /quit command, or 0. +int process_line(char *line) +{ + if (!*line) { // User only pressed enter + if (scr_get_multimode()) { + scr_append_multiline(""); + return 0; + } + if (current_buddy) { + scr_set_chatmode(TRUE); + buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); + scr_ShowBuddyWindow(); + } + return 0; + } + + if (*line != '/') { + // This isn't a command + if (scr_get_multimode()) + scr_append_multiline(line); + else + do_say(line); + return 0; + } + + /* It is (probably) a command -- except for verbatim multi-line mode */ + return process_command(line); +} + /* Commands callback functions */ void do_roster(char *arg) @@ -724,3 +738,29 @@ } } +void do_bind(char *arg) +{ + guint assign; + const gchar *keycode, *value; + + assign = parse_assigment(arg, &keycode, &value); + if (!keycode) { + scr_LogPrint("Huh?"); + return; + } + if (!assign) { + // This is a query + value = settings_get(SETTINGS_TYPE_BINDING, keycode); + if (value) { + scr_LogPrint("Key %s is bound to: %s", keycode, value); + } else + scr_LogPrint("Key %s is not bound", keycode); + return; + } + // Update the key binding + if (!value) + settings_del(SETTINGS_TYPE_BINDING, keycode); + else + settings_set(SETTINGS_TYPE_BINDING, keycode, value); +} + diff -r c2a7e78d9ff5 -r 1eea0fa0955e mcabber/src/commands.h --- a/mcabber/src/commands.h Fri Jul 08 07:31:24 2005 +0100 +++ b/mcabber/src/commands.h Fri Jul 08 21:47:17 2005 +0100 @@ -14,6 +14,7 @@ void cmd_init(void); cmd *cmd_get(const char *command); int process_line(char *line); +int process_command(char *line); char *expandalias(char *line); #endif /* __COMMANDS_H__ */ diff -r c2a7e78d9ff5 -r 1eea0fa0955e mcabber/src/screen.c --- a/mcabber/src/screen.c Fri Jul 08 07:31:24 2005 +0100 +++ b/mcabber/src/screen.c Fri Jul 08 21:47:17 2005 +0100 @@ -1608,9 +1608,19 @@ scr_Resize(); break; default: - scr_LogPrint("Unknown key=%d", key); - if (utf8_mode) - scr_LogPrint("WARNING: UTF-8 not yet supported!"); + { + const gchar *boundcmd = isbound(key); + if (boundcmd) { + gchar *cmd = g_strdup_printf("/%s", boundcmd); + if (process_command(cmd)) + return 255; + g_free(cmd); + } else { + scr_LogPrint("Unknown key=%d", key); + if (utf8_mode) + scr_LogPrint("WARNING: UTF-8 not yet supported!"); + } + } } } if (completion_started && key != 9 && key != KEY_RESIZE) diff -r c2a7e78d9ff5 -r 1eea0fa0955e mcabber/src/settings.c --- a/mcabber/src/settings.c Fri Jul 08 07:31:24 2005 +0100 +++ b/mcabber/src/settings.c Fri Jul 08 21:47:17 2005 +0100 @@ -172,3 +172,11 @@ return 0; } +// Return the command the key is bound to, or NULL. +const gchar *isbound(int key) +{ + gchar asciikey[16]; + g_snprintf(asciikey, 15, "%d", key); + return settings_get(SETTINGS_TYPE_BINDING, asciikey); +} + diff -r c2a7e78d9ff5 -r 1eea0fa0955e mcabber/src/settings.h --- a/mcabber/src/settings.h Fri Jul 08 07:31:24 2005 +0100 +++ b/mcabber/src/settings.h Fri Jul 08 21:47:17 2005 +0100 @@ -17,5 +17,7 @@ const gchar *settings_get(guint type, const gchar *key); int settings_get_int(guint type, const gchar *key); +const gchar *isbound(int key); + #endif /* __SETTINGS_H__ */