ansialign

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: ISC Imports: 3 Imported by: 0

README

ansi-align

Port of ansi-align


align-text with ANSI support for CLIs

Easily center- or right- align a block of text, carefully ignoring ANSI escape codes.

E.g. turn this:

Into this:

ansi text block center aligned!

Install

go get github.com/mytchmason/ansialign

API

ansiAlign(text, [opts])

Align the given text per the line with the greatest string-width, returning a new string (or array).


Arguments
Arg Type Required
text string
opts struct 🚫

Options to change behavior, see below


Options
  • opts.align: string, default 'center'

    The alignment mode. Use 'center' for center-alignment, 'right' for right-alignment, or 'left' for left-alignment. Note that the given text is assumed to be left-aligned already, so specifying align: 'left' just returns the text as is (no-op).

  • opts.split: string, default '\n'

    The separator to use when splitting the text. Only used if text is given as a string.

  • opts.pad: string, default ' '

    The value used to left-pad (prepend to) lines of lesser width. Will be repeated as necessary to adjust alignment to the line with the greatest width.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Align

func Align(text string, opts AlignOptions) string

Types

type AlignOptions

type AlignOptions struct {
	Align string
	Split string
	Pad   string
}

Jump to

Keyboard shortcuts

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