fzf/src/item.go

55 lines
1.0 KiB
Go
Raw Normal View History

2015-01-01 19:49:30 +00:00
package fzf
2015-03-18 16:59:14 +00:00
import (
"github.com/junegunn/fzf/src/util"
2015-03-18 16:59:14 +00:00
)
2015-01-11 18:01:24 +00:00
// Item represents each input line
2015-01-01 19:49:30 +00:00
type Item struct {
index int32
trimLength int32
text util.Chars
origText *[]byte
colors *[]ansiOffset
transformed []Token
}
2016-08-14 08:51:34 +00:00
// Index returns ordinal index of the Item
func (item *Item) Index() int32 {
return item.index
}
var nilItem = Item{index: -1}
func (item *Item) Nil() bool {
return item.index < 0
}
func (item *Item) TrimLength() int32 {
if item.trimLength >= 0 {
return item.trimLength
}
item.trimLength = int32(item.text.TrimLength())
return item.trimLength
}
// Colors returns ansiOffsets of the Item
func (item *Item) Colors() []ansiOffset {
if item.colors == nil {
return []ansiOffset{}
}
return *item.colors
2015-01-01 19:49:30 +00:00
}
2015-01-11 18:01:24 +00:00
// AsString returns the original string
func (item *Item) AsString(stripAnsi bool) string {
2015-08-02 14:54:53 +00:00
if item.origText != nil {
if stripAnsi {
trimmed, _, _ := extractColor(string(*item.origText), nil, nil)
return trimmed
}
return string(*item.origText)
2015-01-08 17:37:08 +00:00
}
return item.text.ToString()
2015-01-01 19:49:30 +00:00
}