From 980f236d84c8a6b23a7204578c0e6527bcfed7e3 Mon Sep 17 00:00:00 2001 From: asdf Date: Sun, 21 Jun 2020 14:24:12 +1000 Subject: [PATCH 1/3] Corrects wrapped lines to ensure they fit the required terminal width --- page.go | 1 + 1 file changed, 1 insertion(+) diff --git a/page.go b/page.go index 6973a7c..ad44ab2 100644 --- a/page.go +++ b/page.go @@ -130,6 +130,7 @@ func (p *Page) WrapContent(width int, color bool) { counter += len(spacer) } content.WriteRune(ch) + counter++ } } } From 57b3afd4d79a31dfa1e14fceb0f48fba2de65782 Mon Sep 17 00:00:00 2001 From: asdf Date: Sun, 21 Jun 2020 14:58:51 +1000 Subject: [PATCH 2/3] Add supporting unit tests for WrapContent --- page_test.go | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 page_test.go diff --git a/page_test.go b/page_test.go new file mode 100644 index 0000000..ef41a80 --- /dev/null +++ b/page_test.go @@ -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) + } + }) + } +} From d2c8af2a0809b35334a5d1a0a91af4b4669a9b32 Mon Sep 17 00:00:00 2001 From: asdf Date: Tue, 23 Jun 2020 14:56:10 +1000 Subject: [PATCH 3/3] Page content now renders to the entire terminal width --- client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.go b/client.go index 25d7723..c84757a 100644 --- a/client.go +++ b/client.go @@ -122,8 +122,8 @@ func (c *client) Draw() { } else { for i := 0; i < c.Height-3; i++ { if i < len(pageContent) { - screen.WriteString(pageContent[i]) screen.WriteString("\033[0K") + screen.WriteString(pageContent[i]) screen.WriteString("\n") } else { screen.WriteString("\033[0K")