summaryrefslogtreecommitdiffstats
path: root/src/item.go
blob: c07d7fffc81d4f31ce289326c4bebb06da6b2cd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package fzf

import (
	"math"

	"github.com/junegunn/fzf/src/util"
)

// Item represents each input line. 56 bytes.
type Item struct {
	text        util.Chars    // 32 = 24 + 1 + 1 + 2 + 4
	transformed *[]Token      // 8
	origText    *[]byte       // 8
	colors      *[]ansiOffset // 8
}

// Index returns ordinal index of the Item
func (item *Item) Index() int32 {
	return item.text.Index
}

var minItem = Item{text: util.Chars{Index: math.MinInt32}}

func (item *Item) TrimLength() uint16 {
	return item.text.TrimLength()
}

// Colors returns ansiOffsets of the Item
func (item *Item) Colors() []ansiOffset {
	if item.colors == nil {
		return []ansiOffset{}
	}
	return *item.colors
}

// AsString returns the original string
func (item *Item) AsString(stripAnsi bool) string {
	if item.origText != nil {
		if stripAnsi {
			trimmed, _, _ := extractColor(string(*item.origText), nil, nil)
			return trimmed
		}
		return string(*item.origText)
	}
	return item.text.ToString()
}