2015-01-02 04:49:30 +09:00
|
|
|
package fzf
|
|
|
|
|
2015-03-19 01:59:14 +09:00
|
|
|
import (
|
2016-08-14 00:39:44 +09:00
|
|
|
"github.com/junegunn/fzf/src/util"
|
2015-03-19 01:59:14 +09:00
|
|
|
)
|
|
|
|
|
2017-07-16 23:31:19 +09:00
|
|
|
// Item represents each input line. 56 bytes.
|
2015-01-02 04:49:30 +09:00
|
|
|
type Item struct {
|
2017-07-16 23:31:19 +09:00
|
|
|
text util.Chars // 32 = 24 + 1 + 1 + 2 + 4
|
|
|
|
transformed *[]Token // 8
|
|
|
|
origText *[]byte // 8
|
|
|
|
colors *[]ansiOffset // 8
|
2016-01-13 21:36:44 +09:00
|
|
|
}
|
|
|
|
|
2016-08-14 17:51:34 +09:00
|
|
|
// Index returns ordinal index of the Item
|
2016-01-13 21:36:44 +09:00
|
|
|
func (item *Item) Index() int32 {
|
2017-07-16 23:31:19 +09:00
|
|
|
return item.text.Index
|
2016-01-13 03:07:42 +09:00
|
|
|
}
|
2015-04-16 14:19:28 +09:00
|
|
|
|
2017-08-15 01:10:41 +09:00
|
|
|
var minItem = Item{text: util.Chars{Index: -1}}
|
2017-07-15 12:28:29 +09:00
|
|
|
|
2017-07-16 23:31:19 +09:00
|
|
|
func (item *Item) TrimLength() uint16 {
|
|
|
|
return item.text.TrimLength()
|
2017-06-02 13:25:35 +09:00
|
|
|
}
|
|
|
|
|
2016-08-19 02:39:32 +09:00
|
|
|
// Colors returns ansiOffsets of the Item
|
|
|
|
func (item *Item) Colors() []ansiOffset {
|
|
|
|
if item.colors == nil {
|
|
|
|
return []ansiOffset{}
|
2015-01-11 23:49:12 +09:00
|
|
|
}
|
2016-08-19 02:39:32 +09:00
|
|
|
return *item.colors
|
2015-01-02 04:49:30 +09:00
|
|
|
}
|
|
|
|
|
2015-01-12 03:01:24 +09:00
|
|
|
// AsString returns the original string
|
2015-08-28 21:23:10 +09:00
|
|
|
func (item *Item) AsString(stripAnsi bool) string {
|
2015-08-02 23:54:53 +09:00
|
|
|
if item.origText != nil {
|
2015-08-28 21:23:10 +09:00
|
|
|
if stripAnsi {
|
2016-06-14 21:52:47 +09:00
|
|
|
trimmed, _, _ := extractColor(string(*item.origText), nil, nil)
|
2016-08-19 02:39:32 +09:00
|
|
|
return trimmed
|
2016-01-13 03:07:42 +09:00
|
|
|
}
|
2016-08-19 02:39:32 +09:00
|
|
|
return string(*item.origText)
|
2015-01-09 02:37:08 +09:00
|
|
|
}
|
2016-08-19 02:39:32 +09:00
|
|
|
return item.text.ToString()
|
2015-01-02 04:49:30 +09:00
|
|
|
}
|