changeset 14977:1c0772f7260b

[gaim-migrate @ 17755] Decide the values for ctrl-up/down at startup depending on $TERM. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 15 Nov 2006 20:39:32 +0000
parents 2ccce4e114ca
children e601bc7880a6
files console/libgnt/gntbindable.c console/libgnt/gntentry.c console/libgnt/gntkeys.c console/libgnt/gntkeys.h console/libgnt/gntmain.c
diffstat 5 files changed, 35 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/console/libgnt/gntbindable.c	Wed Nov 15 20:11:01 2006 +0000
+++ b/console/libgnt/gntbindable.c	Wed Nov 15 20:39:32 2006 +0000
@@ -185,7 +185,7 @@
 
 	g_hash_table_replace(klass->actions, g_strdup(name), action);
 
-	if (trigger) {
+	if (trigger && *trigger) {
 		list = NULL;
 		va_start(args, trigger);
 		while ((data = va_arg(args, void *))) {
--- a/console/libgnt/gntentry.c	Wed Nov 15 20:11:01 2006 +0000
+++ b/console/libgnt/gntentry.c	Wed Nov 15 20:39:32 2006 +0000
@@ -585,9 +585,9 @@
 	gnt_bindable_class_register_action(bindable, "suggest-prev", suggest_prev,
 				GNT_KEY_UP, NULL);
 	gnt_bindable_class_register_action(bindable, "history-prev", history_prev,
-				"\033" GNT_KEY_CTRL_DOWN, NULL);
+				GNT_KEY_CTRL_DOWN, NULL);
 	gnt_bindable_class_register_action(bindable, "history-next", history_next,
-				"\033" GNT_KEY_CTRL_UP, NULL);
+				GNT_KEY_CTRL_UP, NULL);
 
 	gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass));
 	GNTDEBUG;
--- a/console/libgnt/gntkeys.c	Wed Nov 15 20:11:01 2006 +0000
+++ b/console/libgnt/gntkeys.c	Wed Nov 15 20:39:32 2006 +0000
@@ -5,7 +5,7 @@
 
 static const char *term;
 
-void gnt_keys_refine(char *text)
+void gnt_init_keys()
 {
 	if (term == NULL) {
 		term = getenv("TERM");
@@ -13,6 +13,21 @@
 			term = "";  /* Just in case */
 	}
 
+	if (strcmp(term, "xterm") == 0 || strcmp(term, "rxvt") == 0) {
+		gnt_key_cup    = "\033" "[1;5A";
+		gnt_key_cdown  = "\033" "[1;5B";
+		gnt_key_cright = "\033" "[1;5C";
+		gnt_key_cleft  = "\033" "[1;5D";
+	} else if (strcmp(term, "screen") == 0 || strcmp(term, "rxvt-unicode") == 0) {
+		gnt_key_cup    = "\033" "Oa";
+		gnt_key_cdown  = "\033" "Ob";
+		gnt_key_cright = "\033" "Oc";
+		gnt_key_cleft  = "\033" "Od";
+	}
+}
+
+void gnt_keys_refine(char *text)
+{
 	if (*text == 27 && *(text + 1) == '[' && *(text + 3) == '\0' &&
 			(*(text + 2) >= 'A' && *(text + 2) <= 'D')) {
 		/* Apparently this is necessary for urxvt and screen and xterm */
--- a/console/libgnt/gntkeys.h	Wed Nov 15 20:11:01 2006 +0000
+++ b/console/libgnt/gntkeys.h	Wed Nov 15 20:39:32 2006 +0000
@@ -4,6 +4,16 @@
 #include <curses.h>
 #include <term.h>
 
+/**
+ * terminfo/termcap doesn't provide all the information that I want to use, eg.
+ * ctrl-up, ctrl-down etc. So I am going to hard-code some of the information
+ * for some popular $TERMs
+ */
+char *gnt_key_cup;
+char *gnt_key_cdown;
+char *gnt_key_cleft;
+char *gnt_key_cright;
+
 #define SAFE(x)   ((x) ? (x) : "")
 
 #define GNT_KEY_POPUP   SAFE(key_f16)   /* Apparently */
@@ -14,10 +24,10 @@
 #define GNT_KEY_UP     SAFE(key_up)
 #define GNT_KEY_DOWN   SAFE(key_down)
 
-#define GNT_KEY_CTRL_UP     "[1;5A"
-#define GNT_KEY_CTRL_DOWN   "[1;5B"
-#define GNT_KEY_CTRL_RIGHT  "[1;5C"
-#define GNT_KEY_CTRL_LEFT   "[1;5D"
+#define GNT_KEY_CTRL_UP     SAFE(gnt_key_cup)
+#define GNT_KEY_CTRL_DOWN   SAFE(gnt_key_cdown)
+#define GNT_KEY_CTRL_RIGHT  SAFE(gnt_key_cright)
+#define GNT_KEY_CTRL_LEFT   SAFE(gnt_key_cleft)
 
 #define GNT_KEY_PGUP   SAFE(key_ppage)
 #define GNT_KEY_PGDOWN SAFE(key_npage)
@@ -69,6 +79,7 @@
 /**
  * This will do stuff with the terminal settings and stuff.
  */
+void gnt_init_keys();
 void gnt_keys_refine(char *text);
 
 
--- a/console/libgnt/gntmain.c	Wed Nov 15 20:11:01 2006 +0000
+++ b/console/libgnt/gntmain.c	Wed Nov 15 20:39:32 2006 +0000
@@ -324,6 +324,7 @@
 	g_free(filename);
 
 	gnt_init_colors();
+	gnt_init_keys();
 
 	wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
 	refresh();