상위 질문
타임라인
채팅
관점
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
주해
각주
외부 링크
Wikiwand - on
Seamless Wikipedia browsing. On steroids.
Remove ads