summaryrefslogtreecommitdiffstats
path: root/src/core.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-08-15 01:10:41 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-08-15 01:10:41 +0900
commit0d171ba1d81886c6f9caf61867129e6daa268cd6 (patch)
treee82b6b40439ff4f6fc936f31e65790d976ccddb6 /src/core.go
parent2069bbc8b54fa77384e42274ee15af7b397af884 (diff)
Remove special nilItem
Diffstat (limited to 'src/core.go')
-rw-r--r--src/core.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/core.go b/src/core.go
index 0b90a51b..968d407b 100644
--- a/src/core.go
+++ b/src/core.go
@@ -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