From 92738f54b3f829496e7651b08016a75214ed7fd3 Mon Sep 17 00:00:00 2001 From: makeworld Date: Fri, 19 Jun 2020 14:05:05 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Give=20Error=20modals=20titles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NOTES.md | 13 ++----------- client/client.go | 4 +--- display/modals.go | 7 +++---- display/private.go | 17 ++++++++--------- 4 files changed, 14 insertions(+), 27 deletions(-) diff --git a/NOTES.md b/NOTES.md index 3f64462..67883f8 100644 --- a/NOTES.md +++ b/NOTES.md @@ -8,14 +8,5 @@ - Filed [issue 23](https://gitlab.com/tslocum/cview/-/issues/23) - Text background not reset on ANSI pages - Filed [issue 25](https://gitlab.com/tslocum/cview/-/issues/25) -- Inputfield isn't repeatedly in focus - - Tried multiple focus options with App and Form funcs, but nothing worked -- Modal title does not display - - See [my comment](https://gitlab.com/tslocum/cview/-/issues/24#note_364617155) - -## Small todos -- Look at Github issues -- Look at other todos in code -- Add "Why the name amfora" thing to README -- Pass `gemini://egsam.pitr.ca/` test - - Timeout for server not closing connection? +- Modal styling messed up when wrapped - example occurence is the error modal for a long unsupported scheme URL + - Filed [issue 26](https://gitlab.com/tslocum/cview/-/issues/26) diff --git a/client/client.go b/client/client.go index bd91881..67426ea 100644 --- a/client/client.go +++ b/client/client.go @@ -2,8 +2,6 @@ package client import ( - "fmt" - "github.com/makeworld-the-better-one/go-gemini" ) @@ -12,7 +10,7 @@ import ( func Fetch(url string) (*gemini.Response, error) { resp, err := gemini.Fetch(url) if err != nil { - return nil, fmt.Errorf("URL could not be fetched: %v", err) + return nil, err } ok := handleTofu(resp.Cert) if !ok { diff --git a/display/modals.go b/display/modals.go index cf3ba27..68fd333 100644 --- a/display/modals.go +++ b/display/modals.go @@ -54,8 +54,8 @@ func modalInit() { errorModal.SetBorder(true) errorModal.SetBorderColor(tcell.ColorWhite) - errorModal.SetTitleColor(tcell.ColorWhite) - errorModal.SetTitleAlign(cview.AlignCenter) + errorModal.GetFrame().SetTitleColor(tcell.ColorWhite) + errorModal.GetFrame().SetTitleAlign(cview.AlignCenter) errorModal.SetDoneFunc(func(buttonIndex int, buttonLabel string) { tabPages.SwitchToPage(strconv.Itoa(curTab)) }) @@ -96,8 +96,7 @@ func Error(title, text string) { // Add spaces to title for aesthetic reasons title = " " + strings.TrimSpace(title) + " " - errorModal.GetFrame().Clear() - errorModal.GetFrame().AddText(title, true, cview.AlignCenter, tcell.ColorWhite) + errorModal.GetFrame().SetTitle(title) errorModal.SetText(text) tabPages.ShowPage("error") tabPages.SendToFront("error") diff --git a/display/private.go b/display/private.go index 8fcaa9d..b4fae8d 100644 --- a/display/private.go +++ b/display/private.go @@ -60,7 +60,7 @@ func followLink(prev, next string) { prevParsed, _ := url.Parse(prev) nextParsed, err := url.Parse(next) if err != nil { - Error("Error", "Link URL could not be parsed") + Error("URL Error", "Link URL could not be parsed") return } nextURL := prevParsed.ResolveReference(nextParsed).String() @@ -116,11 +116,11 @@ func handleURL(u string) (string, bool) { if strings.HasPrefix(u, "http") { switch strings.TrimSpace(viper.GetString("a-general.http")) { case "", "off": - Error("Error", "Opening HTTP URLs is turned off.") + Info("Opening HTTP URLs is turned off.") case "default": s, err := webbrowser.Open(u) if err != nil { - Error("Error", err.Error()) + Error("Webbrowser Error", err.Error()) } else { Info(s) } @@ -129,15 +129,14 @@ func handleURL(u string) (string, bool) { fields := strings.Fields(viper.GetString("a-general.http")) err := exec.Command(fields[0], append(fields[1:], u)...).Start() if err != nil { - Error("Error", err.Error()) + Error("HTTP Error", "Error executing custom browser command: "+err.Error()) } } bottomBar.SetText(tabMap[curTab].Url) return "", false } if !strings.HasPrefix(u, "gemini") { - // TODO: Replace it with with displaying the URL, once modal titles work - Error("Error", "Unsupported protocol, only [::b]gemini[::-] and [::b]http[::-] are supported.") + Error("Protocol Error", "Only [::b]gemini[::-] and [::b]http[::-] are supported. URL was "+u) bottomBar.SetText(tabMap[curTab].Url) return "", false } @@ -155,7 +154,7 @@ func handleURL(u string) (string, bool) { res, err := client.Fetch(u) if err != nil { - Error("Error", err.Error()) + Error("URL Fetch Error", err.Error()) // Set the bar back to original URL bottomBar.SetText(tabMap[curTab].Url) return "", false @@ -163,7 +162,7 @@ func handleURL(u string) (string, bool) { if renderer.CanDisplay(res) { page, err := renderer.MakePage(u, res) if err != nil { - Error("Error", "Issuing creating page: "+err.Error()) + Error("Page Error", "Issuing creating page: "+err.Error()) // Set the bar back to original URL bottomBar.SetText(tabMap[curTab].Url) return "", false @@ -227,7 +226,7 @@ func handleURL(u string) (string, bool) { s, err := webbrowser.Open("https://portal.mozz.us/gemini/" + portalURL) if err != nil { - Error("Error", err.Error()) + Error("Webbrowser Error", err.Error()) } else { Info(s) }