Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C-W is deleting my command prompt – how to stop this

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 ?

>Solution :

You want to use the prompt argument to readline():

line = readline("ash$ ");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading