Skip to content

Commit

Permalink
don't need filter/util
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmtmmnk committed Feb 26, 2021
1 parent a7a38d0 commit 83fc35e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 54 deletions.
46 changes: 46 additions & 0 deletions filter/ripgrep.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package filter

import (
"errors"
"os/exec"
"strconv"
"strings"

"github.com/tjmtmmnk/ilse/util"
)
Expand All @@ -12,6 +15,49 @@ func newRg() *rg {
return &rg{}
}

func isValidQuery(q string) bool {
return q != ""
}

func isValidRegex(q string) bool {
return true
}

func convert(result string, option *SearchOption) ([]SearchResult, error) {
results := make([]SearchResult, 0, option.Limit)
for i, s := range strings.Split(result, "\n") {
if i > option.Limit {
break
}
res, err := split(s, option)
if err != nil {
return []SearchResult{}, err
}
if res != nil {
results = append(results, *res)
}
}
return results, nil
}

func split(str string, option *SearchOption) (*SearchResult, error) {
// first remove reset flag included in path, line
str = strings.Replace(str, "\x1b[0m", "", 4)
splitted := strings.Split(str, ":")
if len(splitted) < 3 {
return nil, nil
}

fileName := splitted[0]
lineNum, err := strconv.Atoi(splitted[1])
if err != nil {
return nil, errors.New("line number wrong format")
}
// change reset flag included in text to black foreground
text := strings.ReplaceAll(splitted[2], "\x1b[0m", "\x1b[39;40m")
return &SearchResult{fileName, lineNum, text}, nil
}

func (r *rg) Search(q string, option *SearchOption) ([]SearchResult, error) {
if !isValidQuery(q) {
return []SearchResult{}, nil
Expand Down
54 changes: 0 additions & 54 deletions filter/util.go

This file was deleted.

0 comments on commit 83fc35e

Please # to comment.