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/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..9ab01bf 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,18 @@ 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 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) @@ -74,14 +83,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 +104,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 +129,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 +149,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 +177,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/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 314afae..dd6fe5f 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,9 @@ func main() { for { c := cui.Getch() + + handleResize() + switch c { case 'j', 'J': screen.Windows[screen.Activewindow].ScrollDown()