diff --git a/amfora.go b/amfora.go index d675cac..970e196 100644 --- a/amfora.go +++ b/amfora.go @@ -74,7 +74,6 @@ func main() { // Initialize Amfora's settings display.Init(version, commit, builtBy) - display.NewTab() // Load a URL, file, or render from stdin if len(os.Args[1:]) > 0 { @@ -93,9 +92,11 @@ func main() { url = "file://" + fileName } } - display.URL(url) + display.NewTabWithURL(url) } else if !isStdinEmpty() { renderFromStdin() + } else { + display.NewTab() } // Start diff --git a/display/display.go b/display/display.go index 02d8136..377aa8d 100644 --- a/display/display.go +++ b/display/display.go @@ -187,7 +187,6 @@ func Init(version, commit, builtBy string) { if i <= len(tabs[tab].page.Links) && i > 0 { // Open new tab and load link oldTab := tab - NewTab() // Resolve and follow link manually prevParsed, _ := url.Parse(tabs[oldTab].page.URL) nextParsed, err := url.Parse(tabs[oldTab].page.Links[i-1]) @@ -196,7 +195,7 @@ func Init(version, commit, builtBy string) { reset() return } - URL(prevParsed.ResolveReference(nextParsed).String()) + NewTabWithURL(prevParsed.ResolveReference(nextParsed).String()) return } } else { @@ -328,8 +327,7 @@ func Init(version, commit, builtBy string) { Error("URL Error", err.Error()) return nil } - NewTab() - URL(next) + NewTabWithURL(next) } else { NewTab() } @@ -377,6 +375,17 @@ func Stop() { // NewTab opens a new tab and switches to it, displaying the // the default empty content because there's no URL. func NewTab() { + NewTabWithURL("about:newtab") + + bottomBar.SetLabel("") + bottomBar.SetText("") + tabs[NumTabs()-1].saveBottomBar() + +} + +// NewTabWithURL opens a new tab and switches to it, displaying the +// the URL provided. +func NewTabWithURL(url string) { // Create TextView and change curTab // Set the TextView options, and the changed func to App.Draw() // SetDoneFunc to do link highlighting @@ -393,8 +402,16 @@ func NewTab() { curTab = NumTabs() tabs = append(tabs, makeNewTab()) - temp := newTabPage // Copy - setPage(tabs[curTab], &temp) + + var interstitial string + if !strings.HasPrefix(url, "about:") { + interstitial = "Loading " + url + "..." + } + + setPage(tabs[curTab], renderPageFromString(interstitial)) + + // Regardless of the starting URL, about:newtab will + // be the history root. tabs[curTab].addToHistory("about:newtab") tabs[curTab].history.pos = 0 // Manually set as first page @@ -406,9 +423,7 @@ func NewTab() { browser.SetCurrentTab(strconv.Itoa(curTab)) App.SetFocus(tabs[curTab].view) - bottomBar.SetLabel("") - bottomBar.SetText("") - tabs[curTab].saveBottomBar() + URL(url) // Draw just in case App.Draw() @@ -529,11 +544,11 @@ func URL(u string) { func RenderFromString(str string) { t := tabs[curTab] - page, _ := renderPageFromString(str) + page := renderPageFromString(str) setPage(t, page) } -func renderPageFromString(str string) (*structs.Page, bool) { +func renderPageFromString(str string) *structs.Page { rendered, links := renderer.RenderGemini(str, textWidth(), false) page := &structs.Page{ Mediatype: structs.TextGemini, @@ -543,7 +558,7 @@ func renderPageFromString(str string) (*structs.Page, bool) { TermWidth: termW, } - return page, true + return page } func NumTabs() int { diff --git a/display/modals.go b/display/modals.go index eb4bb68..5ad362e 100644 --- a/display/modals.go +++ b/display/modals.go @@ -18,6 +18,7 @@ import ( var infoModal = cview.NewModal() var errorModal = cview.NewModal() +var errorModalDone = make(chan struct{}) var inputModal = cview.NewModal() var inputCh = make(chan string) @@ -152,6 +153,7 @@ func modalInit() { panels.HidePanel("error") App.SetFocus(tabs[curTab].view) App.Draw() + errorModalDone <- struct{}{} }) inputModal.SetBorder(true) @@ -200,6 +202,8 @@ func Error(title, text string) { panels.SendToFront("error") App.SetFocus(errorModal) App.Draw() + + <-errorModalDone } // Info displays some info on the screen in a modal. diff --git a/display/private.go b/display/private.go index ecf4491..d483124 100644 --- a/display/private.go +++ b/display/private.go @@ -134,6 +134,9 @@ func goURL(t *tab, u string) { final, displayed := handleURL(t, u, 0) if displayed { t.addToHistory(final) + } else if t.page.URL == "" { + // The tab is showing interstitial or no content. Let's go to about:newtab. + handleAbout(t, "about:newtab") } if t == tabs[curTab] { // Display the bottomBar state that handleURL set