Skip to content

Commit

Permalink
Merge pull request #678 from noborus/rename-func
Browse files Browse the repository at this point in the history
Rename function to reverseRange
  • Loading branch information
noborus authored Jan 4, 2025
2 parents 99d5799 + a579407 commit c8eaa44
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
github.com/ulikunitz/xz v0.5.12
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
golang.org/x/sync v0.10.0
golang.org/x/term v0.27.0
)
Expand All @@ -42,6 +41,7 @@ require (
github.com/spf13/cast v1.7.1 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20250103183323-7d7fa50e5329 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 h1:1UoZQm6f0P/ZO0w1Ri+f+ifG/gXhegadRdwBIXEFWDo=
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
golang.org/x/exp v0.0.0-20250103183323-7d7fa50e5329 h1:9kj3STMvgqy3YA4VQXBrN7925ICMxD5wzMRcgA30588=
golang.org/x/exp v0.0.0-20250103183323-7d7fa50e5329/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
29 changes: 18 additions & 11 deletions oviewer/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/gdamore/tcell/v2"
)

// defaultStyle is used when the style is not specified.
var defaultStyle = tcell.StyleDefault

// draw is the main routine that draws the screen.
Expand Down Expand Up @@ -177,7 +178,7 @@ func (root *Root) drawWrapLine(y int, lX int, lN int, lineC LineC) (int, int) {
c := lineC.lc[lX+n]
if x+c.width > root.scr.vWidth {
// Right edge.
root.clearEOL(x, y, tcell.StyleDefault)
root.clearEOL(x, y, defaultStyle)
lX += n
break
}
Expand Down Expand Up @@ -272,7 +273,7 @@ func (root *Root) clearEOL(x int, y int, style tcell.Style) {

// clearY clear the specified line.
func (root *Root) clearY(y int) {
root.clearEOL(0, y, tcell.StyleDefault)
root.clearEOL(0, y, defaultStyle)
}

// coordinatesStyle applies the style of the coordinates.
Expand Down Expand Up @@ -312,8 +313,14 @@ func (root *Root) applyMarkStyle(lN int, y int, width int) {
// applyStyleToRange applies the style from the start to the end of the physical line.
func (root *Root) applyStyleToRange(y int, s OVStyle, start int, end int) {
for x := start; x < end; x++ {
mainc, combc, style, _ := root.GetContent(x, y)
root.Screen.SetContent(x, y, mainc, combc, applyStyle(style, s))
mainc, combc, style, width := root.GetContent(x, y)
newStyle := applyStyle(style, s)
if style != newStyle {
root.Screen.SetContent(x, y, mainc, combc, newStyle)
}
if width == 2 {
x++
}
}
}

Expand Down Expand Up @@ -351,25 +358,25 @@ func (root *Root) drawSelect(x1, y1, x2, y2 int, sel bool) {
if x2 < x1 {
x1, x2 = x2, x1
}
root.reverseLine(y1, x1, x2+1, sel)
root.reverseRange(y1, x1, x2+1, sel)
return
}
if root.scr.mouseRectangle {
for y := y1; y <= y2; y++ {
root.reverseLine(y, x1, x2+1, sel)
root.reverseRange(y, x1, x2+1, sel)
}
return
}

root.reverseLine(y1, x1, root.scr.vWidth, sel)
root.reverseRange(y1, x1, root.scr.vWidth, sel)
for y := y1 + 1; y < y2; y++ {
root.reverseLine(y, 0, root.scr.vWidth, sel)
root.reverseRange(y, 0, root.scr.vWidth, sel)
}
root.reverseLine(y2, 0, x2+1, sel)
root.reverseRange(y2, 0, x2+1, sel)
}

// reverseLine reverses one line.
func (root *Root) reverseLine(y int, start int, end int, sel bool) {
// reverseRange reverses the specified range.
func (root *Root) reverseRange(y int, start int, end int, sel bool) {
if start >= end {
return
}
Expand Down
2 changes: 2 additions & 0 deletions oviewer/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func (root *Root) filter(ctx context.Context, str string) {
root.filterDocument(ctx, searcher)
}

// filterDocument filters the document by the searcher.
// It creates a new document and writes the filtered lines to it.
func (root *Root) filterDocument(ctx context.Context, searcher Searcher) {
m := root.Doc
r, w := io.Pipe()
Expand Down

0 comments on commit c8eaa44

Please sign in to comment.