搜索插件、代码仓与 APP 分类

插件详情v5.1.2

dart_console

一个用于命令行应用程序的辅助库,这些程序需要比标准库提供的更多输入/输出控制。

macOSWindowsLinux
近 30 天下载
49.5万
喜欢数
147
Pub 分数
160

安装插件

flutter pub add dart_console

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

dart_console 是一个 Dart 库,旨在通过提供超越标准库功能的高级输入和输出控制来增强命令行应用程序的开发。它使开发者能够创建具有光标操作、彩色文本和实时输入处理等功能的交互式 CLI 体验。适用于需要丰富终端交互的工具,支持在 macOS、Windows 和 Linux 上跨平台运行。该库简化了复杂的控制台操作,使构建用户友好的命令行界面变得更加容易。

适合场景

  • 构建交互式 CLI 工具
  • 创建彩色终端输出
  • 实现实时用户输入处理
  • 开发命令行仪表板
  • 管理终端光标位置
  • 在开发工具中提升终端用户体验

主要特点

  • 高级输入/输出控制
  • 跨平台兼容性
  • 颜色和样式支持
  • 光标定位与操作
  • 实时输入处理
  • 终端交互的简单 API

适合对象

  • 寻求更丰富终端控制的 CLI 开发者
  • 需要交互式用户输入的工具
  • 基于控制台的应用程序,带有视觉反馈
  • Dart 开发人员构建开发工具
  • 需要终端样式和格式化的项目

使用建议

  • 需要终端环境(非网页)
  • 仅限基于控制台的应用程序
  • 可能具有平台特定的特性
  • 不适用于网页或移动应用
  • 取决于底层终端功能

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

A Dart library for building console applications.

pub package Language Build codecov

This library contains a variety of useful functions for console application development, including:

  • Reading the current window dimensions (height, width)
  • Reading and setting the cursor location
  • Setting foreground and background colors
  • Manipulating the console into "raw mode", which allows more advanced keyboard input processing than the default dart:io library.
  • Reading keys and control sequences from the keyboard
  • Writing aligned text to the screen
  • Tabular data display, including month calendar

The library has been used to implement a Dart version of the Kilo text editor; when compiled with Dart it results in a self-contained kilo executable. The library is sufficient for a reasonably complete set of usage, including readline-style CLI and basic text games.

The library assumes a terminal that recognizes and implements common ANSI escape sequences. The package has been tested on macOS, Linux and Windows 10. Note that Windows did not support ANSI escape sequences in earlier versions.

The library uses the win32 package for accessing the Win32 API through FFI. That package contains many examples of using Dart FFI for more complex examples.

Usage

A simple example for the dart_console package:

import 'package:dart_console/dart_console.dart';

main() {
  final console = Console();

  console.clearScreen();
  console.resetCursorPosition();

  console.writeLine(
    'Console size is ${console.windowWidth} cols and ${console.windowHeight} rows.',
    TextAlignment.center,
  );

  console.writeLine();

  return 0;
}

More comprehensive demos of the Console class are provided, as follows:

Example Description
demo.dart Suite of test demos that showcase various capabilities
main.dart Basic demo of how to get started with the dart_console
keys.dart Demonstrates how dart_console processes control characters
readline.dart Sample command-line interface / REPL
kilo.dart Rudimentary text editor
life.dart Game of Life
table.dart Demonstrates tabular data display
calendar.dart Prints a monthly calendar on the screen

Acknowledgements

Special thanks to Matt Sullivan (@mjohnsullivan) and Samir Jindel (@sjindel-google) for their help in explaining FFI to me when it was first introduced and still undocumented.

Thanks to @erf for contributing the Game of Life example.

Features and bugs

Please file feature requests and bugs at the issue tracker.

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目

所在榜单