Merge pull request 'Line wrap correction' (#179) from line-wrap-correction into release2.3.2
This is approved/merging in now :) For historical conversation on this PR please see: #175
This commit is contained in:
commit
6b2ccc5ad4
|
@ -122,8 +122,8 @@ func (c *client) Draw() {
|
||||||
} else {
|
} else {
|
||||||
for i := 0; i < c.Height-3; i++ {
|
for i := 0; i < c.Height-3; i++ {
|
||||||
if i < len(pageContent) {
|
if i < len(pageContent) {
|
||||||
screen.WriteString(pageContent[i])
|
|
||||||
screen.WriteString("\033[0K")
|
screen.WriteString("\033[0K")
|
||||||
|
screen.WriteString(pageContent[i])
|
||||||
screen.WriteString("\n")
|
screen.WriteString("\n")
|
||||||
} else {
|
} else {
|
||||||
screen.WriteString("\033[0K")
|
screen.WriteString("\033[0K")
|
||||||
|
|
1
page.go
1
page.go
|
@ -130,6 +130,7 @@ func (p *Page) WrapContent(width int, color bool) {
|
||||||
counter += len(spacer)
|
counter += len(spacer)
|
||||||
}
|
}
|
||||||
content.WriteRune(ch)
|
content.WriteRune(ch)
|
||||||
|
counter++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_WrapContent_Wrapped_Line_Length(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
WrappedContent []string
|
||||||
|
RawContent string
|
||||||
|
Links []string
|
||||||
|
Location Url
|
||||||
|
ScrollPosition int
|
||||||
|
FoundLinkLines []int
|
||||||
|
SearchTerm string
|
||||||
|
SearchIndex int
|
||||||
|
FileType string
|
||||||
|
WrapWidth int
|
||||||
|
Color bool
|
||||||
|
}
|
||||||
|
type args struct {
|
||||||
|
width int
|
||||||
|
color bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a Url for use by the MakePage function
|
||||||
|
url, _ := MakeUrl("gemini://rawtext.club")
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
input string
|
||||||
|
expects []string
|
||||||
|
args args
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"Short line that doesn't wrap",
|
||||||
|
"0123456789\n",
|
||||||
|
[]string{
|
||||||
|
"0123456789",
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
args{
|
||||||
|
10,
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Long line wrapped to 10 columns",
|
||||||
|
"0123456789 123456789 123456789 123456789 123456789\n",
|
||||||
|
[]string{
|
||||||
|
"0123456789",
|
||||||
|
" 123456789",
|
||||||
|
" 123456789",
|
||||||
|
" 123456789",
|
||||||
|
" 123456789",
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
args{
|
||||||
|
10,
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
p := MakePage(url, tt.input, []string{""})
|
||||||
|
p.WrapContent(tt.args.width-1, tt.args.color)
|
||||||
|
if !reflect.DeepEqual(p.WrappedContent, tt.expects) {
|
||||||
|
t.Errorf("Test failed - %s\nexpects %s\nactual %s", tt.name, tt.expects, p.WrappedContent)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue