ncurses
ncurses(new curses)는 terminal 종류에 독립적인 문자 셀 화면 제어 API와 terminfo database·관리 도구를 제공하는 library다. 대화형 TUI 프로그램을 만들거나 terminal capability를 조회·컴파일할 때 사용한다.
Summary
- 화면 갱신, cursor 이동, 색상, keyboard 입력을 terminal별 escape sequence 차이에서 분리한다.
- 기본 library 외에 겹치는 window를 위한
panel, menu를 위한menu, 입력 form을 위한formlibrary를 제공한다. tic,infocmp,toe,tput,clear,tabs,tset/reset같은 terminfo 관련 utility가 함께 배포된다.- 새 프로그램은 locale과 wide-character 처리를 위해 가능하면
ncurseswinterface를 우선 검토한다.
Installation
Debian / Ubuntu
개발 header와 library, terminal utility를 설치한다.
sudo apt update sudo apt install libncurses-dev ncurses-bin
추가 terminal description이 필요하면 ncurses-term, 문서가 필요하면 ncurses-doc package를 별도로 설치한다.
RHEL / Fedora
sudo dnf install ncurses-devel ncurses
ncurses-devel은 header와 개발용 library를, ncurses는 지원 utility를 제공한다.
macOS
brew install ncurses
ncurses formula는 keg-only다. build system이 macOS 기본 curses보다 Homebrew 설치본을 사용해야 한다면 pkg-config 검색 경로나 compiler/linker flag를 명시해야 할 수 있다. brew info ncurses에 표시되는 현재 경로와 안내를 확인한다.
Windows
ncurses upstream과 Microsoft winget에서 공식 ncurses package 설치 방법은 확인되지 않는다. MSYS2/MinGW 환경의 package나 별도 curses 구현인 PDCurses를 사용할 수 있지만, API·build·terminal 동작이 ncurses와 완전히 같다고 가정하지 않는다.
Verification
infocmp -V ncursesw6-config --version
배포판에 따라 config script 이름이 ncurses6-config이거나 설치되지 않을 수 있다. 이때는 pkg-config –modversion ncursesw로 확인한다.
Usage
ncurses 자체는 단일 executable이 아니라 library와 utility 묶음이다.
pkg-config --cflags --libs ncursesw cc tui.c -o tui $(pkg-config --cflags --libs ncursesw)
pkg-config –cflags –libs ncursesw: compiler와 linker flag를 출력한다.ncursesw6-config –cflags –libs: 설치본이 제공하는 build flag를 출력한다.infocmp [OPTIONS] [TERM…]: terminfo entry를 출력하거나 비교한다.tic [OPTIONS] SOURCE_FILE: terminfo source를 검사하거나 compile한다.toe [OPTIONS] [FILE…]: 사용 가능한 terminal type을 나열한다.tput [OPTIONS] CAPABILITY [PARAMETER…]: terminfo capability를 shell에서 조회하거나 실행한다.
Utilities
| Command | Intent |
|---|---|
infocmp | 현재 또는 지정한 terminal의 terminfo description을 출력·비교한다. |
tic | terminfo source file을 검증하고 compiled database로 변환한다. |
toe | database에 등록된 terminal type과 설명을 나열한다. |
tput | terminal capability 값이나 control sequence를 조회한다. |
clear | 현재 terminal에 맞는 screen clear sequence를 출력한다. |
tabs | hardware tab stop을 설정한다. |
tset, reset | terminal mode와 상태를 초기화하거나 복구한다. |
captoinfo, infotocap | termcap과 terminfo source 표현을 변환한다. |
Examples
Terminal 정보 조회
printf 'TERM=%s\n' "$TERM" infocmp "$TERM" infocmp -D toe -a tput colors tput cols tput lines
TERM 값을 실제 terminal과 맞지 않는 값으로 임의 변경하면 색상, key 입력, 화면 갱신이 깨질 수 있다.
사용자 범위 terminfo 검사·설치
먼저 source를 검사하고, system database 대신 사용자 전용 directory에 compile한다.
tic -c custom.terminfo tic -x -o "$HOME/.terminfo" custom.terminfo infocmp custom-terminal-name
sudo tic보다 사용자 범위에서 검사·시험하는 절차를 먼저 사용한다.
C 프로그램
#include <locale.h> #include <ncurses.h> int main(void) { setlocale(LC_ALL, ""); if (initscr() == NULL) { return 1; } cbreak(); noecho(); keypad(stdscr, TRUE); printw("Press any key to exit."); refresh(); getch(); endwin(); return 0; }
cc tui.c -o tui $(pkg-config --cflags --libs ncursesw) ./tui
프로그램이 signal이나 error로 종료될 때도 가능하면 endwin()을 호출해 terminal mode를 복구한다.
Configuration
TERM: 현재 terminal type의 terminfo entry 이름이다.TERMINFO: 단일 사용자 지정 terminfo database 위치를 지정한다.TERMINFO_DIRS: 여러 terminfo database 검색 경로를 colon으로 구분한다. 빈 항목은 system 기본 위치로 해석될 수 있다.$HOME/.terminfo: 사용자별 compiled terminfo entry의 일반적인 위치다.
TERMINFO나 TERMINFO_DIRS를 설정하면 system database 검색 순서가 달라진다. 문제를 재현할 때는 해당 환경 변수와 infocmp -D 결과를 함께 확인한다.
Troubleshooting
Error opening terminal
printf '%s\n' "$TERM"으로 빈 값이나 잘못된 terminal type인지 확인한다.infocmp "$TERM"으로 해당 entry가 검색되는지 확인한다.- container나 최소 설치 환경에서는
ncurses-base또는ncurses-term등 terminal database package가 빠졌는지 확인한다.
화면이나 입력 상태가 깨짐
reset
reset은 terminal mode를 변경하므로 pipe나 비대화형 session이 아니라 문제가 발생한 terminal에서 실행한다. 화면만 지울 때는 clear 또는 tput clear를 사용한다.
Linker가 symbol을 찾지 못함
- source file 뒤에 library flag가 오도록 link 순서를 확인한다.
- wide-character API를 사용했다면
ncurses가 아니라ncursesw의 flag를 사용한다. pkg-config –cflags –libs ncursesw또는ncursesw6-config –cflags –libs결과를 build system에 전달한다.
Compatibility
- 2026-08-10 기준 upstream 안정 release는 ncurses 6.6이다.
- 이 저장소의 base environment에서
infocmp -V로 확인한 version은ncurses 6.1.20180224다. 아래 Help output도 이 설치본 기준이다. - 배포판별 package 분할, library 이름, header 경로, terminfo database 위치는 다를 수 있다.
- ncurses extension만 사용하면 다른 curses 구현으로의 portability가 낮아질 수 있다. portable code가 필요하면 X/Open Curses 범위와 각 함수의 manual page를 확인한다.
dialog는 ncurses를 사용하는 별도 application이고whiptail은 newt 기반 대체 utility다. 세 이름을 동일한 library나 호환 API로 취급하지 않는다.
Help
See Also
History
- codex:: 2026-08-10 dialog·whiptail과 ncurses의 TUI layer 및 구현 차이를 명확히 하고 상호 link를 추가함.
- codex:: 2026-08-10 ncurses library, terminfo utility, installation, build, troubleshooting reference를 작성함.