mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
* WTF-1031 Rename WtfApp.app to WtfApp.tviewApp Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-1031 Add scaffolding for main to support multiple WtfApp instances Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-1031 WIP Signed-off-by: Chris Cummer <chriscummer@me.com> * Remove common functionality from KeyboardWidget and into Base Signed-off-by: Chris Cummer <chriscummer@me.com> * Augment with some descriptive comments Signed-off-by: Chris Cummer <chriscummer@me.com> * Add full support for multiple app instances via the AppManager. Still to do: * Config support for multiple apps/multiple config files * The ability to switch between apps Signed-off-by: Chris Cummer <chriscummer@me.com> * Move SetTerminal out of main and into its own file Signed-off-by: Chris Cummer <chriscummer@me.com>
105 lines
3.0 KiB
Go
105 lines
3.0 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/logrusorgru/aurora"
|
|
"github.com/olebedev/config"
|
|
)
|
|
|
|
const exitMessageHeader = `
|
|
____ __ ____ .___________. _______
|
|
\ \ / \ / / | || ____|
|
|
\ \/ \/ / ----| |-----| |__
|
|
\ / | | | __|
|
|
\ /\ / | | | |
|
|
\__/ \__/ |__| |__|
|
|
|
|
the personal information dashboard for your terminal
|
|
`
|
|
|
|
// DisplayExitMessage displays the onscreen exit message when the app quits
|
|
func (wtfApp *WtfApp) DisplayExitMessage() {
|
|
exitMessageIsDisplayable := readDisplayableConfig(wtfApp.config)
|
|
|
|
wtfApp.displayExitMsg(exitMessageIsDisplayable)
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func (wtfApp *WtfApp) displayExitMsg(exitMessageIsDisplayable bool) string {
|
|
// If a sponsor or contributor and opt out of seeing the exit message, do not display it
|
|
if (wtfApp.ghUser.IsContributor || wtfApp.ghUser.IsSponsor) && !exitMessageIsDisplayable {
|
|
return ""
|
|
}
|
|
|
|
msgs := []string{}
|
|
|
|
msgs = append(msgs, aurora.Magenta(exitMessageHeader).String())
|
|
|
|
if wtfApp.ghUser.IsContributor {
|
|
msgs = append(msgs, wtfApp.contributorThankYouMessage())
|
|
}
|
|
|
|
if wtfApp.ghUser.IsSponsor {
|
|
msgs = append(msgs, wtfApp.sponsorThankYouMessage())
|
|
}
|
|
|
|
if !wtfApp.ghUser.IsContributor && !wtfApp.ghUser.IsSponsor {
|
|
msgs = append(msgs, wtfApp.supportRequestMessage())
|
|
}
|
|
|
|
displayMsg := strings.Join(msgs, "\n")
|
|
|
|
fmt.Println(displayMsg)
|
|
|
|
return displayMsg
|
|
}
|
|
|
|
// readDisplayableConfig figures out whether or not the exit message should be displayed
|
|
// per the user's wishes. It allows contributors and sponsors to opt out of the exit message
|
|
func readDisplayableConfig(cfg *config.Config) bool {
|
|
displayExitMsg := cfg.UBool("wtf.exitMessage.display", true)
|
|
return displayExitMsg
|
|
}
|
|
|
|
// readGitHubAPIKey attempts to find a GitHub API key somewhere in the configuration file
|
|
func readGitHubAPIKey(cfg *config.Config) string {
|
|
apiKey := cfg.UString("wtf.exitMessage.githubAPIKey", os.Getenv("WTF_GITHUB_TOKEN"))
|
|
if apiKey != "" {
|
|
return apiKey
|
|
}
|
|
|
|
moduleConfig, err := cfg.Get("wtf.mods.github")
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
|
|
return moduleConfig.UString("apiKey", "")
|
|
}
|
|
|
|
/* -------------------- Messaging -------------------- */
|
|
|
|
func (wtfApp *WtfApp) contributorThankYouMessage() string {
|
|
str := " On behalf of all the users of WTF, thank you for contributing to the source code."
|
|
str += fmt.Sprintf(" %s", aurora.Green("\n\n You rock."))
|
|
|
|
return str
|
|
}
|
|
|
|
func (wtfApp *WtfApp) sponsorThankYouMessage() string {
|
|
str := " Your sponsorship of WTF makes a difference. Thank you for sponsoring and supporting WTF."
|
|
str += fmt.Sprintf(" %s", aurora.Green("\n\n You're awesome."))
|
|
|
|
return str
|
|
}
|
|
|
|
func (wtfApp *WtfApp) supportRequestMessage() string {
|
|
str := " The development and maintenance of WTF is supported by sponsorships.\n"
|
|
str += fmt.Sprintf(" Please consider sponsoring WTF at %s\n", aurora.Green("https://github.com/sponsors/senorprogrammer"))
|
|
|
|
return str
|
|
}
|