Remove special nilItem

This commit is contained in:
Junegunn Choi
2017-08-15 01:10:41 +09:00
parent 2069bbc8b5
commit 0d171ba1d8
9 changed files with 49 additions and 51 deletions

View File

@@ -85,29 +85,30 @@ func Run(opts *Options, revision string) {
var chunkList *ChunkList
header := make([]string, 0, opts.HeaderLines)
if len(opts.WithNth) == 0 {
chunkList = NewChunkList(func(data []byte, index int) Item {
chunkList = NewChunkList(func(item *Item, data []byte, index int) bool {
if len(header) < opts.HeaderLines {
header = append(header, string(data))
eventBox.Set(EvtHeader, header)
return nilItem
return false
}
chars, colors := ansiProcessor(data)
chars.Index = int32(index)
return Item{text: chars, colors: colors}
item.text, item.colors = ansiProcessor(data)
item.text.Index = int32(index)
return true
})
} else {
chunkList = NewChunkList(func(data []byte, index int) Item {
chunkList = NewChunkList(func(item *Item, data []byte, index int) bool {
tokens := Tokenize(string(data), opts.Delimiter)
trans := Transform(tokens, opts.WithNth)
transformed := joinTokens(trans)
if len(header) < opts.HeaderLines {
header = append(header, transformed)
eventBox.Set(EvtHeader, header)
return nilItem
return false
}
trimmed, colors := ansiProcessor([]byte(transformed))
trimmed.Index = int32(index)
return Item{text: trimmed, colors: colors, origText: &data}
item.text, item.colors = ansiProcessor([]byte(transformed))
item.text.Index = int32(index)
item.origText = &data
return true
})
}
@@ -151,8 +152,8 @@ func Run(opts *Options, revision string) {
slab := util.MakeSlab(slab16Size, slab32Size)
reader := Reader{
func(runes []byte) bool {
item := chunkList.trans(runes, 0)
if !item.Nil() {
item := Item{}
if chunkList.trans(&item, runes, 0) {
if result, _, _ := pattern.MatchItem(&item, false, slab); result != nil {
opts.Printer(item.text.ToString())
found = true