Add --print0 option

Related: #660
This commit is contained in:
Junegunn Choi
2016-09-18 04:52:47 +09:00
parent 401a5fd5ff
commit 37f43fbb35
5 changed files with 27 additions and 11 deletions

View File

@@ -151,7 +151,7 @@ func Run(opts *Options) {
// Filtering mode
if opts.Filter != nil {
if opts.PrintQuery {
fmt.Println(*opts.Filter)
opts.Printer(*opts.Filter)
}
pattern := patternBuilder([]rune(*opts.Filter))
@@ -164,7 +164,7 @@ func Run(opts *Options) {
item := chunkList.trans(runes, 0)
if item != nil {
if result, _, _ := pattern.MatchItem(item, false, slab); result != nil {
fmt.Println(item.text.ToString())
opts.Printer(item.text.ToString())
found = true
}
}
@@ -180,7 +180,7 @@ func Run(opts *Options) {
chunks: snapshot,
pattern: pattern})
for i := 0; i < merger.Length(); i++ {
fmt.Println(merger.Get(i).item.AsString(opts.Ansi))
opts.Printer(merger.Get(i).item.AsString(opts.Ansi))
found = true
}
}
@@ -254,13 +254,13 @@ func Run(opts *Options) {
} else if val.final {
if opts.Exit0 && count == 0 || opts.Select1 && count == 1 {
if opts.PrintQuery {
fmt.Println(opts.Query)
opts.Printer(opts.Query)
}
if len(opts.Expect) > 0 {
fmt.Println()
opts.Printer("")
}
for i := 0; i < count; i++ {
fmt.Println(val.Get(i).item.AsString(opts.Ansi))
opts.Printer(val.Get(i).item.AsString(opts.Ansi))
}
if count > 0 {
os.Exit(exitOk)