dart_console 是一個 Dart 庫,旨在透過提供超越標準庫功能的進階輸入與輸出控制來增強命令列應用程式開發。它讓開發者能夠建立具有游標操作、色彩文字和即時輸入處理等功能的互動式 CLI 經驗。適用於需要豐富終端互動的工具,支援在 macOS、Windows 和 Linux 上跨平台運作。該庫簡化了複雜的控制台操作,使建立使用者友善的命令列介面變得更容易。
適用情境
建構互動式 CLI 工具
建立彩色終端輸出
實現即時使用者輸入處理
開發命令列儀表板
管理終端機光標位置
在開發工具中提升終端使用者體驗
主要特色
進階輸入/輸出控制
跨平台相容性
顏色和樣式支援
游標定位與操作
即時輸入處理
終端互動的簡單 API
適合對象
尋求更豐富終端控制的 CLI 開發者
需要互動式使用者輸入的工具
基於控制台的應用程式,帶有視覺反饋
Dart 開發人員建構開發工具
需要終端樣式和格式化的專案
使用建議
需要終端環境(非網頁)
僅限基於控制台的應用程式
可能具有平台特定的特性
不適用於網頁或行動應用程式
取決於底層終端功能
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
A Dart library for building console applications.
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();
return0;
}
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