Dart용 풍부하고 간단하며 동기적인 명령줄 프롬프트 라이브러리로, 인터랙티브한 CLI 애플리케이션을 쉽게 구축할 수 있도록 설계되었습니다. 텍스트, 비밀번호, 확인 및 선택 기반 입력과 같은 다양한 프롬프트 유형을 통해 사용자로부터 입력을 받는 깔끔한 API를 제공합니다. 이 라이브러리는 터미널 환경에서 사용자 상호작용이 필요한 도구, 스크립트 또는 개발 유틸리티에 적합합니다. Prompts는 Android, iOS, macOS, Windows, Linux 등 모든 주요 플랫폼에서 작동하여 매우 포터블합니다. 동기적 성격으로 async/await 보일러플레이트 없이 흐름 제어가 간단해집니다.
사용 사례
CLI 도구 빌드
인터랙티브 설정 워즈드
스크립트에서 사용자 입력 수집
개발 유틸리티 응용 프로그램
터미널 기반 구성
주요 기능
동기 API
여러 가지 프롬프트 유형
크로스 플랫폼 지원
간단하고 직관적인 문법
비동기/대기 필요 없음
적합한 대상
CLI 앱을 구축하는 Dart 개발자
터미널에서 사용자 상호작용이 필요한 도구
간단한 명령줄 인터페이스
고려 사항
비동기 워크플로우에 적합하지 않습니다
콘솔 기반 상호작용에 제한됨
입력 중 실행을 차단할 수 있음
터미널 접근이 필요합니다
GUI 애플리케이션용으로 설계되지 않음
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
prompts
Rich, simple, synchronous command-line prompt library for Dart.
Now with pretty colors!
Example
import'package:io/ansi.dart';
import'package:prompts/prompts.dart'as prompts;
voidmain() {
// Easily get a single line.var name = prompts.get('Enter your name');
print('Hello, $name!');
// ... Or many lines.print('Tell me about yourself.');
var bio = prompts.get(
"Enter some lines, using '\\' to escape line breaks",
allowMultiline: true,
inputColor: resetAll,
);
print('About $name:\n$bio');
// Supports default values.
name = prompts.get('Enter your REAL name', defaultsTo: name);
print('Hello, $name!');
// "High-level" prompts are built upon [get].// For example, we can prompt for confirmation trivially.bool shouldDownload = prompts.getBool('Really download this package?');
if (!shouldDownload)
print('Not downloading.');
elseprint('Downloading...!');
// Or, get an integer, WITH validation.int age = prompts.getInt('How old are you?', defaultsTo: 23, chevron: false);
print('$name, you\'re $age? Cool!');
// We can choose from various values.// There are two methods - shorthand and regular.var rgb = [Color.red, Color.green, Color.blue];
Color color = prompts.chooseShorthand('Tell me your favorite color', rgb);
print('You chose: ${color.about}');
// The standard chooser prints to multiple lines, but is often// clearer to read, and has more obvious semantics.
color = prompts.choose('Choose another color', rgb, defaultsTo: Color.blue);
print(color.about);
}
classColor{
finalString name, description;
constColor(this.name, this.description);
staticconstColor red = constColor('Red', 'The color of apples.'),
blue = constColor('Blue', 'The color of the sky.'),
green = constColor('Green', 'The color of leaves.');
Stringget about => '$name - $description';
@overrideStringtoString() => name;
}