summaryrefslogtreecommitdiff
path: root/client/client.c
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>2000-02-17 23:37:16 +0000
committerMartin Mares <mj@ucw.cz>2000-02-17 23:37:16 +0000
commitfae0396ea4fd9d2530086eef77b8a11b6640d640 (patch)
treee20a4d7513feabab3f926c85f7098eaf95349809 /client/client.c
parent0223d4fff11badc03470b4320fa9dfe28afd1bed (diff)
Completion works. Unfortunately, we have to access a couple of internal
symbols of libreadline :-(
Diffstat (limited to 'client/client.c')
-rw-r--r--client/client.c53
1 files changed, 46 insertions, 7 deletions
diff --git a/client/client.c b/client/client.c
index b9e3ab81..9c6b4ae9 100644
--- a/client/client.c
+++ b/client/client.c
@@ -71,6 +71,11 @@ parse_args(int argc, char **argv)
static void server_send(char *);
static void io_loop(int);
+/* HACK: libreadline internals we need to access */
+extern int _rl_vis_botlin;
+extern void _rl_move_vert(int);
+extern Function *rl_last_func;
+
static void
got_line(char *cmd_buffer)
{
@@ -91,10 +96,40 @@ got_line(char *cmd_buffer)
free(cmd_buffer);
}
+void
+input_start_list(void) /* Leave the currently edited line and make space for listing */
+{
+ _rl_move_vert(_rl_vis_botlin);
+ crlf();
+}
+
+void
+input_stop_list(void) /* Reprint the currently edited line after listing */
+{
+ rl_on_new_line();
+ rl_redisplay();
+}
+
static int
input_complete(int arg, int key)
{
- ding();
+ static int complete_flag;
+ char buf[256];
+
+ if (rl_last_func != input_complete)
+ complete_flag = 0;
+ switch (cmd_complete(rl_line_buffer, rl_point, buf, complete_flag))
+ {
+ case 0:
+ complete_flag = 1;
+ break;
+ case 1:
+ rl_insert_text(buf);
+ break;
+ default:
+ complete_flag = 1;
+ ding();
+ }
return 0;
}
@@ -103,22 +138,26 @@ input_help(int arg, int key)
{
int i = 0;
- if (rl_point != rl_end || arg != 1)
+ if (arg != 1)
return rl_insert(arg, '?');
- while (i < rl_end)
+ while (i < rl_point)
{
if (rl_line_buffer[i++] == '"')
do
{
- if (i >= rl_end) /* `?' inside quoted string -> insert */
+ if (i >= rl_point) /* `?' inside quoted string -> insert */
return rl_insert(1, '?');
}
while (rl_line_buffer[i++] != '"');
}
- puts("?");
- cmd_help(rl_line_buffer, rl_end);
- rl_on_new_line();
+ rl_begin_undo_group(); /* HACK: We want to display `?' at point position */
+ rl_insert_text("?");
rl_redisplay();
+ rl_end_undo_group();
+ input_start_list();
+ cmd_help(rl_line_buffer, rl_point);
+ rl_undo_command(1, 0);
+ input_stop_list();
return 0;
}