"set keycmd = x" is now equivalent to "keycmd x"
authorBrendan Taylor <whateley@gmail.com>
Sun, 12 Jul 2009 19:52:34 +0000 (13:52 -0600)
committerBrendan Taylor <whateley@gmail.com>
Sun, 12 Jul 2009 19:52:34 +0000 (13:52 -0600)
tests/Makefile
tests/test-command.c [new file with mode: 0644]
uzbl.c
uzbl.h

index 2bfcf98..7901b7d 100644 (file)
@@ -4,7 +4,7 @@ LDFLAGS:=$(shell pkg-config --libs gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0)
 GTESTER:=gtester
 GTESTER_REPORT:=gtester-report
 
-TEST_PROGS:=test-expand
+TEST_PROGS:=test-expand test-command
 
 all: $(TEST_PROGS)
        LD_LIBRARY_PATH="$(LD_LIBRARY_PATH):." $(GTESTER) --verbose $(TEST_PROGS)
diff --git a/tests/test-command.c b/tests/test-command.c
new file mode 100644 (file)
index 0000000..aee4bf2
--- /dev/null
@@ -0,0 +1,60 @@
+/* -*- c-basic-offset: 4; -*- */
+#define _POSIX_SOURCE
+
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+#include <gdk/gdkkeysyms.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <sys/utsname.h>
+#include <sys/time.h>
+#include <webkit/webkit.h>
+#include <libsoup/soup.h>
+#include <JavaScriptCore/JavaScript.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+
+#include <uzbl.h>
+#include <config.h>
+
+extern Uzbl uzbl;
+
+void
+test_keycmd (void) {
+  add_binding("insert", "set insert_mode = 1");
+  add_binding("command", "set insert_mode = 0");
+
+  /* the 'keycmd' command */
+  parse_command("keycmd", "insert", NULL);
+
+  g_assert_cmpint(1, ==, uzbl.behave.insert_mode);
+  g_assert_cmpstr("", ==, uzbl.state.keycmd);
+
+  /* setting the keycmd variable directly, equivalent to the 'keycmd' comand */
+  set_var_value("keycmd", "command");
+
+  g_assert_cmpint(0, ==, uzbl.behave.insert_mode);
+  g_assert_cmpstr("", ==, uzbl.state.keycmd);
+}
+
+int
+main (int argc, char *argv[]) {
+    g_type_init();
+    g_test_init(&argc, &argv, NULL);
+
+    g_test_add_func("/test-command/keycmd", test_keycmd);
+
+    initialize(argc, argv);
+
+    return g_test_run();
+}
+
+/* vi: set et ts=4: */
diff --git a/uzbl.c b/uzbl.c
index daf7e4d..f4f93ea 100644 (file)
--- a/uzbl.c
+++ b/uzbl.c
@@ -108,7 +108,7 @@ const struct {
     { "base_url",            PTR_V(uzbl.behave.base_url,            STR,  1,   NULL)},
     { "html_endmarker",      PTR_V(uzbl.behave.html_endmarker,      STR,  1,   NULL)},
     { "html_mode_timeout",   PTR_V(uzbl.behave.html_timeout,        INT,  1,   NULL)},
-    { "keycmd",              PTR_V(uzbl.state.keycmd,               STR,  1,   NULL)}, /* XXX */
+    { "keycmd",              PTR_V(uzbl.state.keycmd,               STR,  1,   set_keycmd)},
     { "status_message",      PTR_V(uzbl.gui.sbar.msg,               STR,  1,   update_title)},
     { "show_status",         PTR_V(uzbl.behave.show_status,         INT,  1,   cmd_set_status)},
     { "status_top",          PTR_V(uzbl.behave.status_top,          INT,  1,   move_statusbar)},
@@ -885,6 +885,11 @@ act_dump_config() {
     dump_config();
 }
 
+void set_keycmd() {
+    run_keycmd(FALSE);
+    update_title();
+}
+
 void set_mode_indicator() {
     uzbl.gui.sbar.mode_indicator = (uzbl.behave.insert_mode ?
         uzbl.behave.insert_indicator : uzbl.behave.cmd_indicator);
@@ -1364,7 +1369,7 @@ spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result) {
     g_strfreev (cmd);
 }
 
-static void
+void
 parse_command(const char *cmd, const char *param, GString *result) {
     CommandInfo *c;
 
@@ -2291,7 +2296,7 @@ run_handler (const gchar *act, const gchar *args) {
     g_strfreev(parts);
 }
 
-static void
+void
 add_binding (const gchar *key, const gchar *act) {
     char **parts = g_strsplit(act, " ", 2);
     Action *action;
diff --git a/uzbl.h b/uzbl.h
index 6c292a0..ef462f5 100644 (file)
--- a/uzbl.h
+++ b/uzbl.h
@@ -298,6 +298,9 @@ static bool
 file_exists (const char * filename);
 
 void
+set_keycmd();
+
+void
 set_mode_indicator();
 
 void
@@ -346,7 +349,7 @@ spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result);
 static void
 spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result);
 
-static void
+void
 parse_command(const char *cmd, const char *param, GString *result);
 
 static void
@@ -406,7 +409,7 @@ GtkPlug* create_plug ();
 static void
 run_handler (const gchar *act, const gchar *args);
 
-static void
+void
 add_binding (const gchar *key, const gchar *act);
 
 static gchar*