Git Product home page Git Product logo

ansiwrap's Introduction

ansiwrap

ANSI escape sequence / unicode aware text wrapping for Go.

Code of Conduct | Contribution Guidelines

GitHub release GoDoc Travis Go Report Card License

Why ansiwrap?

Old text wrappers can't handle ANSI escape sequence formatting, but ansiwrap knows what to do!

Features

  • ANSI escape sequence aware
  • unicode aware
  • Greedy and balanced text wrapping
  • Flexible indenting

Example

Screenshot

Code

package main

import (
	"fmt"
	"github.com/manifoldco/ansiwrap"
)

// text including ANSI formatting
const text = "Sweet jujubes tootsie roll cotton candy lollipop. Marzipan donut" +
	" gummies tiramisu fruitcake sesame snaps icing danish.  Ice cream sesame snaps" +
	" candy lemon drops toffee oat cake pastry gummies soufflé. Candy chocolate cake" +
	" ice cream tiramisu \033[35mmarshmallow\033[0m sesame snaps" +
	" \033[35mmarshmallow\033[0m tootsie roll. Pastry cupcake biscuit. Tiramisu" +
	" chocolate sweet sugar plum. Pastry cupcake tart chocolate cake gingerbread" +
	" toffee cake gummi bears oat cake. Icing ice cream danish danish bonbon" +
	" \033[35mmarshmallow\033[0m \033[35mmarshmallow\033[0m gummi bears chocolate bar." +
	" Sesame snaps icing chocolate liquorice macaroon sugar plum macaroon ice cream." +
	" Tootsie roll sugar plum oat cake jelly toffee. Sweet cotton candy candy" +
	" caramels carrot cake cotton candy tiramisu gummies cheesecake. Sweet marzipan" +
	" topping jujubes sesame snaps. Cupcake cake jelly beans candy canes ice cream" +
	" jelly gummies."

func main() {
	// Add your favorite ANSI escape code library, and terminal width reporter.

	// A bold and blue label
	label := "\033[1;34mCupcake ipsum:\033[0m "

	// count the printable characters in label
	rc := ansiwrap.RuneCount(label)

	// Wrap the text to 80 chars, aligning with the end of the label
	// Lines are wrapped with minimal raggedness, as the text is long enough
	// to have ansiwrap choose the Balanced algorithm.
	fmt.Println(ansiwrap.WrapIndent(label+text, 70, 0, rc))
}

For more examples and documentation, see the GoDoc reference

ansiwrap's People

Contributors

garyposter avatar jbowes avatar jelmersnoeck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.