mansil
Mansil is a Multi-language ANSI escape code Library
It provides the commonly used ANSI escape codes and helper functions for:
- Dart
- Go
- JS/TS
- Python
- Rust
Install
# Dart
dart pub add mansil
# Go
go get github.com/vieolo/mansil
# JS/TS
npm install @vieolo/mansil
# Python
pip install mansil # using pip
uv add mansil # using uv
# Rust
cargo add mansil
Helpers
Besides the codes, every language has the same helpers, named in its own style:
| Helper | Go | Python, Rust | JS/TS, Dart |
|---|---|---|---|
| Move the cursor | CursorUp(n), ... |
cursor_up(n), ... |
Mansil.cursorUp(n), ... |
| Remove escape sequences | Strip(s) |
strip(s) |
Mansil.strip(s) |
| Measure in terminal columns | VisibleWidth(s) |
visible_width(s) |
Mansil.visibleWidth(s) |
| Cut to a width | Truncate(s, width, tail) |
truncate(s, width, tail) |
Mansil.truncate(s, width, tail) |
- The relative movements (up, down, right, left, next line and previous line) return an empty string for
n <= 0, so a distance that comes out as 0 does not move the cursor.CursorColumnandCursorPositionare absolute and 1-based. VisibleWidthcounts CJK and most emoji as two columns, and so is a narrow character followed by the emoji presentation selector (U+FE0F). Combining marks, zero-width and control characters count as none. The characters of a joined emoji are counted one by one, so it can come out wider than the terminal draws it.Truncatedrops only the visible characters after the cut and keeps every escape sequence, so the styles and hyperlinks that the text closes stay closed. The tail counts towards the width.
For example, to redraw a block of lines in place in Go:
fmt.Print(mansil.CursorPrevLine(lastHeight) + mansil.ClearScreenDown)
for _, line := range lines {
fmt.Println(mansil.Truncate(line, termWidth, "…"))
}
lastHeight = len(lines)
Development
The codes and the character width tables live in ansi_codes.json. The generator writes them between the GEN START and GEN END comments of each language's source. Everything outside those comments is written by hand.
go run ./cmd/main.go generate # regenerate the codes
uv run --no-project agent.py # regenerate, then check and test every language
uv run --no-project agent.py go # only some groups: generate, go, python, rust, ts, dart
The tests are in mansil_test.go (Go), src/lib.rs (Rust) and test/ (Dart, Python and JS/TS).
Metadata
Release files for mansil 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mansil-0.2.0.tar.gz | 37.1 kB | Without provenance | Details for mansil-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mansil-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for mansil-0.2.0-py3-none-any.whl |
Total release size: 43.7 kB
Release files / mansil-0.2.0.tar.gz
| Download URL | mansil-0.2.0.tar.gz |
|---|---|
| Size | 37.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a0b9f703ac2f6969654865ad0ef79bfce6a6136eb10c963249280b4c01beeb7f
|
|
BLAKE2b-256 checksum How to use checksums |
5399751c52a69a7e52c06543f27c6ce06ea72f41e4780b182d3afe69bcb33527
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / mansil-0.2.0-py3-none-any.whl
| Download URL | mansil-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
01b05d25cbc53ef9c260285478f37f35069999ad3637374d8c555951a10d8973
|
|
BLAKE2b-256 checksum How to use checksums |
8bdc4259e3671314ba8e0ddbe8410de7f1be87112df67d7bbb21e8df87215145
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for mansil 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.