Skip to content

Commit 9547b0c

Browse files
committed
Add comment to visible prompt
This makes it obvious it is a prompt
1 parent aa336c9 commit 9547b0c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/ai_cli.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,28 @@ static char * (*fetch)(config_t *config, const char *prompt, int history_length)
5656
/*
5757
* Add the specified prompt to the RL history, as a comment if the
5858
* comment prefix is defined.
59+
* Return the length of the added comment.
5960
*/
60-
static void
61-
add_prompt_to_history(const char *prompt)
61+
static int
62+
add_commented_prompt_to_history(const char *prompt)
6263
{
6364
if (prompt == NULL)
64-
return;
65+
return 0;
6566

6667
if (!config.prompt_comment_set) {
6768
add_history(prompt);
68-
return;
69+
return 0;
6970
}
7071

7172
char *commented_prompt;
7273
acl_safe_asprintf(&commented_prompt, "%s %s", config.prompt_comment,
7374
prompt);
7475
add_history(commented_prompt);
76+
rl_replace_line(commented_prompt, 0);
77+
*rl_point_ptr = *rl_end_ptr;
78+
rl_redisplay();
7579
free(commented_prompt);
80+
return strlen(config.prompt_comment);
7681
}
7782

7883
/*
@@ -89,8 +94,8 @@ query_ai(int count, int key)
8994
prev_response = NULL;
9095
}
9196

92-
add_prompt_to_history(*rl_line_buffer_ptr);
93-
char *response = fetch(&config, *rl_line_buffer_ptr,
97+
int comment_len = add_commented_prompt_to_history(*rl_line_buffer_ptr);
98+
char *response = fetch(&config, *rl_line_buffer_ptr + comment_len,
9499
*history_length_ptr);
95100
if (!response)
96101
return -1;

0 commit comments

Comments
 (0)