From 4e27c4406122eb1eee359641d65776efd2574002 Mon Sep 17 00:00:00 2001 From: Brian Evans Date: Tue, 28 May 2019 14:23:35 -0700 Subject: [PATCH 1/3] Rough changes to allow for full scroll on resize to small screen. Needs review. --- cui/screen.go | 24 ++----------------- cui/window.go | 65 ++++++++++++++++++++++++++------------------------- main.go | 20 ++++++++++++++++ 3 files changed, 55 insertions(+), 54 deletions(-) diff --git a/cui/screen.go b/cui/screen.go index 7b3cdd4..f79df2d 100644 --- a/cui/screen.go +++ b/cui/screen.go @@ -26,7 +26,7 @@ type Screen struct { // AddWindow adds a new window to the Screen struct in question func (s *Screen) AddWindow(r1, c1, r2, c2 int, scroll, border, show bool) { - w := Window{box{r1, c1, r2, c2}, scroll, 0, []string{}, border, false, show} + w := Window{box{r1, c1, r2, c2}, scroll, 0, []string{}, border, false, show, 1} s.Windows = append(s.Windows, &w) } @@ -61,27 +61,7 @@ func (s Screen) Clear() { // to redraw the full screen or just the content. On a resize // event, the full screen will always be redrawn. func (s *Screen) ReflashScreen(clearScreen bool) { - oldh, oldw := s.Height, s.Width - s.GetSize() - if s.Height != oldh || s.Width != oldw { - // TODO this should be pure library code and not rely on - // specific windows being present with specific behaviors. - // Maybe allow windows to have a resize function that can - // be declared within the application? - // For now this will be ok though. - s.Windows[0].Box.row2 = s.Height - 2 - s.Windows[0].Box.col2 = s.Width - bookmarksWidth := 40 - if s.Width < 40 { - bookmarksWidth = s.Width - } - s.Windows[1].Box.row2 = s.Height - 2 - s.Windows[1].Box.col1 = s.Width - bookmarksWidth - s.Windows[1].Box.col2 = s.Width - - s.DrawAllWindows() - s.DrawMsgBars() - } else if clearScreen { + if clearScreen { s.DrawAllWindows() s.DrawMsgBars() } else { diff --git a/cui/window.go b/cui/window.go index 067e306..fe82cd5 100644 --- a/cui/window.go +++ b/cui/window.go @@ -6,10 +6,10 @@ import ( ) type box struct { - row1 int - col1 int - row2 int - col2 int + Row1 int + Col1 int + Row2 int + Col2 int } // TODO add coloring @@ -21,6 +21,7 @@ type Window struct { drawBox bool Active bool Show bool + tempContentLen int } func (w *Window) DrawWindow() { @@ -36,18 +37,18 @@ func (w *Window) DrawBox() { if w.Active { lead = "a" } - moveThenDrawShape(w.Box.row1, w.Box.col1, lead+"tl") - moveThenDrawShape(w.Box.row1, w.Box.col2, lead+"tr") - moveThenDrawShape(w.Box.row2, w.Box.col1, lead+"bl") - moveThenDrawShape(w.Box.row2, w.Box.col2, lead+"br") - for i := w.Box.col1 + 1; i < w.Box.col2; i++ { - moveThenDrawShape(w.Box.row1, i, lead+"ceiling") - moveThenDrawShape(w.Box.row2, i, lead+"ceiling") + moveThenDrawShape(w.Box.Row1, w.Box.Col1, lead+"tl") + moveThenDrawShape(w.Box.Row1, w.Box.Col2, lead+"tr") + moveThenDrawShape(w.Box.Row2, w.Box.Col1, lead+"bl") + moveThenDrawShape(w.Box.Row2, w.Box.Col2, lead+"br") + for i := w.Box.Col1 + 1; i < w.Box.Col2; i++ { + moveThenDrawShape(w.Box.Row1, i, lead+"ceiling") + moveThenDrawShape(w.Box.Row2, i, lead+"ceiling") } - for i := w.Box.row1 + 1; i < w.Box.row2; i++ { - moveThenDrawShape(i, w.Box.col1, lead+"wall") - moveThenDrawShape(i, w.Box.col2, lead+"wall") + for i := w.Box.Row1 + 1; i < w.Box.Row2; i++ { + moveThenDrawShape(i, w.Box.Col1, lead+"wall") + moveThenDrawShape(i, w.Box.Col2, lead+"wall") } } @@ -61,10 +62,11 @@ func (w *Window) DrawContent() { borderThickness, contenth = 1, 0 } - height := w.Box.row2 - w.Box.row1 + borderThickness - width := w.Box.col2 - w.Box.col1 + borderThickness + height := w.Box.Row2 - w.Box.Row1 + borderThickness + width := w.Box.Col2 - w.Box.Col1 + borderThickness content := wrapLines(w.Content, width) + w.tempContentLen = len(content) if len(content) < w.Scrollposition+height { maxlines = len(content) @@ -74,14 +76,14 @@ func (w *Window) DrawContent() { } for i := w.Scrollposition; i < maxlines; i++ { - MoveCursorTo(w.Box.row1+contenth+i-w.Scrollposition, w.Box.col1+contenth) + MoveCursorTo(w.Box.Row1+contenth+i-w.Scrollposition, w.Box.Col1+contenth) fmt.Print(strings.Repeat(" ", width)) - MoveCursorTo(w.Box.row1+contenth+i-w.Scrollposition, w.Box.col1+contenth) + MoveCursorTo(w.Box.Row1+contenth+i-w.Scrollposition, w.Box.Col1+contenth) fmt.Print(content[i]) } if short_content { for i := len(content); i <= height; i++ { - MoveCursorTo(w.Box.row1+contenth+i-w.Scrollposition, w.Box.col1+contenth) + MoveCursorTo(w.Box.Row1+contenth+i-w.Scrollposition, w.Box.Col1+contenth) fmt.Print(strings.Repeat(" ", width)) } } @@ -95,9 +97,9 @@ func (w *Window) ScrollDown() { borderThickness = 1 } - height := w.Box.row2 - w.Box.row1 + borderThickness - contentLength := len(w.Content) - if w.Scrollposition < contentLength-height { + height := w.Box.Row2 - w.Box.Row1 + borderThickness + + if w.Scrollposition < w.tempContentLen-height { w.Scrollposition++ } else { fmt.Print("\a") @@ -120,12 +122,12 @@ func (w *Window) PageDown() { borderThickness = 1 } - height := w.Box.row2 - w.Box.row1 + borderThickness - contentLength := len(w.Content) - if w.Scrollposition < contentLength-height { + height := w.Box.Row2 - w.Box.Row1 + borderThickness + + if w.Scrollposition < w.tempContentLen-height { w.Scrollposition += height - if w.Scrollposition > contentLength-height { - w.Scrollposition = contentLength-height + if w.Scrollposition > w.tempContentLen-height { + w.Scrollposition = w.tempContentLen-height } } else { fmt.Print("\a") @@ -140,7 +142,7 @@ func (w *Window) PageUp() { borderThickness = 1 } - height := w.Box.row2 - w.Box.row1 + borderThickness + height := w.Box.Row2 - w.Box.Row1 + borderThickness contentLength := len(w.Content) if w.Scrollposition > 0 && height < contentLength { w.Scrollposition -= height @@ -168,11 +170,10 @@ func (w *Window) ScrollEnd() { borderThickness = 1 } - height := w.Box.row2 - w.Box.row1 + borderThickness + height := w.Box.Row2 - w.Box.Row1 + borderThickness - contentLength := len(w.Content) - if w.Scrollposition < contentLength-height { - w.Scrollposition = contentLength-height + if w.Scrollposition < w.tempContentLen-height { + w.Scrollposition = w.tempContentLen-height } else { fmt.Print("\a") } diff --git a/main.go b/main.go index 314afae..3cc2e26 100644 --- a/main.go +++ b/main.go @@ -455,6 +455,25 @@ func initClient() error { return loadConfig() } +func handleResize() { + oldh, oldw := screen.Height, screen.Width + screen.GetSize() + if screen.Height != oldh || screen.Width != oldw { + screen.Windows[0].Box.Row2 = screen.Height - 2 + screen.Windows[0].Box.Col2 = screen.Width + bookmarksWidth := 40 + if screen.Width < 40 { + bookmarksWidth = screen.Width + } + screen.Windows[1].Box.Row2 = screen.Height - 2 + screen.Windows[1].Box.Col1 = screen.Width - bookmarksWidth + screen.Windows[1].Box.Col2 = screen.Width + + screen.DrawAllWindows() + screen.DrawMsgBars() + } +} + func main() { cui.HandleAlternateScreen("smcup") defer cui.Exit() @@ -481,6 +500,7 @@ func main() { for { c := cui.Getch() + handleResize() switch c { case 'j', 'J': screen.Windows[screen.Activewindow].ScrollDown() From 63df316b96b01732aeaafaacf278f3c165c98f72 Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Tue, 28 May 2019 18:57:50 -0700 Subject: [PATCH 2/3] Ugly fix, but does work. Alleviates issue of resize landing you in deadspace that you should not be able to get to. --- README.md | 2 +- cui/window.go | 7 +++++++ main.go | 22 ++++++++++++---------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7f9c130..71c9495 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ If you would prefer to download a binary for your system, rather than build from ### Documentation -Bombadillo has documentation available in two places currently. The first if the [Bombadillo homepage](https://rawtext.club/~sloum/bombadillo.html#docs), which has lots of information about the program, links to places around Gopher, and documentation of the commands and configuration options. +Bombadillo has documentation available in two places currently. The first is the [Bombadillo homepage](https://rawtext.club/~sloum/bombadillo.html#docs), which has lots of information about the program, links to places around Gopher, and documentation of the commands and configuration options. Secondly, and possibly more importantly, documentation is available via Gopher from within Bombadillo. When a user launches Bombadillo for the first time, their `homeurl` is set to the help file. As such they will have access to all of the key bindings, commands, and configuration from the first run. A user can also type `:?` or `:help` at any time to return to the documentation. Remember that Bombadillo uses vim-like key bindings, so scroll with `j` and `k` to view the docs file. diff --git a/cui/window.go b/cui/window.go index fe82cd5..f2f459f 100644 --- a/cui/window.go +++ b/cui/window.go @@ -68,6 +68,13 @@ func (w *Window) DrawContent() { content := wrapLines(w.Content, width) w.tempContentLen = len(content) + if w.Scrollposition > w.tempContentLen-height { + w.Scrollposition = w.tempContentLen-height + if w.Scrollposition < 0 { + w.Scrollposition = 0 + } + } + if len(content) < w.Scrollposition+height { maxlines = len(content) short_content = true diff --git a/main.go b/main.go index 3cc2e26..0568e69 100644 --- a/main.go +++ b/main.go @@ -459,15 +459,15 @@ func handleResize() { oldh, oldw := screen.Height, screen.Width screen.GetSize() if screen.Height != oldh || screen.Width != oldw { - screen.Windows[0].Box.Row2 = screen.Height - 2 - screen.Windows[0].Box.Col2 = screen.Width - bookmarksWidth := 40 - if screen.Width < 40 { - bookmarksWidth = screen.Width - } - screen.Windows[1].Box.Row2 = screen.Height - 2 - screen.Windows[1].Box.Col1 = screen.Width - bookmarksWidth - screen.Windows[1].Box.Col2 = screen.Width + screen.Windows[0].Box.Row2 = screen.Height - 2 + screen.Windows[0].Box.Col2 = screen.Width + bookmarksWidth := 40 + if screen.Width < 40 { + bookmarksWidth = screen.Width + } + screen.Windows[1].Box.Row2 = screen.Height - 2 + screen.Windows[1].Box.Col1 = screen.Width - bookmarksWidth + screen.Windows[1].Box.Col2 = screen.Width screen.DrawAllWindows() screen.DrawMsgBars() @@ -500,7 +500,9 @@ func main() { for { c := cui.Getch() - handleResize() + + handleResize() + switch c { case 'j', 'J': screen.Windows[screen.Activewindow].ScrollDown() From 55d163ce5bebca5b1d53854614b84ed0faea6232 Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Tue, 28 May 2019 19:02:46 -0700 Subject: [PATCH 3/3] Ran go fmt to clean up formating issues --- cui/window.go | 10 +++++----- gopher/url.go | 1 - main.go | 8 ++++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cui/window.go b/cui/window.go index f2f459f..9ab01bf 100644 --- a/cui/window.go +++ b/cui/window.go @@ -21,7 +21,7 @@ type Window struct { drawBox bool Active bool Show bool - tempContentLen int + tempContentLen int } func (w *Window) DrawWindow() { @@ -66,10 +66,10 @@ func (w *Window) DrawContent() { width := w.Box.Col2 - w.Box.Col1 + borderThickness content := wrapLines(w.Content, width) - w.tempContentLen = len(content) + w.tempContentLen = len(content) if w.Scrollposition > w.tempContentLen-height { - w.Scrollposition = w.tempContentLen-height + w.Scrollposition = w.tempContentLen - height if w.Scrollposition < 0 { w.Scrollposition = 0 } @@ -134,7 +134,7 @@ func (w *Window) PageDown() { if w.Scrollposition < w.tempContentLen-height { w.Scrollposition += height if w.Scrollposition > w.tempContentLen-height { - w.Scrollposition = w.tempContentLen-height + w.Scrollposition = w.tempContentLen - height } } else { fmt.Print("\a") @@ -180,7 +180,7 @@ func (w *Window) ScrollEnd() { height := w.Box.Row2 - w.Box.Row1 + borderThickness if w.Scrollposition < w.tempContentLen-height { - w.Scrollposition = w.tempContentLen-height + w.Scrollposition = w.tempContentLen - height } else { fmt.Print("\a") } diff --git a/gopher/url.go b/gopher/url.go index df65386..cb80f2a 100644 --- a/gopher/url.go +++ b/gopher/url.go @@ -83,7 +83,6 @@ func MakeUrl(u string) (Url, error) { out.IsBinary = true } - out.Full = out.Scheme + "://" + out.Host + ":" + out.Port + "/" + out.Gophertype + out.Resource return out, nil diff --git a/main.go b/main.go index 0568e69..dd6fe5f 100644 --- a/main.go +++ b/main.go @@ -456,9 +456,9 @@ func initClient() error { } func handleResize() { - oldh, oldw := screen.Height, screen.Width - screen.GetSize() - if screen.Height != oldh || screen.Width != oldw { + oldh, oldw := screen.Height, screen.Width + screen.GetSize() + if screen.Height != oldh || screen.Width != oldw { screen.Windows[0].Box.Row2 = screen.Height - 2 screen.Windows[0].Box.Col2 = screen.Width bookmarksWidth := 40 @@ -471,7 +471,7 @@ func handleResize() { screen.DrawAllWindows() screen.DrawMsgBars() - } + } } func main() {