1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-12-04 14:46:29 -05:00

Give Error modals titles

This commit is contained in:
makeworld 2020-06-19 14:05:05 -04:00
parent 85a89846bb
commit 92738f54b3
4 changed files with 14 additions and 27 deletions

View File

@ -8,14 +8,5 @@
- Filed [issue 23](https://gitlab.com/tslocum/cview/-/issues/23) - Filed [issue 23](https://gitlab.com/tslocum/cview/-/issues/23)
- Text background not reset on ANSI pages - Text background not reset on ANSI pages
- Filed [issue 25](https://gitlab.com/tslocum/cview/-/issues/25) - Filed [issue 25](https://gitlab.com/tslocum/cview/-/issues/25)
- Inputfield isn't repeatedly in focus - Modal styling messed up when wrapped - example occurence is the error modal for a long unsupported scheme URL
- Tried multiple focus options with App and Form funcs, but nothing worked - Filed [issue 26](https://gitlab.com/tslocum/cview/-/issues/26)
- 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?

View File

@ -2,8 +2,6 @@
package client package client
import ( import (
"fmt"
"github.com/makeworld-the-better-one/go-gemini" "github.com/makeworld-the-better-one/go-gemini"
) )
@ -12,7 +10,7 @@ import (
func Fetch(url string) (*gemini.Response, error) { func Fetch(url string) (*gemini.Response, error) {
resp, err := gemini.Fetch(url) resp, err := gemini.Fetch(url)
if err != nil { if err != nil {
return nil, fmt.Errorf("URL could not be fetched: %v", err) return nil, err
} }
ok := handleTofu(resp.Cert) ok := handleTofu(resp.Cert)
if !ok { if !ok {

View File

@ -54,8 +54,8 @@ func modalInit() {
errorModal.SetBorder(true) errorModal.SetBorder(true)
errorModal.SetBorderColor(tcell.ColorWhite) errorModal.SetBorderColor(tcell.ColorWhite)
errorModal.SetTitleColor(tcell.ColorWhite) errorModal.GetFrame().SetTitleColor(tcell.ColorWhite)
errorModal.SetTitleAlign(cview.AlignCenter) errorModal.GetFrame().SetTitleAlign(cview.AlignCenter)
errorModal.SetDoneFunc(func(buttonIndex int, buttonLabel string) { errorModal.SetDoneFunc(func(buttonIndex int, buttonLabel string) {
tabPages.SwitchToPage(strconv.Itoa(curTab)) tabPages.SwitchToPage(strconv.Itoa(curTab))
}) })
@ -96,8 +96,7 @@ func Error(title, text string) {
// Add spaces to title for aesthetic reasons // Add spaces to title for aesthetic reasons
title = " " + strings.TrimSpace(title) + " " title = " " + strings.TrimSpace(title) + " "
errorModal.GetFrame().Clear() errorModal.GetFrame().SetTitle(title)
errorModal.GetFrame().AddText(title, true, cview.AlignCenter, tcell.ColorWhite)
errorModal.SetText(text) errorModal.SetText(text)
tabPages.ShowPage("error") tabPages.ShowPage("error")
tabPages.SendToFront("error") tabPages.SendToFront("error")

View File

@ -60,7 +60,7 @@ func followLink(prev, next string) {
prevParsed, _ := url.Parse(prev) prevParsed, _ := url.Parse(prev)
nextParsed, err := url.Parse(next) nextParsed, err := url.Parse(next)
if err != nil { if err != nil {
Error("Error", "Link URL could not be parsed") Error("URL Error", "Link URL could not be parsed")
return return
} }
nextURL := prevParsed.ResolveReference(nextParsed).String() nextURL := prevParsed.ResolveReference(nextParsed).String()
@ -116,11 +116,11 @@ func handleURL(u string) (string, bool) {
if strings.HasPrefix(u, "http") { if strings.HasPrefix(u, "http") {
switch strings.TrimSpace(viper.GetString("a-general.http")) { switch strings.TrimSpace(viper.GetString("a-general.http")) {
case "", "off": case "", "off":
Error("Error", "Opening HTTP URLs is turned off.") Info("Opening HTTP URLs is turned off.")
case "default": case "default":
s, err := webbrowser.Open(u) s, err := webbrowser.Open(u)
if err != nil { if err != nil {
Error("Error", err.Error()) Error("Webbrowser Error", err.Error())
} else { } else {
Info(s) Info(s)
} }
@ -129,15 +129,14 @@ func handleURL(u string) (string, bool) {
fields := strings.Fields(viper.GetString("a-general.http")) fields := strings.Fields(viper.GetString("a-general.http"))
err := exec.Command(fields[0], append(fields[1:], u)...).Start() err := exec.Command(fields[0], append(fields[1:], u)...).Start()
if err != nil { if err != nil {
Error("Error", err.Error()) Error("HTTP Error", "Error executing custom browser command: "+err.Error())
} }
} }
bottomBar.SetText(tabMap[curTab].Url) bottomBar.SetText(tabMap[curTab].Url)
return "", false return "", false
} }
if !strings.HasPrefix(u, "gemini") { if !strings.HasPrefix(u, "gemini") {
// TODO: Replace it with with displaying the URL, once modal titles work Error("Protocol Error", "Only [::b]gemini[::-] and [::b]http[::-] are supported. URL was "+u)
Error("Error", "Unsupported protocol, only [::b]gemini[::-] and [::b]http[::-] are supported.")
bottomBar.SetText(tabMap[curTab].Url) bottomBar.SetText(tabMap[curTab].Url)
return "", false return "", false
} }
@ -155,7 +154,7 @@ func handleURL(u string) (string, bool) {
res, err := client.Fetch(u) res, err := client.Fetch(u)
if err != nil { if err != nil {
Error("Error", err.Error()) Error("URL Fetch Error", err.Error())
// Set the bar back to original URL // Set the bar back to original URL
bottomBar.SetText(tabMap[curTab].Url) bottomBar.SetText(tabMap[curTab].Url)
return "", false return "", false
@ -163,7 +162,7 @@ func handleURL(u string) (string, bool) {
if renderer.CanDisplay(res) { if renderer.CanDisplay(res) {
page, err := renderer.MakePage(u, res) page, err := renderer.MakePage(u, res)
if err != nil { 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 // Set the bar back to original URL
bottomBar.SetText(tabMap[curTab].Url) bottomBar.SetText(tabMap[curTab].Url)
return "", false return "", false
@ -227,7 +226,7 @@ func handleURL(u string) (string, bool) {
s, err := webbrowser.Open("https://portal.mozz.us/gemini/" + portalURL) s, err := webbrowser.Open("https://portal.mozz.us/gemini/" + portalURL)
if err != nil { if err != nil {
Error("Error", err.Error()) Error("Webbrowser Error", err.Error())
} else { } else {
Info(s) Info(s)
} }