summaryrefslogtreecommitdiff
path: root/src/core.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/core.go')
-rw-r--r--src/core.go42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/core.go b/src/core.go
index ec4c5e8d..62190d08 100644
--- a/src/core.go
+++ b/src/core.go
@@ -85,8 +85,11 @@ func Run(options *Options) {
}
// Reader
- reader := Reader{func(str string) { chunkList.Push(str) }, eventBox}
- go reader.ReadSource()
+ streamingFilter := opts.Filter != nil && opts.Sort == 0 && !opts.Tac && !opts.Sync
+ if !streamingFilter {
+ reader := Reader{func(str string) { chunkList.Push(str) }, eventBox}
+ go reader.ReadSource()
+ }
// Matcher
patternBuilder := func(runes []rune) *Pattern {
@@ -97,21 +100,32 @@ func Run(options *Options) {
// Filtering mode
if opts.Filter != nil {
- pattern := patternBuilder([]rune(*opts.Filter))
-
- eventBox.Unwatch(EvtReadNew)
- eventBox.WaitFor(EvtReadFin)
-
- snapshot, _ := chunkList.Snapshot()
- merger, _ := matcher.scan(MatchRequest{
- chunks: snapshot,
- pattern: pattern})
-
if opts.PrintQuery {
fmt.Println(*opts.Filter)
}
- for i := 0; i < merger.Length(); i++ {
- fmt.Println(merger.Get(i).AsString())
+
+ pattern := patternBuilder([]rune(*opts.Filter))
+
+ if streamingFilter {
+ reader := Reader{
+ func(str string) {
+ item := chunkList.trans(&str, 0)
+ if pattern.MatchItem(item) {
+ fmt.Println(*item.text)
+ }
+ }, eventBox}
+ reader.ReadSource()
+ } else {
+ eventBox.Unwatch(EvtReadNew)
+ eventBox.WaitFor(EvtReadFin)
+
+ snapshot, _ := chunkList.Snapshot()
+ merger, _ := matcher.scan(MatchRequest{
+ chunks: snapshot,
+ pattern: pattern})
+ for i := 0; i < merger.Length(); i++ {
+ fmt.Println(merger.Get(i).AsString())
+ }
}
os.Exit(0)
}