상위 질문
타임라인
채팅
관점

GNU readline

명령 줄 인터페이스에서 줄 편집, 입력 기록 저장 등을 하는 라이브러리 위키백과, 무료 백과사전

Remove ads

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

간략 정보 원저자, 개발자 ...

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

Remove ads

샘플 코드

다음의 코드는 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);
    }
}
Remove ads

주해

  1. GPL-3.0-or-later since version 6.0 (2009-02-20).
  2. GPL-2.0-or-later from version 2.1 (1997-06-05) until version 5.2 (2006-10-11).
  3. GPL-1.0-or-later from ? until version 2.0 (1994-08-04).

각주

외부 링크

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads