I'm working on a small shell and using libreadline to get command input.
problem
- My command prompt is getting deleted when I use C-W
note this only happens after I enter a word and then C-W, C-w immediately doesn't delete the prompt.
source
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <stdlib.h>
#include <string.h>
int ash_loop(void)
{
char *line = 0;
while(1)
{
// this is the current prompt - i dont want it to be deletable..
printf("ash$ ");
line = readline(0);
if(!line)goto err0;
printf("line: %s\n", line);
free(line);
break;
}
return 0;
err0:
return 1;
}
int main(int argc, char *argv[])
{
int rc;
rc = ash_loop();
return rc;
}
example session
$ ./ash
line:
here i typed word and then C-W.
How can I preserve the prompt ?
You want to use the prompt argument to readline()
:
line = readline("ash$ ");