GNU readline명령 줄 인터페이스에서 줄 편집 및 입력 기록 저장 등의 역할을 하는 라이브러리이다. GNU 프로젝트에 속해 있다.

GNU readline
원저자Brian Fox
개발자Chet Ramey
발표일1989년(35년 전)(1989)
안정화 버전
8.2[1] 위키데이터에서 편집하기 / 2022년 9월 26일
저장소
프로그래밍 언어C
운영 체제크로스 플랫폼
종류라이브러리
라이선스GNU 일반 공중 허가서
웹사이트공식 사이트

GNU readline은 입력 자동 완성, 커서 이동, 잘라내기, 복사, 붙여넣기 등의 기능을 지원하며, Bash 등의 명령 줄 기반 인터랙티브 소프트웨어에서 사용된다.

샘플 코드 편집

다음의 코드는 C로 작성되어 있으며 -lreadline 컴파일러 플래그를 사용하여 컴파일해야 한다:

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <readline/readline.h>
#include <readline/history.h>

int main()
{
    char* input, shell_prompt[100];

    // Configure readline to auto-complete paths when the tab key is hit.
    rl_bind_key('\t', rl_complete);

    for(;;) {
        // Create prompt string from user name and current working directory.
        snprintf(shell_prompt, sizeof(shell_prompt), "%s:%s $ ", getenv("USER"), getcwd(NULL, 1024));

        // Display prompt and read input (n.b. input must be freed after use)...
        input = readline(shell_prompt);

        // Check for EOF.
        if (!input)
            break;

        // Add input to history.
        add_history(input);

        // Do stuff...

        // Free input.
        free(input);
    }
}

각주 편집

  1. “Readline-8.2 Release available” (영어). 2022년 9월 26일. 2022년 9월 26일에 확인함. 

외부 링크 편집