Wrap unicode text not to exceed a certain width.

wwrap Coverage Status

Wrap unicode text not to exceed a specified column width.

There is a fold utility in the GNU Coreutils package, but unfortunately it works on bytes and corrupts CJK text. This is a crossplatform tool for the same purpose but adapted for unicode. Binaries are dependency free.

Install

On any system where Go is installed:

$ go install github.com/kuredoro/wwrap/cmd/wwrap@latest

On Arch Linux:

$ yay -S wwrap

On Windows, if scoop is installed:

> scoop bucket add kuredoro https://github.com/kuredoro/scoop-bucket
> scoop install wwrap

See in action

$ cat test.txt
吾輩は猫である。名前はまだ無い。

 どこで生れたかとんと見当がつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。吾輩はここで始めて人間というものを見た。しかもあとで聞くとそれは書生という人間中で一番獰悪な種族であったそうだ。この書生というのは時々我々を捕えて煮て食うという話である。しかしその当時は何という考もなかったから別段恐しいとも思わなかった。ただ彼の掌に載せられてスーと持ち上げられた時何だかフワフワした感じがあったばかりである。掌の上で少し落ちついて書生の顔を見たのがいわゆる人間というものの見始であろう。この時妙なものだと思った感じが今でも残っている。第一毛をもって装飾されべきはずの顔がつるつるしてまるで薬缶だ。その後猫にもだいぶ逢ったがこんな片輪には一度も出会わした事がない。のみならず顔の真中があまりに突起している。そうしてその穴の中から時々ぷうぷうと煙を吹く。どうも咽せぽくて実に弱った。これが人間の飲む煙草というものである事はようやくこの頃知った。

$ cat lorem.txt
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Dolor magna eget est lorem ipsum dolor sit. Tellus mauris a diam maecenas sed enim ut sem viverra. Auctor eu augue ut lectus. Non consectetur a erat nam at. Sagittis id consectetur purus ut. Est sit amet facilisis magna. Bibendum enim facilisis gravida neque convallis a cras. Sed tempus urna et pharetra. Consectetur adipiscing elit ut aliquam purus sit amet luctus. Non curabitur gravida arcu ac. Morbi leo urna molestie at elementum. Malesuada fames ac turpis egestas sed tempus.

$ cat test.txt | wwrap -w 80
吾輩は猫である。名前はまだ無い。

 どこで生れたかとんと見当がつかぬ。何でも薄暗いじめじめした所でニャーニャー泣い
ていた事だけは記憶している。吾輩はここで始めて人間というものを見た。しかもあとで
聞くとそれは書生という人間中で一番獰悪な種族であったそうだ。この書生というのは時
々我々を捕えて煮て食うという話である。しかしその当時は何という考もなかったから別
段恐しいとも思わなかった。ただ彼の掌に載せられてスーと持ち上げられた時何だかフワ
フワした感じがあったばかりである。掌の上で少し落ちついて書生の顔を見たのがいわゆ
る人間というものの見始であろう。この時妙なものだと思った感じが今でも残っている。
第一毛をもって装飾されべきはずの顔がつるつるしてまるで薬缶だ。その後猫にもだいぶ
逢ったがこんな片輪には一度も出会わした事がない。のみならず顔の真中があまりに突起
している。そうしてその穴の中から時々ぷうぷうと煙を吹く。どうも咽せぽくて実に弱っ
た。これが人間の飲む煙草というものである事はようやくこの頃知った。

$ wwrap -w 80 lorem.txt
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor i
ncididunt ut labore et dolore magna aliqua. Dolor magna eget est lorem ipsum dol
or sit. Tellus mauris a diam maecenas sed enim ut sem viverra. Auctor eu augue u
t lectus. Non consectetur a erat nam at. Sagittis id consectetur purus ut. Est s
it amet facilisis magna. Bibendum enim facilisis gravida neque convallis a cras.
 Sed tempus urna et pharetra. Consectetur adipiscing elit ut aliquam purus sit a
met luctus. Non curabitur gravida arcu ac. Morbi leo urna molestie at elementum.
 Malesuada fames ac turpis egestas sed tempus.

Unfortunately, not in all browsers the above texts would be of the same width, however, in terminal windows, they are.

Owner
しずえ
あなたの心を惑わせる。
しずえ
Similar Resources

Package sanitize provides functions for sanitizing text in golang strings.

sanitize Package sanitize provides functions to sanitize html and paths with go (golang). FUNCTIONS sanitize.Accents(s string) string Accents replaces

Dec 5, 2022

Small and fast FTS (full text search)

Microfts A small full text indexing and search tool focusing on speed and space. Initial tests seem to indicate that the database takes about twice as

Jul 30, 2022

text to speech bot for discord

text to speech bot for discord

text to speech bot for discord

Oct 1, 2022

A diff3 text merge implementation in Go

Diff3 A diff3 text merge implementation in Go based on the awesome paper below. "A Formal Investigation of Diff3" by Sanjeev Khanna, Keshav Kunal, and

Nov 5, 2022

gomtch - find text even if it doesn't want to be found

gomtch - find text even if it doesn't want to be found Do your users have clever ways to hide some terms from you? Sometimes it is hard to find forbid

Sep 28, 2022

Unified text diffing in Go (copy of the internal diffing packages the officlal Go language server uses)

gotextdiff - unified text diffing in Go This is a copy of the Go text diffing packages that the official Go language server gopls uses internally to g

Dec 26, 2022

Convert scanned image PDF file to text annotated PDF file

Convert scanned image PDF file to text annotated PDF file

Jisui (自炊) This tool is PoC (Proof of Concept). Jisui is a helper tool to create e-book. Ordinary the scanned book have not text information, so you c

Dec 11, 2022

A modern text indexing library for go

A modern text indexing library for go

bleve modern text indexing in go - blevesearch.com Features Index any go data structure (including JSON) Intelligent defaults backed up by powerful co

Jan 4, 2023

Paranoid text spacing in Go (Golang)

pangu.go Paranoid text spacing for good readability, to automatically insert whitespace between CJK (Chinese, Japanese, Korean) and half-width charact

Oct 15, 2022
Zero-width character detection and removal for Go

go-zero-width Zero-width character detection and removal for Go. Inspired by this Medium article. Installation go get github.com/trubitsyn/go-zero-wid

Jan 8, 2023
A general purpose application and library for aligning text.

align A general purpose application that aligns text The focus of this application is to provide a fast, efficient, and useful tool for aligning text.

Sep 27, 2022
Parse placeholder and wildcard text commands

allot allot is a small Golang library to match and parse commands with pre-defined strings. For example use allot to define a list of commands your CL

Nov 24, 2022
Guess the natural language of a text in Go

guesslanguage This is a Go version of python guess-language. guesslanguage provides a simple way to detect the natural language of unicode string and

Dec 26, 2022
omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.
omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.

omniparser Omniparser is a native Golang ETL parser that ingests input data of various formats (CSV, txt, fixed length/width, XML, EDI/X12/EDIFACT, JS

Jan 4, 2023
Produces a set of tags from given source. Source can be either an HTML page, Markdown document or a plain text. Supports English, Russian, Chinese, Hindi, Spanish, Arabic, Japanese, German, Hebrew, French and Korean languages.
Produces a set of tags from given source. Source can be either an HTML page, Markdown document or a plain text. Supports English, Russian, Chinese, Hindi, Spanish, Arabic, Japanese, German, Hebrew, French and Korean languages.

Tagify Gets STDIN, file or HTTP address as an input and returns a list of most popular words ordered by popularity as an output. More info about what

Dec 19, 2022
Extract urls from text

xurls Extract urls from text using regular expressions. Requires Go 1.13 or later. import "mvdan.cc/xurls/v2" func main() { rxRelaxed := xurls.Relax

Jan 7, 2023
Easy AWK-style text processing in Go

awk Description awk is a package for the Go programming language that provides an AWK-style text processing capability. The package facilitates splitt

Jul 25, 2022
Change the color of console text.

go-colortext package This is a package to change the color of the text and background in the console, working both under Windows and other systems. Un

Oct 26, 2022
Templating system for HTML and other text documents - go implementation

FAQ What is Kasia.go? Kasia.go is a Go implementation of the Kasia templating system. Kasia is primarily designed for HTML, but you can use it for any

Mar 15, 2022