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

패키지 상세v0.2.3

cli_repl

CLI REPL을 생성하기 위한 간단한 라이브러리

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
8.1만
좋아요
5
Pub 점수
130

패키지 설치

flutter pub add cli_repl

패키지 개요

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

명령줄 인터페이스(CLI)의 읽기-평가-출력 루프(REPL) 생성을 간소화하기 위해 설계된 가벼운 Flutter/Dart 라이브러리입니다. 최소한의 설정으로 상호작용 가능한 명령줄 도구를 구축할 수 있도록 하며, 입력 파싱, 명령 실행 및 출력 렌더링을 지원합니다. 스크립트 유틸리티, 디버깅 도구 또는 터미널 명령을 통해 사용자 상호작용이 필요한 교육용 애플리케이션에 적합합니다. 이 패키지는 크로스플랫폼이며 Android, iOS, Web, macOS, Windows, Linux에서 원활하게 작동합니다.

사용 사례

  • 인터랙티브 CLI 도구 만들기
  • 디버깅 콘솔 만들기
  • 교육용 프로그래밍 환경 개발
  • 명령줄 스크립트 프로토타이핑
  • 사용자 정의 REPL 인터페이스 구현

주요 기능

  • 명령을 정의하기 위한 간단한 API
  • 크로스 플랫폼 호환성
  • 내장된 입력/출력 처리
  • 비동기 명령 실행 지원
  • 확장 가능한 명령 등록 시스템

적합한 대상

  • CLI 유틸리티를 개발하는 개발자
  • 인터랙티브 코딩 튜토리얼을 구축하는 교육자
  • 터미널 기반 상호작용이 필요한 도구 제작자
  • 콘솔 유사 기능이 필요한 플러터 앱

고려 사항

  • 명령줄 상호작용 패턴에 대한 이해가 필요합니다
  • 텍스트 기반 입력/출력에 제한됨
  • 고성능 배치 처리에 최적화되지 않음
  • 복잡한 명령 로직을 위한 추가적인 오류 처리가 필요할 수 있습니다

원본 README

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

cli_repl

A simple library for creating CLI REPLs in Dart.

Features

Example Usage:

/// Echoes all entered lines
for (var line in new Repl().run()) {
  print(line);
} 
Statement Validation

By passing a validator to the Repl constructor, you can tell the REPL whether some entered text is a complete statement or not. The REPL calls this whenever a newline is entered to determine whether to yield a complete statement or continue it on a new line. The default validator returns true for all text.

Custom Prompts

By default, the REPL gives no prompt to the user when asking for a statement. You can change this by passing a prompt to the Repl constructor. By default, statement continuations on a new line will start with whitespace equal to the length of the prompt. You can override this by passing in continuation.

See example/example.dart for a demonstration of statement validation and custom prompts.

History

A history of entered lines is stored. History entries are modified when edited.

By default, a maximum of 50 entries are stored. You can change this by passing maxHistory into the Repl constructor.

Navigation
  • Left/Ctrl-B: Move left one character
  • Right/Ctrl-F: Move right one character
  • Home/Ctrl-A: Move to start of line
  • End/Ctrl-E: Move to end of line
  • Ctrl-L: Clear the screen
  • Ctrl-D: If there is text, delete the character under the cursor. If there is no text, exit.
  • Ctrl-F: Moves forward one character
  • Ctrl-B: Moves backward one character
  • Ctrl-U: Kill (cut) to start of line
  • Ctrl-K: Kill (cut) to end of line
  • Ctrl-Y: Yank (paste) previously killed text, inserting at cursor
  • Up/Down: Navigate within history
Testing REPLs

If running without a terminal, the input will be printed along with the prompts, allowing you to test REPLs made with this library by comparing stdout to the expected log input and output together.

See test/repl_test.dart for an example of this.

Running on Node

If you compile this to JS with Dart 2, you can run it on Node.

There are a couple of behavior differences:

  • Node's built-in readline library is used, so the supported navigation and history commands may vary from the Dart version.
  • Likewise, line history is managed by Node, and you can't change the maximum number of entries or edit history manually from Dart.
  • Only Repl.runAsync() works. Calling Repl.run() will throw an error.

카테고리

의존성

의존성 목록 2 개

소스 저장소

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