Browse Source

Renew prompt. forceline, readline without prompt field

git-svn-id: https://klish.googlecode.com/svn/trunk@558 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 12 years ago
parent
commit
b65f2a2208
3 changed files with 18 additions and 28 deletions
  1. 10 17
      clish/shell/shell_tinyrl.c
  2. 5 7
      tinyrl/tinyrl.c
  3. 3 4
      tinyrl/tinyrl.h

+ 10 - 17
clish/shell/shell_tinyrl.c

@@ -19,23 +19,22 @@
 #include "lub/string.h"
 
 /*-------------------------------------------------------- */
-static void clish_shell_renew_prompt(tinyrl_t *this)
+static void clish_shell_renew_prompt(clish_shell_t *this)
 {
-	clish_context_t *context = tinyrl__get_context(this);
 	clish_context_t prompt_context;
 	char *prompt = NULL;
 	const clish_view_t *view;
 
 	/* Create appropriate context */
 	memset(&prompt_context, 0, sizeof(prompt_context));
-	prompt_context.shell = context->shell;
+	prompt_context.shell = this;
 
 	/* Obtain the prompt */
-	view = clish_shell__get_view(context->shell);
+	view = clish_shell__get_view(this);
 	assert(view);
 	prompt = clish_shell_expand(clish_view__get_prompt(view), SHELL_VAR_ACTION, &prompt_context);
 	assert(prompt);
-	tinyrl__set_prompt(this, prompt);
+	tinyrl__set_prompt(this->tinyrl, prompt);
 	lub_string_free(prompt);
 }
 
@@ -223,7 +222,7 @@ static bool_t clish_shell_tinyrl_key_enter(tinyrl_t *this, int key)
 		context->shell->current_file->line++;
 
 	/* Renew prompt */
-	clish_shell_renew_prompt(this);
+	clish_shell_renew_prompt(context->shell);
 
 	/* nothing to pass simply move down the screen */
 	if (!*line) {
@@ -432,8 +431,6 @@ void clish_shell_tinyrl_delete(tinyrl_t * this)
 /*-------------------------------------------------------- */
 int clish_shell_execline(clish_shell_t *this, const char *line, char **out)
 {
-	char *prompt = NULL;
-	const clish_view_t *view;
 	char *str;
 	clish_context_t context;
 	tinyrl_history_t *history;
@@ -446,24 +443,20 @@ int clish_shell_execline(clish_shell_t *this, const char *line, char **out)
 		return -1;
 	}
 
+	/* Renew prompt */
+	clish_shell_renew_prompt(this);
+
 	/* Set up the context for tinyrl */
 	context.cmd = NULL;
 	context.pargv = NULL;
 	context.shell = this;
 
-	/* Obtain the prompt */
-	view = clish_shell__get_view(this);
-	assert(view);
-	prompt = clish_shell_expand(clish_view__get_prompt(view), SHELL_VAR_ACTION, &context);
-	assert(prompt);
-
 	/* Push the specified line or interactive line */
 	if (line)
-		str = tinyrl_forceline(this->tinyrl, prompt, &context, line);
+		str = tinyrl_forceline(this->tinyrl, &context, line);
 	else
-		str = tinyrl_readline(this->tinyrl, prompt, &context);
+		str = tinyrl_readline(this->tinyrl, &context);
 	lerror = errno;
-	lub_string_free(prompt);
 	if (!str) {
 		switch (lerror) {
 		case ENOENT:

+ 5 - 7
tinyrl/tinyrl.c

@@ -668,7 +668,7 @@ static char *internal_insertline(tinyrl_t * this, char *buffer)
 
 /*----------------------------------------------------------------------- */
 static char *internal_readline(tinyrl_t * this,
-	const char *prompt, void *context, const char *str)
+	void *context, const char *str)
 {
 	FILE *istream = tinyrl_vt100__get_istream(this->term);
 	char *result = NULL;
@@ -681,7 +681,6 @@ static char *internal_readline(tinyrl_t * this,
 	this->buffer = lub_string_dup("");
 	this->buffer_size = strlen(this->buffer);
 	this->line = this->buffer;
-	tinyrl__set_prompt(this, prompt);
 	this->context = context;
 
 	if (this->isatty && !str) {
@@ -786,16 +785,15 @@ static char *internal_readline(tinyrl_t * this,
 }
 
 /*----------------------------------------------------------------------- */
-char *tinyrl_readline(tinyrl_t * this, const char *prompt, void *context)
+char *tinyrl_readline(tinyrl_t * this, void *context)
 {
-	return internal_readline(this, prompt, context, NULL);
+	return internal_readline(this, context, NULL);
 }
 
 /*----------------------------------------------------------------------- */
-char *tinyrl_forceline(tinyrl_t * this,
-	 const char *prompt, void *context, const char *line)
+char *tinyrl_forceline(tinyrl_t * this, void *context, const char *line)
 {
-	return internal_readline(this, prompt, context, line);
+	return internal_readline(this, context, line);
 }
 
 /*----------------------------------------------------------------------- */

+ 3 - 4
tinyrl/tinyrl.h

@@ -110,10 +110,9 @@ extern void tinyrl__set_timeout_fn(tinyrl_t *instance,
 	tinyrl_timeout_fn_t *fn);
 extern void tinyrl__set_keypress_fn(tinyrl_t *instance,
 	tinyrl_keypress_fn_t *fn);
-extern char *tinyrl_readline(tinyrl_t *instance,
-	const char *prompt, void *context);
-extern char *tinyrl_forceline(tinyrl_t *instance,
-	const char *prompt, void *context, const char *line);
+extern char *tinyrl_readline(tinyrl_t *instance, void *context);
+extern char *tinyrl_forceline(tinyrl_t *instance, 
+	void *context, const char *line);
 extern bool_t tinyrl_bind_key(tinyrl_t *instance, int key,
 	tinyrl_key_func_t *fn);
 extern void tinyrl_delete_matches(char **instance);