Репозиторий ALT Linux backports/2.4
Последнее обновление: 9 июля 2008 | Пакетов: 497 | Посещений: 1574076
 поиск   регистрация   авторизация 
 
Группа :: Графические оболочки/Icewm
Пакет: icewm

 Главная   Изменения   Спек   Патчи   Загрузить   Bugs and FR 

Патч: icewm-alt-hist.patch


--- configure.in.orig	2003-07-11 02:38:11 +0400
+++ configure.in	2003-07-14 13:46:57 +0400
@@ -400,6 +400,22 @@
   features="${features} wm-session"
   fi
 
+dnl =================================================== Support for readline ===
+dnl
+AC_ARG_ENABLE(readline,
+  [  --with-readline         Enable readline & history support])
+  if test "$with_readline" != "no"; then
+    AC_CHECK_LIB(history, using_history,
+      CORE_LIBS="${CORE_LIBS} -lhistory -lreadline"
+      features="${features} readline"
+      [ AC_DEFINE(HAVE_READLINE, 1, [Enable readline & history support]) ],
+      [ AC_MSG_ERROR([Unable to find history library])])
+    AC_CHECK_LIB(ncurses, copywin,
+      CORE_LIBS="${CORE_LIBS} -lncurses"
+      [ ],
+      [ AC_MSG_ERROR([Unable to find ncurses library])])
+  fi
+
 dnl ============================================================= GUI Events ===
 dnl
 AC_ARG_ENABLE(guievents,
--- src/aaddressbar.cc.orig	2003-06-22 20:38:20 +0400
+++ src/aaddressbar.cc	2003-07-14 13:23:12 +0400
@@ -15,8 +15,144 @@
 #include "sysdep.h"
 #include "default.h"
 
+#ifdef HAVE_READLINE
+#include <readline/readline.h>
+#include <readline/history.h>
+
+char *extract_colon_unit (char *string, int *p_index)
+{
+  int i, start, len;
+  char *value = NULL;
+
+  if (string == 0)
+    return (string);
+
+  len = strlen (string);
+  if (*p_index >= len)
+    return ((char *)NULL);
+
+  i = *p_index;
+
+  if (i && string[i] == ':')
+    i++;
+
+  for (start = i; string[i] && string[i] != ':'; i++)
+    ;
+
+  *p_index = i;
+
+  if (i == start)
+    {
+      if (string[i])
+	(*p_index)++;
+      /* Return "" in the case of a trailing `:'. */
+      value = new char[1];
+      value[0] = '\0';
+    }
+  else
+    {
+      int len = i-start;
+      value = new char[len+1];
+      strncpy(value, string+start,len);
+      value[len] = '\0';
+    }
+
+  return (value);
+}
+
+char *find_completion(const char *text,int *state) {
+    char *path = getenv("PATH");
+    char *current_path;
+    char **matches = NULL;
+    char *filename = NULL;
+    char *found = NULL;
+    int path_index, text_len = strlen(text), found_len = 0, path_len = 0;
+    struct stat st;
+
+    *state = 0;
+    path_index = 0;
+    if (text[0] != '/' && text[0] != '~') {
+	while (path && path[path_index]) {
+	    current_path = extract_colon_unit(path, &path_index);
+	    if (current_path && *current_path) {
+		filename = new char[2+strlen(current_path)+text_len];
+		sprintf(filename,"%s/%s",current_path,text);
+		path_len = strlen(current_path)+1;
+		free(current_path);
+		matches = rl_completion_matches(filename, rl_filename_completion_function);
+		if (matches) {
+		    //if (!matches[1]) {
+			char *f = *matches+path_len;
+			int len = strlen(f);
+			if (len < found_len) {
+			    free(found);
+			    found = strdup(f);
+			    found_len = len;
+			    *state = 3;
+			} else if (*state) {
+			    *state = 2;
+			    if (found) {
+				free(found);
+				found = NULL;
+			    }
+			} else {
+			    found = strdup(*matches+path_len);
+			    found_len = strlen(found);
+			    if (matches[1])
+				*state = 3;
+			    else
+				*state = 1;
+			}
+		    //} else {
+		//	*state = 2;
+		//    }
+		}
+		if (*state == 2)
+		    return NULL;
+	    }
+	}
+    } else {
+	const char *wtilde = NULL;
+	int len = -1;
+	if (text[0] == '~') {
+	    wtilde = text;
+	    text = tilde_expand(text);
+	    len = strlen(text);
+	}
+        matches = rl_completion_matches(text, rl_filename_completion_function);
+	if (matches) {
+	    stat(*matches,&st);
+	    if (len > 0) {
+	        *matches += len;
+		len = text_len+strlen(*matches);
+		found = new char[len+2];
+		if (S_ISDIR(st.st_mode) && !matches[1]) {
+		    sprintf(found,"%s%s/",wtilde,*matches);
+		} else {
+		    sprintf(found,"%s%s",wtilde,*matches);
+		}
+	    } else {
+		if (S_ISDIR(st.st_mode) && !matches[1]) {
+		    found = new char[strlen(*matches)+2];
+		    sprintf(found,"%s/",*matches);
+		} else {
+		    found = strdup(*matches);
+		}
+	    }
+	    if (matches[1])
+		*state = 3;
+	    else
+		*state = 1;
+	}
+    }
+    return found;
+}
+#endif /* HAVE_READLINE */
 
 AddressBar::AddressBar(YWindow *parent): YInputLine(parent) {
+#ifdef HAVE_READLINE
+    using_history();
+#endif
 }
 
 AddressBar::~AddressBar() {
@@ -27,7 +163,41 @@
         KeySym k = XKeycodeToKeysym(app->display(), key.keycode, 0);
         int m = KEY_MODMASK(key.state);
 
+#ifdef HAVE_READLINE
+	if (k == XK_Tab) {
+	    int state=0, p;
+	    char *f;
+	    char *text = strdup(getText());
+	    p = prevWord(strlen(text), false);
+	    text += p;
+	    f = find_completion(text,&state);
+	    if (state & 1) {
+		char *t = f;
+		if (p != 0) {
+		    t = new char[strlen(f)+p+2];
+		    *text = '\0';
+		    text -= p;
+		    sprintf(t,"%s%s",text,f);
+		    free(text);
+		    free(f);
+		}
+		setText(t);
+		free(t);
+	    }
+	    if (!state || state & 2)
+		; // printf("\a\n");
+    	    return true; // for future compatibility
+	} else if (k == XK_Up || k == XK_Down) {
+	    HIST_ENTRY *hist;
+	    hist = k == XK_Down ? next_history() : previous_history();
+	    if (hist == NULL)
+		return true;
+	    setText(hist->line);
+	    return true;
+        } else if (k == XK_KP_Enter || k == XK_Return) {
+#else
         if (k == XK_KP_Enter || k == XK_Return) {
+#endif
             const char *t = getText();
             const char *args[7];
             int i = 0;
@@ -50,6 +220,9 @@
             if (m & ControlMask)
                 if (t == 0 || t[0] == 0)
                     args[1] = 0;
+#ifdef HAVE_READLINE
+	    add_history((char *)t);
+#endif
             app->runProgram(args[0], args);
             selectAll();
             return true;
--- src/yinput.cc.orig	2003-06-22 20:38:20 +0400
+++ src/yinput.cc	2003-07-11 21:03:26 +0400
@@ -84,7 +84,7 @@
     fText = newstr(text);
     markPos = curPos = leftOfs = 0;
     if (fText)
-        curPos = strlen(fText);
+        markPos = curPos = strlen(fText);
     limit();
     repaint();
 }
 
design & coding: Vladimir Lettiev aka crux © 2004-2005