fzf/src/item.go

45 lines
957 B
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
)
2017-07-16 14:31:19 +00:00
// Item represents each input line. 56 bytes.
2015-01-01 19:49:30 +00:00
type Item struct {
2017-07-16 14:31:19 +00:00
text util.Chars // 32 = 24 + 1 + 1 + 2 + 4
transformed *[]Token // 8
origText *[]byte // 8
colors *[]ansiOffset // 8
}
2016-08-14 08:51:34 +00:00
// Index returns ordinal index of the Item
func (item *Item) Index() int32 {
2017-07-16 14:31:19 +00:00
return item.text.Index
}
2017-08-14 16:10:41 +00:00
var minItem = Item{text: util.Chars{Index: -1}}
2017-07-16 14:31:19 +00:00
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
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
}