Tiny Unicode‑aware & ANSI‑aware string CLI – written in Go – built on top of the internal public stringui package.
struiis the command‑line face ofstringuipackage:
think of it as a minimal, UTF‑8‑smart replacement forcut,wc, ortrthat actually understands emojis and ANSI escapes.The underlying
stringuipackage is 100 % independent – import it in any Go project without pulling the CLI.
- Everything from
stringuiat the tips of your fingers:- clean ANSI escapes
- measure visual width / height
- split / join / repeat helpers
- substring count
- UTF‑8 aware (CJK, wide & combined emojis)
- Zero runtime dependencies – the binary is fully self‑contained
- Ships as one tiny binary (≈ 3 MB with Go 1.22, CGO off)
go install github.com/guillaumeast/strui-go-cli/cmd/strui@latestThis will:
- detect your platform (Linux/macOS/Windows, x86_64/arm64),
- download the right binary from the latest release,
- install it to
~/.local/bin(or a custom path if you set$DEST), - add
~/.local/binto$PATHif needed, - and verify the checksum before running anything.
Test it:
strui width "$(printf "\033[31m1\n1🛑4\n12\033[0m")" // → 4go get github.com/guillaumeast/strui-go-cli/pkg/stringuiThen:
import "github.com/guillaumeast/strui-go-cli/pkg/stringui"
fmt.Println(stringui.Width("\033[31m1\n1🛑4\n12\033[0m")) // → 4strui installs a single executable called strui
(muscle‑memory friendly for folks migrating from the C++ version).
| Command | Description |
|---|---|
strui width <string> |
Return visual width (columns) of string |
strui height <string> |
Return number of lines in string |
strui clean <string> |
Remove ANSI escape sequences |
strui split <string> <separator> |
Vector‑split string on separator |
strui join ?--separator ?<sep> <...strings...> |
Join strings with optional separator |
strui repeat <count> <string> ?<separator> |
Repeat string count times |
strui count <value> <string> |
Count occurrences of value in string |
📚 See
go-runewidthfor more details on width computing.
Requirement: Docker
Tests are run locally and inside multiple Linux containers to guarantee portability:
make test # build + tests + multi‑distro checksstrui/
├── go.mod
├── go.sum
├── Makefile
├── cmd/
│ └── strui/ # CLI entry‑point
│ └── main.go
├── pkg/
│ └── stringui/ # public library
│ └── stringui.go
├── scripts/
│ ├── loader.sh
│ └── make.sh
└── tests/
└── unit.sh
- Runtime: none
- Build‑time:
- Go 1.22+
github.com/mattn/go-runewidth(vendored automatically)
“Measure what you see — not what you store.” 📏