# include <readline>

# include <readline/readline.h> // readline함수를 사용하기 위한 헤더 # include <readline/history.h>// add_history함수를 사용하기 위한 헤더
 
  • readline
    • char *readline(const char *prompt); - readline 은 명령 줄 인터페이스에서 줄 편집 및 입력 기록 저장 등의 역할을 하는 라이브러리이다. 입력 자동완성, 커서 이동, 잘라내기, 복사, 붙여 넣기 등의 기능을 지원하며, Bash 등의 명령 줄 기반 인터랙티브 소프트웨어에서 사용된다. - compile 옵션으로 -lreadline 으로 주면된다.
      예제
      #include <readline/readline.h> #include <readline/history.h> #include <stdio.h> #include <string.h> #include <stdlib.h> int main(void) { char *str; while(1) { str = readline("Enter the string : "); if (strcmp(str, "exit") == 0) break; else printf("Result : %s\n\n", str); add_history(str); free(str); } return(0); }
  • rl_clear_history
    • void rl_clear_history (void); - 프롬프트에 입력된 히스토리를 지워준다. - Clear the history list by deleting all of the entries, in the same manner as the History library’s clear_history() function. This differs from clear_history because it frees private data Readline saves in the history list.
  • rl_on_new_line
    • int rl_on_new_line (void); - 업데이트 기능에 대해 주로 새 라인을 출력 후 일반적으로 새(공백) 줄로 이동했음을 알려준다. - Tell the update functions that we have moved onto a new (empty) line, usually after outputting a newline.
  • rl_replace_line
    • void rl_replace_line (const char *text, int clear_undo); - 현재까지 입력된 프롬프트의 문자열을 text로 바꿔준다. ctrl + c 와같은 명령을 줄때 rl_replace_line(””, 1) 을 하면 새로운 프롬프트로 바꿔준다. - Replace the contents of rl_line_buffer with text. The point and mark are preserved, if possible. If clear undo is non-zero, the undo list associated with the current line is cleared.
  • rl_redisplay
    • void rl_redisplay (void); - read_line 버퍼에 있는 가장 최근값으로 보여준다.
  • add_history
    • int add_history(const char *); - history에 문자열을 저장한다.