Release to master 2.4.0 #217
21
client.go
21
client.go
|
@ -73,7 +73,8 @@ func (c *client) Draw() {
|
||||||
screen.WriteString("\033[0m")
|
screen.WriteString("\033[0m")
|
||||||
screen.WriteString(c.TopBar.Render(c.Width, c.Options["theme"]))
|
screen.WriteString(c.TopBar.Render(c.Width, c.Options["theme"]))
|
||||||
screen.WriteString("\n")
|
screen.WriteString("\n")
|
||||||
pageContent := c.PageState.Render(c.Height, c.Width-1, (c.Options["theme"] == "color"))
|
maxWidth, _ := strconv.Atoi(c.Options["maxwidth"])
|
||||||
|
pageContent := c.PageState.Render(c.Height, c.Width-1, maxWidth, (c.Options["theme"] == "color"))
|
||||||
var re *regexp.Regexp
|
var re *regexp.Regexp
|
||||||
if c.Options["theme"] == "inverse" {
|
if c.Options["theme"] == "inverse" {
|
||||||
screen.WriteString("\033[7m")
|
screen.WriteString("\033[7m")
|
||||||
|
@ -258,7 +259,8 @@ func (c *client) TakeControlInput() {
|
||||||
}
|
}
|
||||||
err = c.NextSearchItem(0)
|
err = c.NextSearchItem(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.PageState.History[c.PageState.Position].WrapContent(c.Width-1,(c.Options["theme"] == "color"))
|
maxWidth, _ := strconv.Atoi(c.Options["maxwidth"])
|
||||||
|
c.PageState.History[c.PageState.Position].WrapContent(c.Width-1,maxWidth,(c.Options["theme"] == "color"))
|
||||||
c.Draw()
|
c.Draw()
|
||||||
}
|
}
|
||||||
case ':', ' ':
|
case ':', ' ':
|
||||||
|
@ -988,7 +990,8 @@ func (c *client) handleGopher(u Url) {
|
||||||
} else {
|
} else {
|
||||||
pg.FileType = "text"
|
pg.FileType = "text"
|
||||||
}
|
}
|
||||||
pg.WrapContent(c.Width-1, (c.Options["theme"] == "color"))
|
maxWidth, _ := strconv.Atoi(c.Options["maxwidth"])
|
||||||
|
pg.WrapContent(c.Width-1, maxWidth, (c.Options["theme"] == "color"))
|
||||||
c.PageState.Add(pg)
|
c.PageState.Add(pg)
|
||||||
c.SetPercentRead()
|
c.SetPercentRead()
|
||||||
c.ClearMessage()
|
c.ClearMessage()
|
||||||
|
@ -1015,7 +1018,8 @@ func (c *client) handleGemini(u Url) {
|
||||||
u.Mime = capsule.MimeMin
|
u.Mime = capsule.MimeMin
|
||||||
pg := MakePage(u, capsule.Content, capsule.Links)
|
pg := MakePage(u, capsule.Content, capsule.Links)
|
||||||
pg.FileType = capsule.MimeMaj
|
pg.FileType = capsule.MimeMaj
|
||||||
pg.WrapContent(c.Width-1, (c.Options["theme"] == "color"))
|
maxWidth, _ := strconv.Atoi(c.Options["maxwidth"])
|
||||||
|
pg.WrapContent(c.Width-1, maxWidth, (c.Options["theme"] == "color"))
|
||||||
c.PageState.Add(pg)
|
c.PageState.Add(pg)
|
||||||
c.SetPercentRead()
|
c.SetPercentRead()
|
||||||
c.ClearMessage()
|
c.ClearMessage()
|
||||||
|
@ -1081,7 +1085,8 @@ func (c *client) handleLocal(u Url) {
|
||||||
if ext == ".jpg" || ext == ".jpeg" || ext == ".gif" || ext == ".png" {
|
if ext == ".jpg" || ext == ".jpeg" || ext == ".gif" || ext == ".png" {
|
||||||
pg.FileType = "image"
|
pg.FileType = "image"
|
||||||
}
|
}
|
||||||
pg.WrapContent(c.Width-1, (c.Options["theme"] == "color"))
|
maxWidth, _ := strconv.Atoi(c.Options["maxwidth"])
|
||||||
|
pg.WrapContent(c.Width-1, maxWidth, (c.Options["theme"] == "color"))
|
||||||
c.PageState.Add(pg)
|
c.PageState.Add(pg)
|
||||||
c.SetPercentRead()
|
c.SetPercentRead()
|
||||||
c.ClearMessage()
|
c.ClearMessage()
|
||||||
|
@ -1097,7 +1102,8 @@ func (c *client) handleFinger(u Url) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pg := MakePage(u, content, []string{})
|
pg := MakePage(u, content, []string{})
|
||||||
pg.WrapContent(c.Width-1, (c.Options["theme"] == "color"))
|
maxWidth, _ := strconv.Atoi(c.Options["maxwidth"])
|
||||||
|
pg.WrapContent(c.Width-1, maxWidth, (c.Options["theme"] == "color"))
|
||||||
c.PageState.Add(pg)
|
c.PageState.Add(pg)
|
||||||
c.SetPercentRead()
|
c.SetPercentRead()
|
||||||
c.ClearMessage()
|
c.ClearMessage()
|
||||||
|
@ -1117,7 +1123,8 @@ func (c *client) handleWeb(u Url) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pg := MakePage(u, page.Content, page.Links)
|
pg := MakePage(u, page.Content, page.Links)
|
||||||
pg.WrapContent(c.Width-1, (c.Options["theme"] == "color"))
|
maxWidth, _ := strconv.Atoi(c.Options["maxwidth"])
|
||||||
|
pg.WrapContent(c.Width-1, maxWidth, (c.Options["theme"] == "color"))
|
||||||
c.PageState.Add(pg)
|
c.PageState.Add(pg)
|
||||||
c.SetPercentRead()
|
c.SetPercentRead()
|
||||||
c.ClearMessage()
|
c.ClearMessage()
|
||||||
|
|
|
@ -56,6 +56,7 @@ var defaultOptions = map[string]string{
|
||||||
"theme": "normal", // "normal", "inverted", "color"
|
"theme": "normal", // "normal", "inverted", "color"
|
||||||
"timeout": "15", // connection timeout for gopher/gemini in seconds
|
"timeout": "15", // connection timeout for gopher/gemini in seconds
|
||||||
"webmode": "none", // "none", "gui", "lynx", "w3m", "elinks"
|
"webmode": "none", // "none", "gui", "lynx", "w3m", "elinks"
|
||||||
|
"maxwidth": "100",
|
||||||
}
|
}
|
||||||
|
|
||||||
// homePath will return the path to your home directory as a string
|
// homePath will return the path to your home directory as a string
|
||||||
|
|
7
page.go
7
page.go
|
@ -65,12 +65,15 @@ func (p *Page) RenderImage(width int) {
|
||||||
// width and updates the WrappedContent
|
// width and updates the WrappedContent
|
||||||
// of the Page struct width a string slice
|
// of the Page struct width a string slice
|
||||||
// of the wrapped data
|
// of the wrapped data
|
||||||
func (p *Page) WrapContent(width int, color bool) {
|
func (p *Page) WrapContent(width, maxWidth int, color bool) {
|
||||||
if p.FileType == "image" {
|
if p.FileType == "image" {
|
||||||
p.RenderImage(width)
|
p.RenderImage(width)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
width = min(width, 100)
|
if maxWidth < 100 {
|
||||||
|
maxWidth = 100
|
||||||
|
}
|
||||||
|
width = min(width, maxWidth)
|
||||||
counter := 0
|
counter := 0
|
||||||
spacer := ""
|
spacer := ""
|
||||||
var content strings.Builder
|
var content strings.Builder
|
||||||
|
|
10
page_test.go
10
page_test.go
|
@ -20,8 +20,9 @@ func Test_WrapContent_Wrapped_Line_Length(t *testing.T) {
|
||||||
Color bool
|
Color bool
|
||||||
}
|
}
|
||||||
type args struct {
|
type args struct {
|
||||||
width int
|
width int
|
||||||
color bool
|
maxWidth int
|
||||||
|
color bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a Url for use by the MakePage function
|
// create a Url for use by the MakePage function
|
||||||
|
@ -41,6 +42,7 @@ func Test_WrapContent_Wrapped_Line_Length(t *testing.T) {
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
args{
|
args{
|
||||||
|
10,
|
||||||
10,
|
10,
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -57,6 +59,7 @@ func Test_WrapContent_Wrapped_Line_Length(t *testing.T) {
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
args{
|
args{
|
||||||
|
10,
|
||||||
10,
|
10,
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -77,6 +80,7 @@ func Test_WrapContent_Wrapped_Line_Length(t *testing.T) {
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
args{
|
args{
|
||||||
|
10,
|
||||||
10,
|
10,
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -85,7 +89,7 @@ func Test_WrapContent_Wrapped_Line_Length(t *testing.T) {
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
p := MakePage(url, tt.input, []string{""})
|
p := MakePage(url, tt.input, []string{""})
|
||||||
p.WrapContent(tt.args.width-1, tt.args.color)
|
p.WrapContent(tt.args.width-1, tt.args.maxWidth, tt.args.color)
|
||||||
if !reflect.DeepEqual(p.WrappedContent, tt.expects) {
|
if !reflect.DeepEqual(p.WrappedContent, tt.expects) {
|
||||||
t.Errorf("Test failed - %s\nexpects %s\nactual %s", tt.name, tt.expects, p.WrappedContent)
|
t.Errorf("Test failed - %s\nexpects %s\nactual %s", tt.name, tt.expects, p.WrappedContent)
|
||||||
}
|
}
|
||||||
|
|
4
pages.go
4
pages.go
|
@ -60,7 +60,7 @@ func (p *Pages) Add(pg Page) {
|
||||||
|
|
||||||
// Render wraps the content for the current page and returns
|
// Render wraps the content for the current page and returns
|
||||||
// the page content as a string slice
|
// the page content as a string slice
|
||||||
func (p *Pages) Render(termHeight, termWidth int, color bool) []string {
|
func (p *Pages) Render(termHeight, termWidth, maxWidth int, color bool) []string {
|
||||||
if p.Length < 1 {
|
if p.Length < 1 {
|
||||||
return make([]string, 0)
|
return make([]string, 0)
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func (p *Pages) Render(termHeight, termWidth int, color bool) []string {
|
||||||
prev := len(p.History[p.Position].WrappedContent)
|
prev := len(p.History[p.Position].WrappedContent)
|
||||||
|
|
||||||
if termWidth != p.History[p.Position].WrapWidth || p.History[p.Position].Color != color {
|
if termWidth != p.History[p.Position].WrapWidth || p.History[p.Position].Color != color {
|
||||||
p.History[p.Position].WrapContent(termWidth, color)
|
p.History[p.Position].WrapContent(termWidth, maxWidth, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
now := len(p.History[p.Position].WrappedContent)
|
now := len(p.History[p.Position].WrappedContent)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user