Skip to content
Myr

item.go

This file

Path

src/item.go

59 lines · 1.4 KiB · Go

Last changed by

Not known.

History of this file

Take it

1package fzf23import (4	"math"56	"github.com/junegunn/fzf/src/util"7)89type transformed struct {10	// Because nth can be changed dynamically by change-nth action, we need to11	// keep the revision number at the time of transformation.12	revision revision13	tokens   []Token14}1516// Item represents each input line. 56 bytes.17type Item struct {18	text        util.Chars    // 32 = 24 + 1 + 1 + 2 + 419	transformed *transformed  // 820	origText    *[]byte       // 821	colors      *[]ansiOffset // 822}2324// Index returns ordinal index of the Item25func (item *Item) Index() int32 {26	return item.text.Index27}2829var minItem = Item{text: util.Chars{Index: math.MinInt32}}3031func (item *Item) TrimLength() uint16 {32	return item.text.TrimLength()33}3435// Colors returns ansiOffsets of the Item36func (item *Item) Colors() []ansiOffset {37	if item.colors == nil {38		return []ansiOffset{}39	}40	return *item.colors41}4243// AsString returns the original string44func (item *Item) AsString(stripAnsi bool) string {45	if item.origText != nil {46		if stripAnsi {47			trimmed, _, _ := extractColor(string(*item.origText), nil, nil)48			return trimmed49		}50		return string(*item.origText)51	}52	return item.text.ToString()53}5455func (item *Item) acceptNth(stripAnsi bool, delimiter Delimiter, transformer func([]Token, int32) string) string {56	tokens := Tokenize(item.AsString(stripAnsi), delimiter)57	transformed := transformer(tokens, item.Index())58	return StripLastDelimiter(transformed, delimiter)59}