mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 13:19:02 +08:00
Fix the bug that the output format is different from the original version.
This commit is contained in:
parent
36025d8f01
commit
05d918528f
@ -75,14 +75,14 @@ Find document on: https://github.com/zu1k/nali
|
||||
return
|
||||
}
|
||||
if isJson {
|
||||
_, _ = fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(line).Json())
|
||||
_, _ = fmt.Fprintf(color.Output, "%s", entity.ParseLine(line).Json())
|
||||
} else {
|
||||
_, _ = fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(line).ColorString())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if isJson {
|
||||
_, _ = fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(strings.Join(args, " ")).Json())
|
||||
_, _ = fmt.Fprintf(color.Output, "%s", entity.ParseLine(strings.Join(args, " ")).Json())
|
||||
} else {
|
||||
_, _ = fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(strings.Join(args, " ")).ColorString())
|
||||
}
|
||||
|
@ -90,7 +90,10 @@ func (es Entities) ColorString() string {
|
||||
func (es Entities) Json() string {
|
||||
var s strings.Builder
|
||||
for _, e := range es {
|
||||
if e.Type == TypePlain {
|
||||
continue
|
||||
}
|
||||
s.WriteString(e.Json() + "\n")
|
||||
}
|
||||
return strings.TrimSpace(s.String())
|
||||
return s.String()
|
||||
}
|
||||
|
@ -48,6 +48,13 @@ func ParseLine(line string) Entities {
|
||||
for _, e := range tmp {
|
||||
start := e.Loc[0]
|
||||
if start >= idx {
|
||||
if start > idx {
|
||||
es = append(es, &Entity{
|
||||
Loc: [2]int{idx, start},
|
||||
Type: TypePlain,
|
||||
Text: line[idx:start],
|
||||
})
|
||||
}
|
||||
res := db.Find(dbif.QueryType(e.Type), e.Text)
|
||||
if res != nil {
|
||||
e.InfoText = res.String()
|
||||
@ -57,6 +64,12 @@ func ParseLine(line string) Entities {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if total := len(line); idx < total {
|
||||
es = append(es, &Entity{
|
||||
Loc: [2]int{idx, total},
|
||||
Type: TypePlain,
|
||||
Text: line[idx:total],
|
||||
})
|
||||
}
|
||||
return es
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user