sisteransi

中文文档
2.0.0发布于 2026/06/25MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 3.6亿

ANSI escape codes for some terminal swag

原始使用文档
文档目录9 节
  1. Installation
  2. Usage
  3. API
  4. cursor
  5. scroll
  6. erase
  7. clear
  8. Credit
  9. License

sister ANSI Version CI Downloads

Ansi escape codes faster than you can say "Bam bam".

Installation

npm install sisteransi

Note: sisteransi 2.0 is ESM-only and needs Node.js >= 20. import works on any Node 20+, and CommonJS can require() it on Node 20.19+ (where require(esm) is unflagged). Stay on the 1.x line only if you're on older Node. (Contributing? The test suite runs the TypeScript source directly via Node's type stripping, so local development needs Node.js >= 22.)

Usage

import { cursor } from 'sisteransi';
// or grab everything: import * as ansi from 'sisteransi';

const p = str => process.stdout.write(str);

// move cursor to 2, 1
p(cursor.to(2, 1));

// up two, down one
p(cursor.up(2) + cursor.down(1));

API

cursor

to(x, y)

Set the absolute position of the cursor. x0 y0 is the top left of the screen.

move(x, y)

Set the position of the cursor relative to its current position.

up(count = 1)

Move cursor up a specific amount of rows. Default is 1.

down(count = 1)

Move cursor down a specific amount of rows. Default is 1.

forward(count = 1)

Move cursor forward a specific amount of rows. Default is 1.

backward(count = 1)

Move cursor backward a specific amount of rows. Default is 1.

nextLine(count = 1)

Move cursor to the next line a specific amount of lines. Default is 1.

prevLine(count = 1)

Move cursor to the previous a specific amount of lines. Default is 1.

left

Move cursor to the left side.

hide

Hide cursor.

show

Show cursor.

save

Save cursor position.

restore

Restore cursor position.

scroll

up(count = 1)

Scroll display up a specific amount of lines. Default to 1.

down(count = 1)

Scroll display down a specific amount of lines. Default to 1.

erase

screen

Erase the screen and move the cursor the top left position.

up(count = 1)

Erase the screen from the current line up to the top of the screen. Default to 1.

down(count = 2)

Erase the screen from the current line down to the bottom of the screen. Default to 1.

line

Erase the entire current line.

lineEnd

Erase from the current cursor position to the end of the current line.

lineStart

Erase from the current cursor position to the start of the current line.

lines(count)

Erase from the current cursor position up the specified amount of rows.

clear

screen

Clear the terminal screen. (Viewport)

Credit

This is a fork of ansi-escapes.

License

MIT © Terkel Gjervig

版本与发布记录

sisteransi 共发布 10 个版本,首次发布于 2018/02/20;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.0latest2026/06/254 个月前
1.0.52020/03/186 年前
1.0.42019/11/116 年前
1.0.32019/08/057 年前
1.0.22019/07/047 年前
1.0.12019/07/037 年前

关于 sisteransi 的常见问题

sisteransi 是什么?

ANSI escape codes for some terminal swag

如何安装 sisteransi?

在项目目录运行 npm install sisteransi,或使用 pnpm add / yarn add / bun add。

sisteransi 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

sisteransi 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

sisteransi 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

sisteransi 可以商用吗?

sisteransi 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

sisteransi 的下载量有多少?

根据 npm 官方下载统计,sisteransi 在 2026/10/07 – 2026/11/05 这 30 天内被下载 363,929,224 次,日均约 12,130,974 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

sisteransi 还在维护吗?

最新版本 2.0.0 发布于 2026/06/25(4 个月前);至今共发布 10 个版本,其中过去 12 个月发布了 1 个;首次发布于 2018/02/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。