]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - interactive.c
Merge branch 'refs/heads/t/score-formula'
[paraslash.git] / interactive.c
index c34a0f6eb3c5ff3fd6fcb0e85546a180d21fd880..8c4545b476e8f792ea7bba6f88b4e83fb952e540 100644 (file)
@@ -1,8 +1,4 @@
-/*
- * Copyright (C) 2011 Andre Noll <maan@tuebingen.mpg.de>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
+/* Copyright (C) 2011 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
 
 /** \file interactive.c Readline abstraction for interactive sessions. */
 
@@ -49,7 +45,7 @@ static struct i9e_private i9e_private, *i9ep = &i9e_private;
  * running.
  *
  * \return A negative return value of zero means the i9e task terminated. Only
- * in this case it is safe to call ie9_close().
+ * in this case it is safe to call i9e_close().
  */
 int i9e_get_error(void)
 {
@@ -206,26 +202,7 @@ void i9e_attach_to_stdout(struct btr_node *producer)
 
 static void wipe_bottom_line(void)
 {
-       char x[] = "          ";
-       int n = i9ep->num_columns;
-
-       /*
-        * For reasons beyond my understanding, writing more than 68 characters
-        * here causes MacOS to mess up the terminal. Writing a line of spaces
-        * in smaller chunks works fine though. Weird.
-        */
-       fprintf(i9ep->stderr_stream, "\r");
-       while (n > 0) {
-               if (n >= sizeof(x)) {
-                       fprintf(i9ep->stderr_stream, "%s", x);
-                       n -= sizeof(x);
-                       continue;
-               }
-               x[n] = '\0';
-               fprintf(i9ep->stderr_stream, "%s", x);
-               break;
-       }
-       fprintf(i9ep->stderr_stream, "\r");
+       fprintf(i9ep->stderr_stream, "\r%s\r", i9ep->empty_line);
 }
 
 #ifndef RL_FREE_KEYMAP_DECLARED
@@ -579,7 +556,7 @@ __printf_2_3 void i9e_log(int ll, const char* fmt,...)
  * the given text. If the length of this text exceeds the width of the
  * terminal, the text is shortened by leaving out a part in the middle.
  */
-void ie9_print_status_bar(char *buf, unsigned len)
+void i9e_print_status_bar(char *buf, unsigned len)
 {
        size_t x = i9ep->num_columns, y = (x - 4) / 2;
 
@@ -785,17 +762,25 @@ int i9e_print_completions(struct i9e_completer *completers)
        ci.argc = create_argv(ci.buffer, " ", &ci.argv);
        ci.word_num = compute_word_num(ci.buffer, " ", ci.point);
 
+       /* determine the current word to complete */
        end = ci.buffer + ci.point;
+
+       if (*end == ' ') {
+               if (ci.point == 0 || ci.buffer[ci.point - 1] == ' ') {
+                       ci.word = para_strdup(NULL);
+                       goto create_matches;
+               } else /* The cursor is positioned right after a word */
+                       end--;
+       }
        for (p = end; p > ci.buffer && *p != ' '; p--)
                ; /* nothing */
        if (*p == ' ')
                p++;
-
        n = end - p + 1;
        ci.word = para_malloc(n + 1);
        strncpy(ci.word, p, n);
        ci.word[n] = '\0';
-
+create_matches:
        PARA_DEBUG_LOG("line: %s, point: %d (%c), wordnum: %d, word: %s\n",
                ci.buffer, ci.point, ci.buffer[ci.point], ci.word_num, ci.word);
        if (ci.word_num == 0)