text

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: BSD-2-Clause Imports: 5 Imported by: 2

README

PACKAGE STYLE

GoDoc  Go Report Card 

text provides text manipulation functions (like indentation, wrapping, columnize,...) that can differentiate printable from non-printable sequences (like ANSI colored sequences).

text provides helpers to format tables and to print diff between text.

EXAMPLE

package main

import (
    "fmt"

    "github.com/pirmd/text"
    "github.com/pirmd/text/ansi"
)

func Example() {
    tab := text.NewTable().SetMaxWidth(80).SetGrid(" ", "-", " ")

     tab.Rows(
         []string{"Column1", "Column2", "Column3"},
         []string{"Basic column", "This one is here\nto demonstrate\nthat colums with several lines work too", "Any " + ansi.SetBold("formatted") + " string can be inserted too without beaking the table."},
         []string{"", "This second row is here to test multi-lines rows format", "Also possibly a second chance to verify that multi-lines is working"},
     )

     fmt.Println(tab.Draw())
}

INSTALLATION

Everything should work fine using go standard commands (build, get, install...).

USAGE

Running go doc github.com/pirmd/text should give you helpful guidelines on available features.

CONTRIBUTION

If you feel like to contribute, just follow github guidelines on forking then send a pull request

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Center added in v0.6.0

func Center(s string, sz int) string

Center centers text and pads it with spaces to reach the given "visual" length.

func Columnize added in v0.4.0

func Columnize(columns ...string) string

Columnize organizes supplied strings in a side-by-side fashion.

func Indent

func Indent(s string, tag, prefix string) string

Indent inserts a name/bullet/number at the beginning of the string, then indents it (add prefix at the beginning and before any new line).

Tag is superposed to the indent prefix to obtain the first line prefix, if tag length is greater than prefix, prefix is completed by trailing spaces.

func Justify

func Justify(s string, sz int) string

Justify wraps a text to the given maximum size and makes sure that returned lines are of exact provided size by wrapping and padding them as needed.

func LazyTab added in v0.6.2

func LazyTab(s string, tag, prefix string, sz int) string

LazyTab wraps and indents the given text.

LazyTab operates like Tab but relies on LazyWrap and does not split long words to fit the provided "visual" limit.

func LazyWrap added in v0.6.1

func LazyWrap(s string, sz int) string

LazyWrap wraps a text by ensuring that each of its line's "visual" length is lower or equal to the provided limit. Wrap works with word limits being spaces.

If a "word" is encountered that is longer than the limit, it is not split in chunks of 'limit' length and is kept as is.

func Left added in v0.6.0

func Left(s string, sz int) string

Left aligns text on the left and pads it with spaces to reach the given "visual" length.

func Right(s string, sz int) string

Right aligns text on the right and pads it with spaces to reach the given "visual" length.

func Rowwise added in v0.6.0

func Rowwise(rows ...string) string

Rowwise organizes supplied strings in a table-like fashion. Each string is displayed as a table row, each '\t' delimiting a column.

func Tab

func Tab(s string, tag, prefix string, sz int) string

Tab wraps and indents the given text.

Tab will additionally add the given tag in front of the first line. Tag is superposed to the indent prefix to obtain the first line prefix, if tag's length is greater than prefix, prefix is completed by trailing spaces.

Tab calculates the correct wrapping limits taking indent's prefix length. It does not work if prefix is made of tabs as indent's tag/prefix length is unknown (like '\t').

func Tabulate added in v0.6.0

func Tabulate(tabbedtext string) string

Tabulate organizes supplied string in a table-like fashion. Each '\t\n' delimiting a table's row and each '\t' a column.

func Wrap

func Wrap(s string, sz int) string

Wrap wraps a text by ensuring that each of its line's "visual" length is lower or equal to the provided limit. Wrap works with word limits being spaces.

If a "word" is encountered that is longer than the limit, it is split in chunks of 'limit' length.

Types

This section is empty.

Directories

Path Synopsis
Package diff proposes a set of functions to compute differences between two strings.
Package diff proposes a set of functions to compute differences between two strings.

Jump to

Keyboard shortcuts

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