ellipsis

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package ellipsis helps to truncate text at a specific width and adding an optional ellipsis ("…") to indicate that the text has been truncated. Use the different EllipsisType to define how and where the truncation should take place, if necessary.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Shorten

func Shorten(rs []rune, maxLength int, ellipsisType EllipsisType) []rune

func ShortenString

func ShortenString(str string, maxLength int, ellipsisType EllipsisType) string
Example
package main

import (
	"fmt"

	"github.com/inspektor-gadget/inspektor-gadget/pkg/columns/ellipsis"
)

func main() {
	fmt.Println(ellipsis.ShortenString("Foobar123", 8, ellipsis.None))
	fmt.Println(ellipsis.ShortenString("Foobar123", 8, ellipsis.Start))
	fmt.Println(ellipsis.ShortenString("Foobar123", 8, ellipsis.End))
	fmt.Println(ellipsis.ShortenString("Foobar123", 8, ellipsis.Middle))
}
Output:

Foobar12
…obar123
Foobar1…
Foob…123

Types

type EllipsisType

type EllipsisType int
const (
	None   EllipsisType = iota // None simply cuts the text if it is too long
	End                        // End cuts an overflowing string one character before reaching the maximum width and adds an ellipsis ("…").
	Start                      // Start lets the overflowing string start with an ellipsis ("…") followed by the last X characters, where X is the maximum length - 1.
	Middle                     // Middle uses the first and last characters of an overflowing string, merging them in the middle with an ellipsis ("…").
)

func (EllipsisType) String

func (et EllipsisType) String() string

Jump to

Keyboard shortcuts

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