prose

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

README

🤓 Prose | CLI output for humans

A library built on the shoulders of giants specifically for formatting CLI output in a way that is pleasing to read in the terminal and easy to compose in source code.

About

The guiding principle of this library is writing human-readable text should also be human-readable in code. The formatting is opinionated because humans are opinionated.

Walkthrough

import "github.com/jogly/prose"

func main() {
  book := prose.NewBook(60)
}

The book has functions that format some text in an opinionated way:

// ...
import "github.com/fatih/color"

func main() {
  // ...
  book.Paragraph(
    "A paragraph has a new line first, then the string content, and then",
    "another trailing new line. Multiple sentences can be provided at once,",
    "and will be joined into a single text block using 1 space so you can wrap",
    "text in source code prettily")

  white := color.New(color.White).SprintFunc()
  book.Strings(
    "Formatting blocks of text using double quotes and commas can be really useful for",
    white("wrapping text elements in color formatters"),
    `
      but can be irritating when tweaking language in larger contiguous blocks
      of text due to content changing the width of the line.  Multi-line strings
      are reformatted to replace newlines and contiguous blocks of whitespace
      with a single space, and then wrapped according to the book width.
    `)
}

Built using

  • github.com/muesli/reflow/indent
  • github.com/muesli/reflow/wordwrap

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultWrapWidth = 60
)

Functions

func CollapseSpace

func CollapseSpace(s string) string

func Strings

func Strings(s ...string) string

Strings is a convenience function that trims, joins, wraps the provided strings and returns the result.

Types

type Book

type Book struct {
	wordwrap.WordWrap
}

func NewBook

func NewBook(width int) *Book

func (*Book) Example

func (b *Book) Example(foreword, code string) *Book

func (*Book) MustWrite

func (b *Book) MustWrite(byts []byte)

func (*Book) NL

func (b *Book) NL() *Book

func (*Book) Paragraph

func (b *Book) Paragraph(s ...string) *Book

func (*Book) Strings

func (b *Book) Strings(s ...string) *Book

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL