패키지, 저장소 및 앱 카테고리 검색

cli_dialog 표지
패키지 상세v0.5.0

cli_dialog

Inquirer.js 스타일로 아름답고 강력한 CLI 프롬프트를 만들고 테스트하세요.

macOSWindowsLinux
30일 다운로드
3.1천
좋아요
38
Pub 점수
140

패키지 설치

flutter pub add cli_dialog

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Inquirer.js를 영감으로 삼아 시각적으로 매력적이고 상호작용적인 명령줄 인터페이스(CLI) 프롬프트 생성을 가능하게 하는 플러터/다트 패키지입니다. 개발자는 터미널에서 입력 양식, 선택 메뉴, 확인 대화상자와 같은 풍부한 사용자 상호작용을 직접 구축할 수 있습니다. 테스트를 고려해 설계되어 CLI 워크플로우를 시뮬레이션하고 검증하기 쉬워졌습니다. macOS, Windows, Linux에서 호환되며, 다트 기반 CLI 애플리케이션에 원활하게 통합됩니다.

사용 사례

  • 인터랙티브 CLI 도구 만들기
  • 터미널 기반 사용자 흐름 테스트
  • 설정 워즈드 생성
  • 명령줄 구성 유틸리티 개발
  • 사용자 입력 검증 구현

주요 기능

  • Inquirer.js 스타일의 프롬프트
  • 내장 테스트 지원
  • 크로스 플랫폼 호환성
  • 일반적인 프롬프트 유형을 위한 간단한 API
  • 비동기 사용자 상호작용을 지원합니다

적합한 대상

  • CLI 앱을 구축하는 Dart 개발자
  • 테스트 가능한 터미널 인터페이스가 필요한 팀
  • 스크립트에서 사용자 입력이 필요한 도구
  • CLI 설계를 가르치는 교육 프로젝트
  • 사용자 상호작용이 있는 자동화 스크립트

고려 사항

  • 터미널 환경이 필요합니다
  • 콘솔 기반 출력에 제한됨
  • 복잡한 UI를 위해 추가 설정이 필요할 수 있습니다
  • GUI 애플리케이션에 적합하지 않습니다
  • 플랫폼별 터미널 동작에 따라 달라짐

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

cli_dialog

Build Status Pub Version Coverage Status

A Dart package which allows you to use Inquirer.js prompts with some additional features.

The following GIF shows a CLI dialog which was created using this library. You can also visit the library page on pub.dev.

Demo of cli_dialog

You can find the source for this example here

Usage

Basic Usage
import 'package:cli_dialog/cli_dialog.dart';

void main() {
  final dialog = CLI_Dialog(questions: [
    ['What is your name?', 'name']
  ]);
  final name = dialog.ask()['name'];
}

Whenever you want to create a CLI dialog you create a CLI_Dialog() instance.

The CLI_Dialog class supports multiple keyword arguments amongst which questions is the most basic one. questions is a list of questions and corresponding keys to retreive the answers.

Thus, each list entry for questions has the following syntax: [<question>, <key<].

Then you will want to call the ask() method. It performs the CLI dialog and returns a map with the keys you provided and the values it received from the user.

Boolean questions
import 'package:cli_dialog/cli_dialog.dart';

void main() {
  final dialog = CLI_Dialog(booleanQuestions: [
    ['Are you happy with this package?', 'isHappy']
  ]);
  final answer = dialog.ask()['isHappy'];
}

As the name suggests, boolean questions just asks the user for (y/N) answers and always returns bool values.

The N in (y/N) indicates that the default answer is no. You can change this by passing trueByDefault: true to the constructor.

List questions
import 'package:cli_dialog/cli_dialog.dart';

void main() {
  const listQuestions = [
    [
      {
        'question': 'What is your favourite colour?',
        'options': ['Red', 'Blue', 'Green']
      },
      'colour'
    ]
  ];

  final dialog = CLI_Dialog(listQuestions: listQuestions);
  final answer = dialog.ask();
  final colour = answer['colour'];
}

List questions allow the user to make a selection amongst several strings. 'question' is the question that will be printed before the selection. 'options' are the options from which the user chooses exactly one. 'colour' is the key used to retreive the answer.

Messages

Messages were added in 0.2.0. They are used to display information to users without prompting them for an answer.

You can use them like any other question using the messages keyword parameter or addQuestion(message, is_message: true). It is only optional to include a key if you are not using order.

Order
import 'package:cli_dialog/cli_dialog.dart';

void main() {
  const listQuestions = [
    [
      {
        'question': 'Where are you from?',
        'options': ['Africa', 'Asia', 'Europe', 'North America', 'South Africa']
      },
      'origin'
    ]
  ];

  const booleanQuestions = [
    ['Do you want to continue?', 'continue']
  ];

  final dialog = CLI_Dialog(
      booleanQuestions: booleanQuestions,
      listQuestions: listQuestions,
      order: ['origin', 'continue']);

  dialog.ask();
}

The optional keyword parameter order for the constructor allows you to set a custom order for your questions in the dialog by passing a list with keys in your required order.

If you do not indicate any order then the standard order is applied:

  1. All messages are displayed to the user.
  2. All regular questions.
  3. All boolean questions.
  4. All list questions.

We used the order parameter in this example because otherwise the question 'Do you want to continue' would be asked before 'Where are you from?' according to standard order.

Navigation mode

Navigation mode was added in 0.2.0. It allows users to freely navigate through the prompt and repeadetly answer questions if the want to. For the developer it is a matter of setting navigationMode to true:

final dialog = CLI_Dialog(navigationMode: true);

In navigation mode, each question is prepended by an index which shows the user which question he currently answers. The user can then prepend a colon to his answer and use these indices to jump to another question, even those he has not answered yet. For instance, answering :2 makes the user jump to the second question. After answering it, the user will be prompted with the third question (again) etc. Entering a question number which is out of scope finishes the CLI_Dialog and makes it return the answer map.

Testing

This package also provides a small infrastructure for testing your dialogs.

For this purpose, there is the named constructor CLI_Dialog.std() which has two required arguments:

  • std_input = a StdinService
  • std_output = a StdoutService

StdinService and StdoutService are classes which are provided with this library. There are always used internally for i/o. If you explicitly use these classes then you will probably want to set the mock parameter to true which will make these services mock objects.

Furtermore, it is mostly advised to pass std_output to std_input using the informStdout and isTest parameter to inform the StdoutService about standard input in echo mode. Details can be checked out in the tests I have written (test/).

How it works

This library uses ANSI/XTerm escape sequences and regular escape sequences. You can take a look at them in this file

Contributing

Of course you are welcome to contribute to this project by issuing a pull request on Github.

Please write unit tests (test/) for new functionality and make sure that test.sh and lint.sh (tool/) run succesfully before submitting.

Please format your code using dartfmt -w . (this is also covered by lint.sh).

Windows

cli_dialog supports Windows.

  • Colors look a bit different in command prompt
  • The UTF-16 right indicator is replaced by a simple >

Acknowledgements and Alternatives

This library is more a less a Dart port of Inquirer.js.

There is dart_inquirer which is not developed any more (even the Github repository was deleted by the author). It works fine but it has less features than this package (no colors, no navigation, no resume, no question mark etc.).

I also found interact but I have not tested it.

카테고리

의존성

의존성 목록 1 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.