All Projects → muesli → Reflow

muesli / Reflow

Licence: mit
A collection of (ANSI-sequence aware) text reflow operations & algorithms

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Reflow

Imgcat
It's like cat, but for images.
Stars: ✭ 577 (+235.47%)
Mutual labels:  hacktoberfest, ansi
Swiftycontacts
A Swift library for Contacts framework.
Stars: ✭ 171 (-0.58%)
Mutual labels:  hacktoberfest
Revel
A high productivity, full-stack web framework for the Go language.
Stars: ✭ 12,463 (+7145.93%)
Mutual labels:  hacktoberfest
Hacktoberfest
Opportunity to start open source and PR experience
Stars: ✭ 171 (-0.58%)
Mutual labels:  hacktoberfest
Fiber
⚡️ Express inspired web framework written in Go
Stars: ✭ 17,334 (+9977.91%)
Mutual labels:  hacktoberfest
Docker
Run the Pelias geocoder in docker containers, including example projects.
Stars: ✭ 171 (-0.58%)
Mutual labels:  hacktoberfest
Grunt
Grunt: The JavaScript Task Runner
Stars: ✭ 12,133 (+6954.07%)
Mutual labels:  hacktoberfest
Androidbluetoothlibrary
A Library for easy implementation of Serial Bluetooth Classic and Low Energy on Android. 💙
Stars: ✭ 171 (-0.58%)
Mutual labels:  hacktoberfest
Ha Dockermon
A NodeJS RESTful API which can be used with Home Assistant to report the state of Docker Containers
Stars: ✭ 171 (-0.58%)
Mutual labels:  hacktoberfest
Mad
Map PoGo stuff with Android devices
Stars: ✭ 171 (-0.58%)
Mutual labels:  hacktoberfest
Loki
Like Prometheus, but for logs.
Stars: ✭ 14,483 (+8320.35%)
Mutual labels:  hacktoberfest
Croc
Easily and securely send things from one computer to another 🐊 📦
Stars: ✭ 17,834 (+10268.6%)
Mutual labels:  hacktoberfest
Dvc.org
🔗 DVC website and documentation
Stars: ✭ 171 (-0.58%)
Mutual labels:  hacktoberfest
Xbmc
Kodi is an award-winning free and open source home theater/media center software and entertainment hub for digital media. With its beautiful interface and powerful skinning engine, it's available for Android, BSD, Linux, macOS, iOS and Windows.
Stars: ✭ 13,175 (+7559.88%)
Mutual labels:  hacktoberfest
Docker Android Sdk
Stars: ✭ 171 (-0.58%)
Mutual labels:  hacktoberfest
Flameshot
Powerful yet simple to use screenshot software 🖥️ 📸
Stars: ✭ 15,429 (+8870.35%)
Mutual labels:  hacktoberfest
Awesome Design Systems
💅🏻 ⚒ A collection of awesome design systems
Stars: ✭ 13,308 (+7637.21%)
Mutual labels:  hacktoberfest
Rocket.chat.livechat
New Livechat client written in Preact
Stars: ✭ 171 (-0.58%)
Mutual labels:  hacktoberfest
K8s In 30mins
Learn how to set up the Kubernetes cluster in 30 mins and deploy the application inside the cluster.
Stars: ✭ 172 (+0%)
Mutual labels:  hacktoberfest
Naomi
The Naomi Project is an open source, technology agnostic platform for developing always-on, voice-controlled applications!
Stars: ✭ 171 (-0.58%)
Mutual labels:  hacktoberfest

reflow

Latest Release Build Status Coverage Status Go ReportCard GoDoc

A collection of ANSI-aware methods and io.Writers helping you to transform blocks of text. This means you can still style your terminal output with ANSI escape sequences without them affecting the reflow operations & algorithms.

Word-Wrapping

The wordwrap package lets you word-wrap strings or entire blocks of text.

import "github.com/muesli/reflow/wordwrap"

s := wordwrap.String("Hello World!", 5)
fmt.Println(s)

Result:

Hello
World!

The word-wrapping Writer is compatible with the io.Writer / io.WriteCloser interfaces:

f := wordwrap.NewWriter(limit)
f.Write(b)
f.Close()

fmt.Println(f.String())

Customize word-wrapping behavior:

f := wordwrap.NewWriter(limit)
f.Breakpoints = []rune{':', ','}
f.Newline = []rune{'\r'}

Unconditional Wrapping

The wrap package lets you unconditionally wrap strings or entire blocks of text.

import "github.com/muesli/reflow/wrap"

s := wrap.String("Hello World!", 7)
fmt.Println(s)

Result:

Hello W
orld!

The unconditional wrapping Writer is compatible with the io.Writer interfaces:

f := wrap.NewWriter(limit)
f.Write(b)

fmt.Println(f.String())

Customize word-wrapping behavior:

f := wrap.NewWriter(limit)
f.Newline = []rune{'\r'}
f.KeepNewlines = false
f.reserveSpace = true
f.TabWidth = 2

Tip: This wrapping method can be used in conjunction with word-wrapping when word-wrapping is preferred but a line limit has to be enforced:

wrapped := wrap.String(wordwrap.String("Just an example", 5), 5)
fmt.Println(wrapped)

Result:

Just
an
examp
le

ANSI Example

s := wordwrap.String("I really \x1B[38;2;249;38;114mlove\x1B[0m Go!", 8)
fmt.Println(s)

Result:

ANSI Example Output

Indentation

The indent package lets you indent strings or entire blocks of text.

import "github.com/muesli/reflow/indent"

s := indent.String("Hello World!", 4)
fmt.Println(s)

Result: Hello World!

There is also an indenting Writer, which is compatible with the io.Writer interface:

// indent uses spaces per default:
f := indent.NewWriter(width, nil)

// but you can also use a custom indentation function:
f = indent.NewWriter(width, func(w io.Writer) {
    w.Write([]byte("."))
})

f.Write(b)
f.Close()

fmt.Println(f.String())

Dedentation

The dedent package lets you dedent strings or entire blocks of text.

import "github.com/muesli/reflow/dedent"

input := `    Hello World!
  Hello World!
`

s := dedent.String(input)
fmt.Println(s)

Result:

  Hello World!
Hello World!

Padding

The padding package lets you pad strings or entire blocks of text.

import "github.com/muesli/reflow/padding"

s := padding.String("Hello", 8)
fmt.Println(s)

Result: Hello___ (the underlined portion represents 3 spaces)

There is also a padding Writer, which is compatible with the io.WriteCloser interface:

// padding uses spaces per default:
f := padding.NewWriter(width, nil)

// but you can also use a custom padding function:
f = padding.NewWriter(width, func(w io.Writer) {
    w.Write([]byte("."))
})

f.Write(b)
f.Close()

fmt.Println(f.String())
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].