Skip to content

Commit

Permalink
Merge pull request #231 from noborus/move-multicolor
Browse files Browse the repository at this point in the history
Moved multicolor settings from viewer to document
  • Loading branch information
noborus authored Dec 22, 2022
2 parents 28d168a + 4311d8a commit 7887f59
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
17 changes: 1 addition & 16 deletions oviewer/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,25 +436,10 @@ func (root *Root) setMultiColor(input string) {
return !quoted && r == ' '
})

root.setMultiColorWords(f)
root.Doc.setMultiColorWords(f)
root.setMessagef("Set multicolor strings [%s]", input)
}

// setMultiColor set multiple strings to highlight with multiple colors.
func (root *Root) setMultiColorWords(words []string) {
m := root.Doc

m.multiColorRegexps = nil
for _, w := range words {
s, err := strconv.Unquote(w)
if err != nil {
s = w
}
reg := regexpCompile(s, true)
m.multiColorRegexps = append(m.multiColorRegexps, reg)
}
}

// setJumpTarget sets the position of the search result.
func (root *Root) setJumpTarget(input string) {
num := int(math.Round(strToPosition(root.vHight, input)))
Expand Down
14 changes: 14 additions & 0 deletions oviewer/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/fs"
"os"
"regexp"
"strconv"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -332,3 +333,16 @@ func (m *Document) setSectionDelimiter(delm string) {
m.SectionDelimiter = delm
m.SectionDelimiterReg = regexpCompile(delm, true)
}

// setMultiColor set multiple strings to highlight with multiple colors.
func (m *Document) setMultiColorWords(words []string) {
m.multiColorRegexps = nil
for _, w := range words {
s, err := strconv.Unquote(w)
if err != nil {
s = w
}
reg := regexpCompile(s, true)
m.multiColorRegexps = append(m.multiColorRegexps, reg)
}
}
9 changes: 5 additions & 4 deletions oviewer/oviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,16 +557,17 @@ func (root *Root) Run() error {
root.Screen.EnableMouse(MouseFlags)
}

if root.Config.MultiColorWords != nil {
root.setMultiColorWords(root.Config.MultiColorWords)
}

root.Config.General.SectionDelimiterReg = regexpCompile(root.Config.General.SectionDelimiter, true)

root.optimizedMan()

for n, doc := range root.DocList {
doc.general = root.Config.General

if root.Config.MultiColorWords != nil {
doc.setMultiColorWords(root.Config.MultiColorWords)
}

w := ""
if doc.general.WatchInterval > 0 {
doc.watchMode()
Expand Down

0 comments on commit 7887f59

Please sign in to comment.