multistrings

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: MIT Imports: 7 Imported by: 0

README

multistrings

What is multistrings?

multistrings is a small library to manipulate multiple strings as a whole.

Usage

import (
    "github.com/tpfeiffer67/multistrings"
)

Functions

  • New creates a MultiStrings with a given capacity.
  • NewWithGivenLen creates a MultiStrings with a given length.
  • NewFromStringSlice creates a MultiStrings from a string slice.
  • NewWithPresetContent creates a MultiStrings with a preset line count and content.
  • NewFromString creates a MultiStrings from a string.
  • WriteToFile writes the MultiStrings to a file.
  • ToString concatenates the MultiStrings into a string with a given line separator.
  • String, the Stringer interface.
  • Width returns the length of the longest string in the MultiStrings.
  • Cut truncates the MultiStrings to a given maximum width by cutting strings that exceed it.
  • Limit truncates the MultiStrings to a given maximum width by splitting strings that exceed it.
  • PadRight pads the MultiStrings on the right side of each string with a fill pattern to achieve a given width.
  • Sort sorts the MultiStrings in lexicographically increasing order.

Dependencies

The package runesstr is imported to work with Unicode characters in the strings.

Examples

Example 1

package main

import (
	"fmt"

	"github.com/tpfeiffer67/multistrings"
)

const loremipsum = `Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`

func main() {
	ms := multistrings.NewFromString(loremipsum)
	fmt.Println(ms)
}

Contributing

If you'd like to contribute to this repository, feel free to submit a pull request. Please include tests for any new functions or changes to existing functions.

License

This repository is licensed under the MIT License. See the LICENSE file for more information.

Author

Documentation

Index

Examples

Constants

View Source
const (
	AccoladesStyleCount     = 3
	AccoladesStyleMaxIndex  = int(AccoladesStyleUnicode)
	AccoladesStyleLastValue = AccoladesStyleUnicode
)
View Source
const (
	BoxStyleCount     = 21
	BoxStyleMaxIndex  = int(BoxStyleFantasy4)
	BoxStyleLastValue = BoxStyleFantasy4
)
View Source
const (
	LabelAlignCount     = 3
	LabelAlignMaxIndex  = int(LabelAlignRight)
	LabelAlignLastValue = LabelAlignRight
)
View Source
const MultiStringsMaxWidth = 1000

Variables

This section is empty.

Functions

This section is empty.

Types

type AccoladesStyle

type AccoladesStyle int
Example
for i := 0; i < 3; i++ {
	fmt.Println(AccoladesStyle(i))
}
Output:
AccoladesStyleNone
AccoladesStyleAscii
AccoladesStyleUnicode
const (
	AccoladesStyleNone AccoladesStyle = iota
	AccoladesStyleAscii
	AccoladesStyleUnicode
)

func AccoladesStyleFromString

func AccoladesStyleFromString(s string) (AccoladesStyle, error)

func (AccoladesStyle) String

func (v AccoladesStyle) String() string

type BoxPattern

type BoxPattern struct {
	TopLeftCorner     string
	TopBorder         string
	TopRightCorner    string
	LeftBorder        string
	RightBorder       string
	BottomLeftCorner  string
	BottomBorder      string
	BottomRightCorner string
}

func GetBoxPattern

func GetBoxPattern(style BoxStyle) BoxPattern

type BoxSettings

type BoxSettings struct {
	Width            int
	TopLabel         string
	TopLabelAlign    LabelAlign
	BottomLabel      string
	BottomLabelAlign LabelAlign
}

BoxSettings{30, "", Left, "", Left}

type BoxStyle

type BoxStyle int
Example
for i := 2; i <= BoxStyleMaxIndex; i++ {
	fmt.Println(NewFromString(BoxStyle(i).String()).PadRight(" ", 38).Surround(" ", " ").AutoBox(BoxSettings{40, "", LabelAlignLeft, "", LabelAlignLeft}, GetBoxPattern(BoxStyle(i))))
}
Output:
┌────────────────────────────────────────┐
│ BoxStyleSingleLine                     │
└────────────────────────────────────────┘

╭────────────────────────────────────────╮
│ BoxStyleSingleLineRounded              │
╰────────────────────────────────────────╯

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ BoxStyleBold                           ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

╒════════════════════════════════════════╕
│ BoxStyleSingleVDoubleH                 │
╘════════════════════════════════════════╛

╓────────────────────────────────────────╖
║ BoxStyleSingleHDoubleV                 ║
╙────────────────────────────────────────╜

╔════════════════════════════════════════╗
║ BoxStyleDoubleLine                     ║
╚════════════════════════════════════════╝

▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜
▌ BoxStyleExtraBold                      ▐
▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟

▞▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▚
▌ BoxStyleExtraBoldRounded               ▐
▚▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▞

█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
█ BoxStyleMaxBold                        █
█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░ BoxStyleBlocksLightShade               ░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒ BoxStyleBlocksMediumShade              ▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒

▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓ BoxStyleBlocksDarkShade                ▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

██████████████████████████████████████████
█ BoxStyleBlocks                         █
██████████████████████████████████████████

..........................................
: BoxStyleDots                           :
:........................................:

◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆
◆ BoxStyleDiamonds                       ◆
◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆

╭╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╼╮
╽ BoxStyleFantasy1                       ╿
╰╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╯

╱▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔╲
│ BoxStyleFantasy2                       │
╲▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁╱

▁▂▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▂▁
▌ BoxStyleFantasy3                       ▐
▜▃▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▂▃▛

▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂
█ BoxStyleFantasy4                       █
█▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂█
const (
	BoxStyleNone BoxStyle = iota
	BoxStyleSpaceChar
	BoxStyleSingleLine
	BoxStyleSingleLineRounded
	BoxStyleBold
	BoxStyleSingleVDoubleH
	BoxStyleSingleHDoubleV
	BoxStyleDoubleLine
	BoxStyleExtraBold
	BoxStyleExtraBoldRounded
	BoxStyleMaxBold
	BoxStyleBlocksLightShade
	BoxStyleBlocksMediumShade
	BoxStyleBlocksDarkShade
	BoxStyleBlocks
	BoxStyleDots
	BoxStyleDiamonds
	BoxStyleFantasy1
	BoxStyleFantasy2
	BoxStyleFantasy3
	BoxStyleFantasy4
)

func BoxStyleFromString

func BoxStyleFromString(s string) (BoxStyle, error)

func (BoxStyle) String

func (v BoxStyle) String() string

type LabelAlign

type LabelAlign int
const (
	LabelAlignLeft LabelAlign = iota
	LabelAlignCenter
	LabelAlignRight
)

func LabelAlignFromString

func LabelAlignFromString(s string) (LabelAlign, error)

func (LabelAlign) String

func (v LabelAlign) String() string

type MultiStrings

type MultiStrings []string

func New added in v1.0.1

func New(cap int) MultiStrings

New creates and returns a new MultiStrings slice with a given capacity. - cap is an integer representing the desired capacity of the slice.

func NewFromString added in v1.1.0

func NewFromString(s string) MultiStrings

NewFromString creates and returns a new MultiStrings slice from a string. The given string is split into separate substrings at each occurrence of a newline character. - s is a string from which to create the new MultiStrings slice.

func NewFromStringSlice added in v1.0.1

func NewFromStringSlice(s []string) (linesOut MultiStrings)

NewFromStringSlice creates and returns a new MultiStrings slice from a string slice. - s is a slice of strings from which to create the new MultiStrings slice.

func NewWithGivenLen added in v1.0.1

func NewWithGivenLen(length int) MultiStrings

NewWithGivenLen creates and returns a new MultiStrings slice with a given length. - l is the desired length of the slice.

func NewWithPresetContent added in v1.0.1

func NewWithPresetContent(line string, count int) (linesOut MultiStrings)

NewWithPresetContent creates and returns a new MultiStrings slice with a preset line count and content. - line is a string representing the content to be added to each line of the new slice. - count is the desired number of lines in the new slice.

func (MultiStrings) Accolades

func (linesIn MultiStrings) Accolades(style AccoladesStyle) (linesOut MultiStrings)
Example (StyleAscii)
lns0 := New(0)
fmt.Println(len(lns0.Accolades(AccoladesStyleAscii)))

for i := 1; i < 10; i++ {
	lns := linesSample2(i)
	fmt.Println(lns.Limit(55).PadRight(" ", 55).Accolades(AccoladesStyleAscii))
}
Output:
0
<Lorem Elsass ipsum gal non hoplageiss                  >

/Lorem Elsass ipsum gal non hoplageiss                  \
\vielmols, jetz gehts los picon bière                   /

 /Lorem Elsass ipsum gal non hoplageiss                  \
< vielmols, jetz gehts los picon bière                    >
 \tellus eget Hans quam, Christkindelsmärik auctor,      /

 /Lorem Elsass ipsum gal non hoplageiss                  \
▕ vielmols, jetz gehts los picon bière                   ▕
< tellus eget Hans quam, Christkindelsmärik auctor,       >
 \leverwurscht amet gewurztraminer nüdle quam.           /

 /Lorem Elsass ipsum gal non hoplageiss                  \
▕ vielmols, jetz gehts los picon bière                   ▕
< tellus eget Hans quam, Christkindelsmärik auctor,       >
▕ leverwurscht amet gewurztraminer nüdle quam.           ▕
 \T'inquiète, ch'ai ramené du schpeck,                   /

 /Lorem Elsass ipsum gal non hoplageiss                  \
▕ vielmols, jetz gehts los picon bière                   ▕
▕ tellus eget Hans quam, Christkindelsmärik auctor,      ▕
< leverwurscht amet gewurztraminer nüdle quam.            >
▕ T'inquiète, ch'ai ramené du schpeck,                   ▕
 \du chambon, un kuglopf et du schnaps dans mon rucksack./

 /Lorem Elsass ipsum gal non hoplageiss                  \
▕ vielmols, jetz gehts los picon bière                   ▕
▕ tellus eget Hans quam, Christkindelsmärik auctor,      ▕
▕ leverwurscht amet gewurztraminer nüdle quam.           ▕
< T'inquiète, ch'ai ramené du schpeck,                    >
▕ du chambon, un kuglopf et du schnaps dans mon rucksack.▕
▕ Allez, s'guelt ! Wotch a kofee avec ton bibalaekaess et▕
 \ta wurscht ?                                           /

 /Lorem Elsass ipsum gal non hoplageiss                  \
▕ vielmols, jetz gehts los picon bière                   ▕
▕ tellus eget Hans quam, Christkindelsmärik auctor,      ▕
▕ leverwurscht amet gewurztraminer nüdle quam.           ▕
< T'inquiète, ch'ai ramené du schpeck,                    >
▕ du chambon, un kuglopf et du schnaps dans mon rucksack.▕
▕ Allez, s'guelt ! Wotch a kofee avec ton bibalaekaess et▕
▕ ta wurscht ?                                           ▕
 \Yeuh non che suis au réchime,                          /

 /Lorem Elsass ipsum gal non hoplageiss                  \
▕ vielmols, jetz gehts los picon bière                   ▕
▕ tellus eget Hans quam, Christkindelsmärik auctor,      ▕
▕ leverwurscht amet gewurztraminer nüdle quam.           ▕
▕ T'inquiète, ch'ai ramené du schpeck,                   ▕
< du chambon, un kuglopf et du schnaps dans mon rucksack. >
▕ Allez, s'guelt ! Wotch a kofee avec ton bibalaekaess et▕
▕ ta wurscht ?                                           ▕
▕ Yeuh non che suis au réchime,                          ▕
▕ je ne mange plus que des Grumbeere light et che fais de▕
 \la chym.                                               /
Example (Styleunicode)
lns0 := New(0)
fmt.Println(len(lns0.Accolades(AccoladesStyleUnicode)))

for i := 1; i < 10; i++ {
	lns := linesSample2(i)
	fmt.Println(lns.Limit(55).PadRight(" ", 55).Accolades(AccoladesStyleUnicode))
}
Output:
0
{Lorem Elsass ipsum gal non hoplageiss                  }

⎰Lorem Elsass ipsum gal non hoplageiss                  ⎱
⎱vielmols, jetz gehts los picon bière                   ⎰

⎧Lorem Elsass ipsum gal non hoplageiss                  ⎫
⎫vielmols, jetz gehts los picon bière                   ⎧
⎩tellus eget Hans quam, Christkindelsmärik auctor,      ⎭

⎧Lorem Elsass ipsum gal non hoplageiss                  ⎫
⎭vielmols, jetz gehts los picon bière                   ⎩
⎫tellus eget Hans quam, Christkindelsmärik auctor,      ⎧
⎩leverwurscht amet gewurztraminer nüdle quam.           ⎭

⎧Lorem Elsass ipsum gal non hoplageiss                  ⎫
⎭vielmols, jetz gehts los picon bière                   ⎩
⎫tellus eget Hans quam, Christkindelsmärik auctor,      ⎧
⎪leverwurscht amet gewurztraminer nüdle quam.           ⎪
⎩T'inquiète, ch'ai ramené du schpeck,                   ⎭

⎧Lorem Elsass ipsum gal non hoplageiss                  ⎫
⎪vielmols, jetz gehts los picon bière                   ⎪
⎭tellus eget Hans quam, Christkindelsmärik auctor,      ⎩
⎫leverwurscht amet gewurztraminer nüdle quam.           ⎧
⎪T'inquiète, ch'ai ramené du schpeck,                   ⎪
⎩du chambon, un kuglopf et du schnaps dans mon rucksack.⎭

⎧Lorem Elsass ipsum gal non hoplageiss                  ⎫
⎪vielmols, jetz gehts los picon bière                   ⎪
⎪tellus eget Hans quam, Christkindelsmärik auctor,      ⎪
⎭leverwurscht amet gewurztraminer nüdle quam.           ⎩
⎫T'inquiète, ch'ai ramené du schpeck,                   ⎧
⎪du chambon, un kuglopf et du schnaps dans mon rucksack.⎪
⎪Allez, s'guelt ! Wotch a kofee avec ton bibalaekaess et⎪
⎩ta wurscht ?                                           ⎭

⎧Lorem Elsass ipsum gal non hoplageiss                  ⎫
⎪vielmols, jetz gehts los picon bière                   ⎪
⎪tellus eget Hans quam, Christkindelsmärik auctor,      ⎪
⎭leverwurscht amet gewurztraminer nüdle quam.           ⎩
⎫T'inquiète, ch'ai ramené du schpeck,                   ⎧
⎪du chambon, un kuglopf et du schnaps dans mon rucksack.⎪
⎪Allez, s'guelt ! Wotch a kofee avec ton bibalaekaess et⎪
⎪ta wurscht ?                                           ⎪
⎩Yeuh non che suis au réchime,                          ⎭

⎧Lorem Elsass ipsum gal non hoplageiss                  ⎫
⎪vielmols, jetz gehts los picon bière                   ⎪
⎪tellus eget Hans quam, Christkindelsmärik auctor,      ⎪
⎪leverwurscht amet gewurztraminer nüdle quam.           ⎪
⎭T'inquiète, ch'ai ramené du schpeck,                   ⎩
⎫du chambon, un kuglopf et du schnaps dans mon rucksack.⎧
⎪Allez, s'guelt ! Wotch a kofee avec ton bibalaekaess et⎪
⎪ta wurscht ?                                           ⎪
⎪Yeuh non che suis au réchime,                          ⎪
⎪je ne mange plus que des Grumbeere light et che fais de⎪
⎩la chym.                                               ⎭

func (MultiStrings) Append

func (linesIn MultiStrings) Append(linesToAppend MultiStrings) MultiStrings

Append appends the strings from another MultiStrings slice to the end of the current one.

Example
lns := linesSample2(2)
lns2 := linesSample2(2)
fmt.Println(lns.Append(lns2))
fmt.Println(lns.Append(lns2).AutoBox(BoxSettings{1, "", LabelAlignLeft, "", LabelAlignRight}, GetBoxPattern(BoxStyleSingleLine)))
fmt.Println(lns.Append(NewFromString("T'inquiète, ch'ai ramené du schpeck\ndu chambon et un kuglopf.")))
Output:
Lorem Elsass ipsum gal non hoplageiss
vielmols, jetz gehts los picon bière
Lorem Elsass ipsum gal non hoplageiss
vielmols, jetz gehts los picon bière

┌─────────────────────────────────────┐
│Lorem Elsass ipsum gal non hoplageiss│
│vielmols, jetz gehts los picon bière │
│Lorem Elsass ipsum gal non hoplageiss│
│vielmols, jetz gehts los picon bière │
└─────────────────────────────────────┘

Lorem Elsass ipsum gal non hoplageiss
vielmols, jetz gehts los picon bière
T'inquiète, ch'ai ramené du schpeck
du chambon et un kuglopf.

func (MultiStrings) AutoAccolades

func (linesIn MultiStrings) AutoAccolades(style AccoladesStyle) (linesOut MultiStrings)
Example
for i := 1; i < 10; i++ {
	lns := linesSample2(i)
	fmt.Println(lns.AutoAccolades(AccoladesStyleUnicode))
}
Output:
{ Lorem Elsass ipsum gal non hoplageiss }

⎰ Lorem Elsass ipsum gal non hoplageiss ⎱
⎱ vielmols, jetz gehts los picon bière  ⎰

⎧ Lorem Elsass ipsum gal non hoplageiss             ⎫
⎫ vielmols, jetz gehts los picon bière              ⎧
⎩ tellus eget Hans quam, Christkindelsmärik auctor, ⎭

⎧ Lorem Elsass ipsum gal non hoplageiss             ⎫
⎭ vielmols, jetz gehts los picon bière              ⎩
⎫ tellus eget Hans quam, Christkindelsmärik auctor, ⎧
⎩ leverwurscht amet gewurztraminer nüdle quam.      ⎭

⎧ Lorem Elsass ipsum gal non hoplageiss             ⎫
⎭ vielmols, jetz gehts los picon bière              ⎩
⎫ tellus eget Hans quam, Christkindelsmärik auctor, ⎧
⎪ leverwurscht amet gewurztraminer nüdle quam.      ⎪
⎩ T'inquiète, ch'ai ramené du schpeck,              ⎭

⎧ Lorem Elsass ipsum gal non hoplageiss                   ⎫
⎪ vielmols, jetz gehts los picon bière                    ⎪
⎭ tellus eget Hans quam, Christkindelsmärik auctor,       ⎩
⎫ leverwurscht amet gewurztraminer nüdle quam.            ⎧
⎪ T'inquiète, ch'ai ramené du schpeck,                    ⎪
⎩ du chambon, un kuglopf et du schnaps dans mon rucksack. ⎭

⎧ Lorem Elsass ipsum gal non hoplageiss                                ⎫
⎪ vielmols, jetz gehts los picon bière                                 ⎪
⎭ tellus eget Hans quam, Christkindelsmärik auctor,                    ⎩
⎫ leverwurscht amet gewurztraminer nüdle quam.                         ⎧
⎪ T'inquiète, ch'ai ramené du schpeck,                                 ⎪
⎪ du chambon, un kuglopf et du schnaps dans mon rucksack.              ⎪
⎩ Allez, s'guelt ! Wotch a kofee avec ton bibalaekaess et ta wurscht ? ⎭

⎧ Lorem Elsass ipsum gal non hoplageiss                                ⎫
⎪ vielmols, jetz gehts los picon bière                                 ⎪
⎪ tellus eget Hans quam, Christkindelsmärik auctor,                    ⎪
⎭ leverwurscht amet gewurztraminer nüdle quam.                         ⎩
⎫ T'inquiète, ch'ai ramené du schpeck,                                 ⎧
⎪ du chambon, un kuglopf et du schnaps dans mon rucksack.              ⎪
⎪ Allez, s'guelt ! Wotch a kofee avec ton bibalaekaess et ta wurscht ? ⎪
⎩ Yeuh non che suis au réchime,                                        ⎭

⎧ Lorem Elsass ipsum gal non hoplageiss                                ⎫
⎪ vielmols, jetz gehts los picon bière                                 ⎪
⎪ tellus eget Hans quam, Christkindelsmärik auctor,                    ⎪
⎭ leverwurscht amet gewurztraminer nüdle quam.                         ⎩
⎫ T'inquiète, ch'ai ramené du schpeck,                                 ⎧
⎪ du chambon, un kuglopf et du schnaps dans mon rucksack.              ⎪
⎪ Allez, s'guelt ! Wotch a kofee avec ton bibalaekaess et ta wurscht ? ⎪
⎪ Yeuh non che suis au réchime,                                        ⎪
⎩ je ne mange plus que des Grumbeere light et che fais de la chym.     ⎭

func (MultiStrings) AutoBox

func (linesIn MultiStrings) AutoBox(settings BoxSettings, pattern BoxPattern) MultiStrings
Example
lns := linesSample1()
w := 30
settings := BoxSettings{w, "Oo=-", LabelAlignLeft, "-=xX", LabelAlignRight}
fmt.Println(settings)
fmt.Println(lns.AutoBox(settings, GetBoxPattern(BoxStyleSingleLineRounded)))

lns = lns.Limit(w)
fmt.Println(lns.AutoBox(BoxSettings{w, "-=oOo=-", LabelAlignCenter, "-=xXx=-", LabelAlignCenter}, GetBoxPattern(BoxStyleDoubleLine)))

pattern := GetBoxPattern(BoxStyleFantasy4)
fmt.Println(lns.Surround(" ", " ").AutoBox(BoxSettings{w, "", LabelAlignLeft, "", LabelAlignLeft}, pattern))

fmt.Println(linesSample1().Cut(8).AutoBox(BoxSettings{w, "Title", LabelAlignLeft, "Status", LabelAlignRight}, GetBoxPattern(-4)))
fmt.Println(linesSample1().Cut(4).AutoBox(BoxSettings{w, "Title", LabelAlignLeft, "Status", LabelAlignRight}, GetBoxPattern(1000)))

settings = BoxSettings{w, "", LabelAlignLeft, "", LabelAlignLeft}
w = 10
lns = linesSample1().Cut(w)
for i := 0; i < 4; i++ {
	settings.Width = w + i*2
	lns = lns.AutoBox(settings, GetBoxPattern(BoxStyle(int(BoxStyleBlocksLightShade)+i)))
}
fmt.Println(lns)

pattern = BoxPattern{"", "", "", "", "", "", "", ""}
fmt.Println(linesSample1().AutoBox(BoxSettings{w, "", LabelAlignLeft, "", LabelAlignLeft}, pattern).Surround("[", "]"))
Output:
{30 Oo=- LabelAlignLeft -=xX LabelAlignRight}
╭Oo=-───────────────────────────────────╮
│Ceci est une  ligne relativement longue│
│Ligne courte ¨                         │
│Ceci est la troisième ligne            │
╰───────────────────────────────────-=xX╯

╔══════════-=oOo=-══════════╗
║Ceci est une  ligne        ║
║relativement longue        ║
║Ligne courte ¨             ║
║Ceci est la troisième ligne║
╚══════════-=xXx=-══════════╝

▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃
█ Ceci est une  ligne         █
█ relativement longue         █
█ Ligne courte ¨              █
█ Ceci est la troisième ligne █
█▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃▂▁▂▃█

┌Title───┐
│Ceci est│
│Ligne co│
│Ceci est│
└──Status┘

┌Titl┐
│Ceci│
│Lign│
│Ceci│
└Stat┘

██████████████████
█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█
█▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓█
█▓▒░░░░░░░░░░░░▒▓█
█▓▒░Ceci est u░▒▓█
█▓▒░Ligne cour░▒▓█
█▓▒░Ceci est l░▒▓█
█▓▒░░░░░░░░░░░░▒▓█
█▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓█
█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█
██████████████████

[Ceci est une  ligne relativement longue]
[Ligne courte ¨]
[Ceci est la troisième ligne]

func (MultiStrings) Box

func (linesIn MultiStrings) Box(settings BoxSettings, pattern BoxPattern) (linesOut MultiStrings)
Example
lns := linesSample1()
fmt.Println(lns.Box(BoxSettings{-2, "", LabelAlignLeft, "", LabelAlignLeft}, GetBoxPattern(BoxStyleSingleLine)))
fmt.Println(lns.Box(BoxSettings{1005, "", LabelAlignLeft, "", LabelAlignLeft}, GetBoxPattern(BoxStyleSingleLine)))

w := 30
settings := BoxSettings{w + 2, "-=oOo=-", LabelAlignCenter, "¨", LabelAlignCenter} // +2 because of the Surround
pattern := GetBoxPattern(BoxStyleDoubleLine)
fmt.Println(lns.Limit(w).PadRight(".", w).Surround(" ", " ").Box(settings, pattern))

lns = linesSample1()
w = 30
settings = BoxSettings{w, "▅▆▇ TITLE ▇▆▅", LabelAlignCenter, "▁▂▃▃▂▁", LabelAlignCenter}
pattern = GetBoxPattern(BoxStyleFantasy3)
fmt.Println(lns.Limit(w).PadRight(".", w).Box(settings, pattern))
Output:
Ceci est une  ligne relativement longue
Ligne courte ¨
Ceci est la troisième ligne

Ceci est une  ligne relativement longue
Ligne courte ¨
Ceci est la troisième ligne

╔═════════════-=oOo=-════════════╗
║ Ceci est une  ligne........... ║
║ relativement longue........... ║
║ Ligne courte ¨................ ║
║ Ceci est la troisième ligne... ║
╚════════════════¨═══════════════╝

▁▂▃▃▃▃▃▃▃▃▅▆▇ TITLE ▇▆▅▃▃▃▃▃▃▃▂▁
▌Ceci est une  ligne...........▐
▌relativement longue...........▐
▌Ligne courte ¨................▐
▌Ceci est la troisième ligne...▐
▜▃▂▁▁▁▁▁▁▁▁▁▁▁▂▃▃▂▁▁▁▁▁▁▁▁▁▁▁▂▃▛

func (MultiStrings) Cut

func (linesIn MultiStrings) Cut(maxWidth int) (linesOut MultiStrings)

Cut truncates the MultiStrings slice to a given maximum width by cutting strings that exceed it. - maxWidth is the maximum width to which to truncate the strings.

Example
lns := linesSample1()
fmt.Println(lns.Cut(30))

lns = linesSample1()
fmt.Println(lns.Cut(10))

lns = linesSample1()
fmt.Println(lns.Cut(50))

lns = linesSample1()
fmt.Println(lns.Cut(1))

lns = linesSample1()
fmt.Println(lns.Cut(0))

lns = linesSample1()
fmt.Println(lns.Cut(-7))

lns = NewFromString("Wie geht's les samis ? ")
fmt.Println(lns.Cut(21))
Output:
Ceci est une  ligne relativeme
Ligne courte ¨
Ceci est la troisième ligne

Ceci est u
Ligne cour
Ceci est l

Ceci est une  ligne relativement longue
Ligne courte ¨
Ceci est la troisième ligne

C
L
C

Ceci est une  ligne relativement longue
Ligne courte ¨
Ceci est la troisième ligne

Ceci est une  ligne relativement longue
Ligne courte ¨
Ceci est la troisième ligne

Wie geht's les samis

func (MultiStrings) Limit

func (linesIn MultiStrings) Limit(maxWidth int) (linesOut MultiStrings)

Limit truncates the MultiStrings slice to a given maximum width by splitting strings that exceed it. - maxWidth is the maximum width to which to truncate the strings.

Example
lns := linesSample1()
fmt.Println(lns.Limit(50))

lns = linesSample1()
fmt.Println(lns.Limit(30))

lns = linesSample1()
fmt.Println(lns.Limit(10))

lns = linesSample1()
fmt.Println(lns.Limit(3))

lns = linesSample1()
fmt.Println(lns.Limit(1))

lns = linesSample1()
fmt.Println(lns.Limit(0))

lns = linesSample1()
fmt.Println(lns.Limit(-7))
Output:
Ceci est une  ligne relativement longue
Ligne courte ¨
Ceci est la troisième ligne

Ceci est une  ligne
relativement longue
Ligne courte ¨
Ceci est la troisième ligne

Ceci est
une  ligne
relativeme
nt longue
Ligne
courte ¨
Ceci est
la
troisième
ligne

Cec
i
est
une
lig
ne
rel
ati
vem
ent
lon
gue
Lig
ne
cou
rte
¨
Cec
i
est
la
tro
isi
ème
lig
ne

C
e
c
i
e
s
t
u
n
e
l
i
g
n
e
r
e
l
a
t
i
v
e
m
e
n
t
l
o
n
g
u
e
L
i
g
n
e
c
o
u
r
t
e
¨
C
e
c
i
e
s
t
l
a
t
r
o
i
s
i
è
m
e
l
i
g
n
e

Ceci est une  ligne relativement longue
Ligne courte ¨
Ceci est la troisième ligne

Ceci est une  ligne relativement longue
Ligne courte ¨
Ceci est la troisième ligne

func (MultiStrings) Mustache

func (linesIn MultiStrings) Mustache(m map[string]interface{}) (linesOut MultiStrings, err error)

func (MultiStrings) MustacheNoErr

func (linesIn MultiStrings) MustacheNoErr(m map[string]interface{}) (linesOut MultiStrings)

func (MultiStrings) PadRight added in v1.0.1

func (linesIn MultiStrings) PadRight(fillPattern string, width int) (linesOut MultiStrings)

PadRight pads the MultiStrings slice on the right side with a given fill pattern to a given width. - fillPattern represents the pattern to use for padding. - width is the desired width of each line after padding.

func (MultiStrings) Sort

func (linesIn MultiStrings) Sort() MultiStrings

Sort sorts the MultiStrings slice in lexicographic order and returns the sorted slice.

Example
lns := linesSample2(9)
fmt.Println(lns.Sort())
Output:
Allez, s'guelt ! Wotch a kofee avec ton bibalaekaess et ta wurscht ?
Lorem Elsass ipsum gal non hoplageiss
T'inquiète, ch'ai ramené du schpeck,
Yeuh non che suis au réchime,
du chambon, un kuglopf et du schnaps dans mon rucksack.
je ne mange plus que des Grumbeere light et che fais de la chym.
leverwurscht amet gewurztraminer nüdle quam.
tellus eget Hans quam, Christkindelsmärik auctor,
vielmols, jetz gehts los picon bière

func (MultiStrings) String

func (lines MultiStrings) String() string

String implements the Stringer interface for MultiStrings.

func (MultiStrings) Surround

func (linesIn MultiStrings) Surround(left string, right string) (linesOut MultiStrings)

Surround surrounds each line of the MultiStrings slice with a given left and right string. - left is the left-side surround for each line. - right is the right-side surround.

Example
lns := linesSample1()
fmt.Println(lns.Surround("|", ""))

lns = linesSample1()
fmt.Println(lns.Surround("", "|"))

lns = linesSample1()
w := 27
fmt.Println(lns.Limit(w).PadRight(" ", w).Surround("(", ")"))
Output:
|Ceci est une  ligne relativement longue
|Ligne courte ¨
|Ceci est la troisième ligne

Ceci est une  ligne relativement longue|
Ligne courte ¨|
Ceci est la troisième ligne|

(Ceci est une  ligne        )
(relativement longue        )
(Ligne courte ¨             )
(Ceci est la troisième ligne)

func (MultiStrings) ToString

func (lines MultiStrings) ToString(linesSeparator string) (result string)

ToString concatenates the MultiStrings slice into a string with a given line separator. - linesSeparator is a string representing the separator to use between each line.

func (MultiStrings) Width

func (lines MultiStrings) Width() (width int)

Width returns the width of the MultiStrings slice, which is the length of the longest string in the slice.

func (MultiStrings) WriteToFile

func (lines MultiStrings) WriteToFile(fileName string) (err error)

WriteToFile writes the MultiStrings slice to a file with a given filename. - fileName is the name of the file to which to write the slice.

Jump to

Keyboard shortcuts

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