From 0558dfee795c297abef27a3abaa232c73d8a042d Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 16 Aug 2017 12:26:06 +0900 Subject: Remove count field from ChunkList --- src/core.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/core.go') diff --git a/src/core.go b/src/core.go index 61f14f91..6bb4b2e7 100644 --- a/src/core.go +++ b/src/core.go @@ -83,20 +83,22 @@ func Run(opts *Options, revision string) { // Chunk list var chunkList *ChunkList + var itemIndex int32 header := make([]string, 0, opts.HeaderLines) if len(opts.WithNth) == 0 { - chunkList = NewChunkList(func(item *Item, data []byte, index int) bool { + chunkList = NewChunkList(func(item *Item, data []byte) bool { if len(header) < opts.HeaderLines { header = append(header, string(data)) eventBox.Set(EvtHeader, header) return false } item.text, item.colors = ansiProcessor(data) - item.text.Index = int32(index) + item.text.Index = itemIndex + itemIndex++ return true }) } else { - chunkList = NewChunkList(func(item *Item, data []byte, index int) bool { + chunkList = NewChunkList(func(item *Item, data []byte) bool { tokens := Tokenize(string(data), opts.Delimiter) trans := Transform(tokens, opts.WithNth) transformed := joinTokens(trans) @@ -106,8 +108,9 @@ func Run(opts *Options, revision string) { return false } item.text, item.colors = ansiProcessor([]byte(transformed)) - item.text.Index = int32(index) + item.text.Index = itemIndex item.origText = &data + itemIndex++ return true }) } @@ -153,7 +156,7 @@ func Run(opts *Options, revision string) { reader := NewReader( func(runes []byte) bool { item := Item{} - if chunkList.trans(&item, runes, 0) { + if chunkList.trans(&item, runes) { if result, _, _ := pattern.MatchItem(&item, false, slab); result != nil { opts.Printer(item.text.ToString()) found = true -- cgit v1.2.3