2015-01-01 19:49:30 +00:00
|
|
|
package fzf
|
|
|
|
|
2015-03-18 16:59:14 +00:00
|
|
|
import (
|
2016-08-13 15:39:44 +00:00
|
|
|
"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 {
|
2016-08-18 17:39:32 +00:00
|
|
|
index int32
|
2016-08-13 15:39:44 +00:00
|
|
|
text util.Chars
|
|
|
|
origText *[]byte
|
2016-08-18 17:39:32 +00:00
|
|
|
colors *[]ansiOffset
|
2015-08-02 05:00:18 +00:00
|
|
|
transformed []Token
|
2016-01-13 12:36:44 +00:00
|
|
|
}
|
|
|
|
|
2016-08-14 08:51:34 +00:00
|
|
|
// Index returns ordinal index of the Item
|
2016-01-13 12:36:44 +00:00
|
|
|
func (item *Item) Index() int32 {
|
2016-08-18 17:39:32 +00:00
|
|
|
return item.index
|
2016-01-12 18:07:42 +00:00
|
|
|
}
|
2015-04-16 05:19:28 +00:00
|
|
|
|
2016-08-18 17:39:32 +00:00
|
|
|
// Colors returns ansiOffsets of the Item
|
|
|
|
func (item *Item) Colors() []ansiOffset {
|
|
|
|
if item.colors == nil {
|
|
|
|
return []ansiOffset{}
|
2015-01-11 14:49:12 +00:00
|
|
|
}
|
2016-08-18 17:39:32 +00:00
|
|
|
return *item.colors
|
2015-01-01 19:49:30 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 18:01:24 +00:00
|
|
|
// AsString returns the original string
|
2015-08-28 12:23:10 +00:00
|
|
|
func (item *Item) AsString(stripAnsi bool) string {
|
2015-08-02 14:54:53 +00:00
|
|
|
if item.origText != nil {
|
2015-08-28 12:23:10 +00:00
|
|
|
if stripAnsi {
|
2016-06-14 12:52:47 +00:00
|
|
|
trimmed, _, _ := extractColor(string(*item.origText), nil, nil)
|
2016-08-18 17:39:32 +00:00
|
|
|
return trimmed
|
2016-01-12 18:07:42 +00:00
|
|
|
}
|
2016-08-18 17:39:32 +00:00
|
|
|
return string(*item.origText)
|
2015-01-08 17:37:08 +00:00
|
|
|
}
|
2016-08-18 17:39:32 +00:00
|
|
|
return item.text.ToString()
|
2015-01-01 19:49:30 +00:00
|
|
|
}
|