Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor drawline function to improve readability #670

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions oviewer/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,45 +164,51 @@ func (root *Root) drawWrapLine(y int, lX int, lN int, lineC LineC) (int, int) {
return 0, 0
}

for x := 0; ; x++ {
if lX+x >= len(lineC.lc) {
screen := root.Screen
for n := 0; ; n++ {
x := root.scr.startX + n
if lX+n >= len(lineC.lc) {
// EOL
root.clearEOL(root.scr.startX+x, y, lineC.eolStyle)
root.clearEOL(x, y, lineC.eolStyle)
lX = 0
lN++
break
}
content := lineC.lc[lX+x]
if x+root.scr.startX+content.width > root.scr.vWidth {
c := lineC.lc[lX+n]
if x+c.width > root.scr.vWidth {
// Right edge.
root.clearEOL(root.scr.startX+x, y, tcell.StyleDefault)
lX += x
root.clearEOL(x, y, tcell.StyleDefault)
lX += n
break
}
root.Screen.SetContent(root.scr.startX+x, y, content.mainc, content.combc, content.style)
screen.SetContent(x, y, c.mainc, c.combc, c.style)
}

return lX, lN
}

// drawNoWrapLine draws contents without wrapping and returns the next drawing position.
func (root *Root) drawNoWrapLine(y int, startX int, lN int, lineC LineC) (int, int) {
startX = max(startX, root.minStartX)
for x := 0; root.scr.startX+x < root.scr.vWidth; x++ {
if startX+x >= len(lineC.lc) {
func (root *Root) drawNoWrapLine(y int, lX int, lN int, lineC LineC) (int, int) {
lX = max(lX, root.minStartX)
screen := root.Screen
for n := 0; root.scr.startX+n < root.scr.vWidth; n++ {
x := root.scr.startX + n
if lX+n >= len(lineC.lc) {
// EOL
root.clearEOL(root.scr.startX+x, y, lineC.eolStyle)
root.clearEOL(x, y, lineC.eolStyle)
break
}
c := DefaultContent
if startX+x >= 0 {
c = lineC.lc[startX+x]
if lX+n < 0 {
c := DefaultContent
screen.SetContent(x, y, c.mainc, c.combc, c.style)
continue
}
root.Screen.SetContent(root.scr.startX+x, y, c.mainc, c.combc, c.style)
c := lineC.lc[lX+n]
screen.SetContent(x, y, c.mainc, c.combc, c.style)
}
lN++

return startX, lN
return lX, lN
}

// blankLineNumber should be blank for the line number.
Expand Down
Loading