搜尋套件、儲存庫與 APP 分類

prompts 封面
套件詳情v2.0.0

prompts

豐富、簡單、同步的命令列提示程式庫,適用於 Dart。

AndroidiOSmacOSWindowsLinux
近 30 天下載
116萬
喜歡數
29
Pub 分數
140

安裝套件

flutter pub add prompts

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個功能豐富、簡單且同步的命令列提示庫,專為 Dart 設計,旨在讓建構互動式 CLI 應用變得輕鬆。它提供了一個乾淨的 API,支援透過多種提示類型(如文字、密碼、確認和選擇型輸入)向使用者取得輸入。該庫非常適合需要在終端環境中進行使用者互動的工具、腳本或開發實用程式。Prompts 支援所有主要平台,包括 Android、iOS、macOS、Windows 和 Linux,具有高度可移植性。其同步特性簡化了流程控制,無需使用 async/await 的樣板程式碼。

適用情境

  • 構建 CLI 工具
  • 互動式設定向導
  • 腳本中的使用者輸入收集
  • 開發實用程式應用程式
  • 基於終端的設定

主要特色

  • 同步 API
  • 多種提示類型
  • 跨平台支援
  • 簡單、直覺的語法
  • 無需 async/await

適合對象

  • Dart 開發人員建構 CLI 應用
  • 終端中需要使用者互動的工具
  • 簡單的命令列介面

使用建議

  • 不適用於非同步工作流程
  • 僅限基於控制台的互動
  • 可能在輸入期間阻擋執行
  • 需要終端存取
  • 不適用於圖形使用者介面應用程式

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

prompts

Pub

Rich, simple, synchronous command-line prompt library for Dart.

Now with pretty colors!

GIF Demo

Example

import 'package:io/ansi.dart';
import 'package:prompts/prompts.dart' as prompts;

void main() {
  // 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.');
  else
    print('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);
}

class Color {
  final String name, description;

  const Color(this.name, this.description);

  static const Color red = const Color('Red', 'The color of apples.'),
      blue = const Color('Blue', 'The color of the sky.'),
      green = const Color('Green', 'The color of leaves.');

  String get about => '$name - $description';

  @override
  String toString() => name;
}

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案