Blessed는 현대적인 JavaScript 환경에 ncurses와 같은 풍부한 위젯 기능을 제공하는 Node.js용 고수준 터미널 인터페이스 라이브러리입니다.
스크린 초기화
const blessed = require('blessed');
const screen = blessed.screen({
smartCSR: true, // 터미널 다시 그리기 깜빡임 최적화
autoPadding: true,
title: 'My Dashboard'
});
screen.append(element);
screen.render();
// 전역 키보드 종료 이벤트 처리
screen.key(['escape', 'q', 'C-c'], (ch, key) => {
return process.exit(0);
});
UI 요소 (Box 위젯)
const box = blessed.box({
top: 'center',
left: 'center',
width: '50%',
height: '50%',
content: '{bold}Hello{/bold} Blessed!',
tags: true, // 인라인 서식 태그 활성화
border: {
type: 'line' // 'line' 또는 'bg'
},
style: {
fg: 'white',
bg: 'magenta',
border: {
fg: '#f0f0f0'
},
hover: {
bg: 'green'
}
}
});
screen.append(box);
서식 태그
tags: true가 설정되면 요소가 인라인 서식 태그를 파싱합니다:
{bold}...{/bold}: 굵은 텍스트{underline}...{/underline}: 밑줄 텍스트{center}...{/center}: 가운데 정렬 콘텐츠{right}...{/right}: 오른쪽 정렬 텍스트{|}: 좌/우 가로 정렬 구분자{#c0ff33-fg}...{/}: 사용자 지정 16진수(hex) 전경색
원본 문자열의 태그를 이스케이프하려면 blessed.escape(str)를 사용하세요.