From 84e2262ad63df2112f16b2a80fc661294c3da45e Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 12 Feb 2025 20:15:04 +0900 Subject: Make --accept-nth and --with-nth support templates --- src/core.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/core.go') diff --git a/src/core.go b/src/core.go index 08d9e868..939910b3 100644 --- a/src/core.go +++ b/src/core.go @@ -96,7 +96,7 @@ func Run(opts *Options) (int, error) { var chunkList *ChunkList var itemIndex int32 header := make([]string, 0, opts.HeaderLines) - if len(opts.WithNth) == 0 { + if opts.WithNth == nil { chunkList = NewChunkList(cache, func(item *Item, data []byte) bool { if len(header) < opts.HeaderLines { header = append(header, byteString(data)) @@ -109,6 +109,7 @@ func Run(opts *Options) (int, error) { return true }) } else { + nthTransformer := opts.WithNth(opts.Delimiter) chunkList = NewChunkList(cache, func(item *Item, data []byte) bool { tokens := Tokenize(byteString(data), opts.Delimiter) if opts.Ansi && opts.Theme.Colored && len(tokens) > 1 { @@ -127,15 +128,13 @@ func Run(opts *Options) (int, error) { } } } - trans := Transform(tokens, opts.WithNth) - transformed := JoinTokens(trans) + transformed := nthTransformer(tokens) if len(header) < opts.HeaderLines { header = append(header, transformed) eventBox.Set(EvtHeader, header) return false } item.text, item.colors = ansiProcessor(stringBytes(transformed)) - item.text.TrimTrailingWhitespaces() item.text.Index = itemIndex item.origText = &data itemIndex++ -- cgit v1.2.3