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 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
Click to show internal directories.
Click to hide internal directories.