From 5056bd303d13725a07f2bcbdde2bab9f275fe3f1 Mon Sep 17 00:00:00 2001 From: makeworld Date: Wed, 24 Jun 2020 11:37:32 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Add=20no-color=20UI=20elements?= =?UTF-8?q?=20-=20fixes=20#16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + NOTES.md | 2 +- README.md | 6 ++++- display/bookmarks.go | 23 ++++++++++++----- display/display.go | 24 ++++++++++++++---- display/modals.go | 60 +++++++++++++++++++++++++++++++++----------- 6 files changed, 89 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c3eeeb..e2fa950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Mark status code 21 as invalid - Bottom bar is not in focus after clicking Enter - Badly formed links on pages can no longer crash the browser +- Disabling color in config affects UI elements (#16) ## [1.0.0] - 2020-06-18 diff --git a/NOTES.md b/NOTES.md index 7cdbe8e..4635bfd 100644 --- a/NOTES.md +++ b/NOTES.md @@ -11,5 +11,5 @@ - 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) - Add some bold back into modal text after this is fixed -- Bookmark keys aren't deleted, just set to "" +- Bookmark keys aren't deleted, just set to `""` - Waiting on [this viper PR](https://github.com/spf13/viper/pull/519) to be merged \ No newline at end of file diff --git a/README.md b/README.md index 9c5e228..55ab5e2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@
amphora logo -
Modified from: amphora by Alvaro Cabrera from the Noun Project
+
Modified from: amphora by Alvaro Cabrera from the Noun Project
@@ -15,6 +15,8 @@ +###### Recording of v1.0.0 + Amfora aims to be the best looking [Gemini](https://gemini.circumlunar.space/) client with the most features... all in the terminal. It does not support Gopher or other non-Web protocols - check out [Bombadillo](http://bombadillo.colorfield.space/) for that. It also aims to be completely cross platform, with full Windows support. If you're on Windows, I would not recommend using the default terminal software. Maybe use [Cmder](https://cmder.net/) instead? @@ -35,6 +37,8 @@ update-desktop-database ~/.local/share/applications Just call `amfora` or `amfora ` on the terminal. On Windows it might be `amfora.exe` instead. +To determine the version, you can run `amfora --version` or `amfora -v`. + The project keeps many standard terminal keybindings and is intuitive. Press ? inside the application to pull up the help menu with a list of all the keybindings, and Esc to leave it. If you have used Bombadillo you will find it similar. It is designed with large or fullscreen terminals in mind. For optimal usage, make your terminal fullscreen. It was also designed with a dark background terminal in mind, but please file an issue if the colour choices look bad on your terminal setup. It was tested with left-to-right languages, and will likely not work as well with right-to-left languages like Arabic. diff --git a/display/bookmarks.go b/display/bookmarks.go index c3f8193..1941515 100644 --- a/display/bookmarks.go +++ b/display/bookmarks.go @@ -5,19 +5,16 @@ import ( "strconv" "strings" - "github.com/makeworld-the-better-one/amfora/renderer" - "github.com/makeworld-the-better-one/amfora/structs" - "github.com/gdamore/tcell" "github.com/makeworld-the-better-one/amfora/bookmarks" + "github.com/makeworld-the-better-one/amfora/renderer" + "github.com/makeworld-the-better-one/amfora/structs" + "github.com/spf13/viper" "gitlab.com/tslocum/cview" ) // For adding and removing bookmarks, basically a clone of the input modal. var bkmkModal = cview.NewModal(). - SetBackgroundColor(tcell.ColorTeal). - SetButtonBackgroundColor(tcell.ColorNavy). - SetButtonTextColor(tcell.ColorWhite). SetTextColor(tcell.ColorWhite) // bkmkCh is for the user action @@ -25,6 +22,20 @@ var bkmkCh = make(chan int) // 1, 0, -1 for add/update, cancel, and remove var bkmkModalText string // The current text of the input field in the modal func bkmkInit() { + if viper.GetBool("a-general.color") { + bkmkModal.SetBackgroundColor(tcell.ColorTeal). + SetButtonBackgroundColor(tcell.ColorNavy). + SetButtonTextColor(tcell.ColorWhite) + } else { + bkmkModal.SetBackgroundColor(tcell.ColorBlack). + SetButtonBackgroundColor(tcell.ColorWhite). + SetButtonTextColor(tcell.ColorBlack) + bkmkModal.GetForm(). + SetLabelColor(tcell.ColorWhite). + SetFieldBackgroundColor(tcell.ColorWhite). + SetFieldTextColor(tcell.ColorBlack) + } + bkmkModal.SetBorder(true) bkmkModal.SetBorderColor(tcell.ColorWhite) bkmkModal.SetDoneFunc(func(buttonIndex int, buttonLabel string) { diff --git a/display/display.go b/display/display.go index 79e6f5e..0040061 100644 --- a/display/display.go +++ b/display/display.go @@ -23,8 +23,7 @@ var termW int // The user input and URL display bar at the bottom var bottomBar = cview.NewInputField(). SetFieldBackgroundColor(tcell.ColorWhite). - SetFieldTextColor(tcell.ColorBlack). - SetLabelColor(tcell.ColorGreen) + SetFieldTextColor(tcell.ColorBlack) // Viewer for the tab primitives // Pages are named as strings of tab numbers - so the textview for the first tab @@ -115,6 +114,11 @@ func Init() { } tabPages.AddPage("help", helpTable, true, false) + if viper.GetBool("a-general.color") { + bottomBar.SetLabelColor(tcell.ColorGreen) + } else { + bottomBar.SetLabelColor(tcell.ColorBlack) + } bottomBar.SetBackgroundColor(tcell.ColorWhite) bottomBar.SetDoneFunc(func(key tcell.Key) { switch key { @@ -333,7 +337,11 @@ func NewTab() { // Add tab number to the actual place where tabs are show on the screen // Tab regions are 0-indexed but text displayed on the screen starts at 1 - fmt.Fprintf(tabRow, `["%d"][darkcyan] %d [white][""]|`, curTab, curTab+1) + if viper.GetBool("a-general.color") { + fmt.Fprintf(tabRow, `["%d"][darkcyan] %d [white][""]|`, curTab, curTab+1) + } else { + fmt.Fprintf(tabRow, `["%d"] %d [""]|`, curTab, curTab+1) + } tabRow.Highlight(strconv.Itoa(curTab)).ScrollToHighlight() bottomBar.SetLabel("") @@ -376,8 +384,14 @@ func CloseTab() { tabPages.SwitchToPage(strconv.Itoa(curTab)) // Go to previous page // Rewrite the tab display tabRow.Clear() - for i := 0; i < NumTabs(); i++ { - fmt.Fprintf(tabRow, `["%d"][darkcyan] %d [white][""]|`, i, i+1) + if viper.GetBool("a-general.color") { + for i := 0; i < NumTabs(); i++ { + fmt.Fprintf(tabRow, `["%d"][darkcyan] %d [white][""]|`, i, i+1) + } + } else { + for i := 0; i < NumTabs(); i++ { + fmt.Fprintf(tabRow, `["%d"] %d [""]|`, i, i+1) + } } tabRow.Highlight(strconv.Itoa(curTab)).ScrollToHighlight() diff --git a/display/modals.go b/display/modals.go index bd8bff8..55d20f6 100644 --- a/display/modals.go +++ b/display/modals.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/gdamore/tcell" + "github.com/spf13/viper" "gitlab.com/tslocum/cview" ) @@ -13,23 +14,14 @@ import ( // The bookmark modal is in bookmarks.go var infoModal = cview.NewModal(). - SetBackgroundColor(tcell.ColorGray). - SetButtonBackgroundColor(tcell.ColorNavy). - SetButtonTextColor(tcell.ColorWhite). SetTextColor(tcell.ColorWhite). AddButtons([]string{"Ok"}) var errorModal = cview.NewModal(). - SetBackgroundColor(tcell.ColorMaroon). - SetButtonBackgroundColor(tcell.ColorNavy). - SetButtonTextColor(tcell.ColorWhite). SetTextColor(tcell.ColorWhite). AddButtons([]string{"Ok"}) var inputModal = cview.NewModal(). - SetBackgroundColor(tcell.ColorGreen). - SetButtonBackgroundColor(tcell.ColorNavy). - SetButtonTextColor(tcell.ColorWhite). SetTextColor(tcell.ColorWhite). AddButtons([]string{"Send", "Cancel"}) @@ -37,8 +29,6 @@ var inputCh = make(chan string) var inputModalText string // The current text of the input field in the modal var yesNoModal = cview.NewModal(). - SetButtonBackgroundColor(tcell.ColorNavy). - SetButtonTextColor(tcell.ColorWhite). SetTextColor(tcell.ColorWhite). AddButtons([]string{"Yes", "No"}) @@ -52,6 +42,39 @@ func modalInit() { AddPage("yesno", yesNoModal, false, false). AddPage("bkmk", bkmkModal, false, false) + // Color setup + if viper.GetBool("a-general.color") { + infoModal.SetBackgroundColor(tcell.ColorGray). + SetButtonBackgroundColor(tcell.ColorNavy). + SetButtonTextColor(tcell.ColorWhite) + errorModal.SetBackgroundColor(tcell.ColorMaroon). + SetButtonBackgroundColor(tcell.ColorNavy). + SetButtonTextColor(tcell.ColorWhite) + inputModal.SetBackgroundColor(tcell.ColorGreen). + SetButtonBackgroundColor(tcell.ColorNavy). + SetButtonTextColor(tcell.ColorWhite) + yesNoModal.SetButtonBackgroundColor(tcell.ColorNavy). + SetButtonTextColor(tcell.ColorWhite) + } else { + infoModal.SetBackgroundColor(tcell.ColorBlack). + SetButtonBackgroundColor(tcell.ColorWhite). + SetButtonTextColor(tcell.ColorBlack) + errorModal.SetBackgroundColor(tcell.ColorBlack). + SetButtonBackgroundColor(tcell.ColorWhite). + SetButtonTextColor(tcell.ColorBlack) + inputModal.SetBackgroundColor(tcell.ColorBlack). + SetButtonBackgroundColor(tcell.ColorWhite). + SetButtonTextColor(tcell.ColorBlack) + inputModal.GetForm(). + SetLabelColor(tcell.ColorWhite). + SetFieldBackgroundColor(tcell.ColorWhite). + SetFieldTextColor(tcell.ColorBlack) + + // YesNo background color is changed in funcs + yesNoModal.SetButtonBackgroundColor(tcell.ColorWhite). + SetButtonTextColor(tcell.ColorBlack) + } + // Modal functions that can't be added up above, because they return the wrong type infoModal.SetBorder(true) @@ -161,7 +184,12 @@ func Input(prompt string) (string, bool) { // YesNo displays a modal asking a yes-or-no question. func YesNo(prompt string) bool { - yesNoModal.SetText(prompt).SetBackgroundColor(tcell.ColorPurple) + if viper.GetBool("a-general.color") { + yesNoModal.SetBackgroundColor(tcell.ColorPurple) + } else { + yesNoModal.SetBackgroundColor(tcell.ColorBlack) + } + yesNoModal.SetText(prompt) tabPages.ShowPage("yesno") tabPages.SendToFront("yesno") App.SetFocus(yesNoModal) @@ -177,9 +205,13 @@ func YesNo(prompt string) bool { func Tofu(host string) bool { // Reuses yesNoModal, with error colour - yesNoModal.SetBackgroundColor(tcell.ColorMaroon) + if viper.GetBool("a-general.color") { + yesNoModal.SetBackgroundColor(tcell.ColorMaroon) + } else { + yesNoModal.SetBackgroundColor(tcell.ColorBlack) + } yesNoModal.SetText( - fmt.Sprintf("%s's certificate has changed, possibly indicating an security issue. Are you sure you want to continue anyway?", host), + fmt.Sprintf("%s's certificate has changed, possibly indicating an security issue. Are you sure you want to continue?", host), ) tabPages.ShowPage("yesno") tabPages.SendToFront("yesno")