diff --git a/colors.go b/colors.go index 3ebe85a..afc16fc 100644 --- a/colors.go +++ b/colors.go @@ -1,8 +1,6 @@ package main import ( - "log" - "github.com/gdamore/tcell/v2" ) @@ -31,11 +29,7 @@ func newColor() *Colors { for k, v := range defaultColors { // color from the config file - cfgColor, err := getString(gomu.env, k) - if err != nil { - log.Fatal(err) - } - + cfgColor := getString(gomu.env, k) if validHexColor(cfgColor) { continue } @@ -46,10 +40,7 @@ func newColor() *Colors { // handle none background color var bgColor tcell.Color - bg, err := getString(gomu.env, "color_background") - if err != nil { - log.Fatal(err) - } + bg := getString(gomu.env, "color_background") if bg == "none" { bgColor = tcell.ColorDefault @@ -57,30 +48,11 @@ func newColor() *Colors { bgColor = tcell.GetColor(bg) } - accent, err := getString(gomu.env, "color_accent") - if err != nil { - log.Fatal(err) - } - - foreground, err := getString(gomu.env, "color_foreground") - if err != nil { - log.Fatal(err) - } - - popup, err := getString(gomu.env, "color_popup") - if err != nil { - log.Fatal(err) - } - - title, err := getString(gomu.env, "color_now_playing_title") - if err != nil { - log.Fatal(err) - } - - playlist, err := getString(gomu.env, "color_playlist") - if err != nil { - log.Fatal(err) - } + accent := getString(gomu.env, "color_accent") + foreground := getString(gomu.env, "color_foreground") + popup := getString(gomu.env, "color_popup") + title := getString(gomu.env, "color_now_playing_title") + playlist := getString(gomu.env, "color_playlist") color := &Colors{ accent: tcell.GetColor(accent), diff --git a/command.go b/command.go index 7c62c5a..2b38a89 100644 --- a/command.go +++ b/command.go @@ -204,10 +204,7 @@ func (c Command) defineCommands() { c.define("bulk_add", func() { currNode := gomu.playlist.GetCurrentNode() - bulkAdd, err := getBool(gomu.env, "confirm_bulk_add") - if err != nil { - log.Fatal(err) - } + bulkAdd := getBool(gomu.env, "confirm_bulk_add") if !bulkAdd { gomu.playlist.addAllToQueue(currNode) @@ -323,10 +320,7 @@ func (c Command) defineCommands() { /* Global */ c.define("quit", func() { - confirmOnExit, err := getBool(gomu.env, "confirm_on_exit") - if err != nil { - log.Fatal(err) - } + confirmOnExit := getBool(gomu.env, "confirm_on_exit") if !confirmOnExit { err := gomu.quit(gomu.args) diff --git a/player.go b/player.go index 2e288d4..e48133e 100644 --- a/player.go +++ b/player.go @@ -4,7 +4,6 @@ package main import ( "fmt" - "log" "os" "time" @@ -38,10 +37,7 @@ type Player struct { func newPlayer() *Player { - volume, err := getInt(gomu.env, "volume") - if err != nil { - log.Fatal(err) - } + volume := getInt(gomu.env, "volume") // Read initial volume from config initVol := absVolume(volume) diff --git a/playingbar_test.go b/playingbar_test.go index 356b2f1..0bffcf6 100644 --- a/playingbar_test.go +++ b/playingbar_test.go @@ -7,6 +7,13 @@ import ( func Test_NewPlayingBar(t *testing.T) { gomu = newGomu() + err := execConfig(expandFilePath("./test/config")) + if err != nil { + t.Error(err) + } + + gomu.colors = newColor() + p := newPlayingBar() if p.progress == nil { diff --git a/playlist.go b/playlist.go index 9c46dd6..c70bbd0 100644 --- a/playlist.go +++ b/playlist.go @@ -742,20 +742,12 @@ func (p *Playlist) paste() error { } func setDisplayText(songName string) string { - useEmoji, err := getBool(gomu.env, "use_emoji") - if err != nil { - log.Fatal(err) - } - + useEmoji := getBool(gomu.env, "use_emoji") if !useEmoji { return songName } - emojiFile, err := getString(gomu.env, "emoji_file") - if err != nil { - log.Fatal(err) - } - + emojiFile := getString(gomu.env, "emoji_file") return fmt.Sprintf(" %s %s", emojiFile, songName) } diff --git a/playlist_test.go b/playlist_test.go index 139bb32..fa25242 100644 --- a/playlist_test.go +++ b/playlist_test.go @@ -20,6 +20,13 @@ func prepareTest() *Gomu { } gomu.app = tview.NewApplication() + err := execConfig(expandFilePath("./test/config")) + if err != nil { + panic(err) + } + + gomu.colors = newColor() + rootDir, err := filepath.Abs("./test") if err != nil { panic(err) @@ -41,6 +48,12 @@ func prepareTest() *Gomu { func TestPopulate(t *testing.T) { gomu = newGomu() + err := execConfig(expandFilePath("./test/config")) + if err != nil { + t.Error(err) + } + gomu.colors = newColor() + rootDir, err := filepath.Abs("./test") if err != nil { @@ -78,12 +91,15 @@ func TestPopulate(t *testing.T) { }) populate(root, rootDir) - gotItems := 1 + gotItems := 0 root.Walk(func(node, _ *tview.TreeNode) bool { gotItems++ return true }) + // ignore config and arbitrary_file.txt + gotItems += 2 + if gotItems != expected { t.Errorf("Invalid amount of file; expected %d got %d", expected, gotItems) } diff --git a/popup.go b/popup.go index 6c181da..50144de 100644 --- a/popup.go +++ b/popup.go @@ -68,10 +68,7 @@ func (s *Stack) pop() tview.Primitive { // Gets popup timeout from config file func getPopupTimeout() time.Duration { - dur, err := getString(gomu.env, "popup_timeout") - if err != nil { - log.Fatal(err) - } + dur := getString(gomu.env, "popup_timeout") m, err := time.ParseDuration(dur) @@ -542,7 +539,7 @@ func debugPopup(message string) { func inputPopup(prompt string) string { popupID := "general-input-popup" - input := newInputPopup(popupID, "", prompt + ": ", "") + input := newInputPopup(popupID, "", prompt+": ", "") result := make(chan string) input.SetInputCapture(func(e *tcell.EventKey) *tcell.EventKey { @@ -552,7 +549,7 @@ func inputPopup(prompt string) string { if newName == "" { return e } - result <-newName + result <- newName gomu.pages.RemovePage(popupID) gomu.popups.pop() diff --git a/queue.go b/queue.go index b52ff4e..64d7780 100644 --- a/queue.go +++ b/queue.go @@ -8,7 +8,6 @@ import ( "encoding/hex" "fmt" "io/ioutil" - "log" "math/rand" "os" "path" @@ -98,29 +97,22 @@ func (q *Queue) updateTitle() string { var loop string - isEmoji, err := getBool(gomu.env, "use_emoji") - if err != nil { - log.Fatal(err) - } + isEmoji := getBool(gomu.env, "use_emoji") if q.isLoop { if isEmoji { - loop, err = getString(gomu.env, "emoji_loop") + loop = getString(gomu.env, "emoji_loop") } else { loop = "Loop" } } else { if isEmoji { - loop, err = getString(gomu.env, "emoji_noloop") + loop = getString(gomu.env, "emoji_noloop") } else { loop = "No loop" } } - if err != nil { - log.Fatal(err) - } - title := fmt.Sprintf("─ Queue ───┤ %d %s | %s | %s ├", len(q.items), count, fmtTime, loop) diff --git a/search.go b/search.go index cdbeb7b..ce2d621 100644 --- a/search.go +++ b/search.go @@ -86,15 +86,12 @@ func getRequest(url string, v interface{}) error { func getSearchResult(query string) ([]YoutubeVideo, error) { query = url.QueryEscape(query) - domain, err := getString(gomu.env, "invidious_instance") - if err != nil { - return nil, err - } + domain := getString(gomu.env, "invidious_instance") targetUrl := domain + `/api/v1/search?q=` + query yt := []YoutubeVideo{} - err = getRequest(targetUrl, &yt) + err := getRequest(targetUrl, &yt) if err != nil { return nil, err } diff --git a/start.go b/start.go index dc4b2ba..5ed8508 100644 --- a/start.go +++ b/start.go @@ -32,11 +32,11 @@ type Panel interface { } const ( - configPath = "~/.config/gomu/config" - musicPath = "~/music" + configPath = "~/.config/gomu/config" + musicPath = "~/music" ) -func execConfig() error { +func execConfig(config string) error { const defaultConfig = ` @@ -82,7 +82,7 @@ color_popup = "#0A0F14" gomu.env.DefineGlobal("debug_popup", debugPopup) gomu.env.DefineGlobal("input_popup", inputPopup) - cfg := expandTilde(configPath) + cfg := expandTilde(config) _, err := os.Stat(cfg) if os.IsNotExist(err) { @@ -112,8 +112,6 @@ color_popup = "#0A0F14" return nil } - - type Args struct { config *string empty *bool @@ -154,7 +152,7 @@ func start(application *tview.Application, args Args) { // Assigning to global variable gomu gomu = newGomu() - err := execConfig() + err := execConfig(expandFilePath(*args.config)) if err != nil { panic(err) } @@ -184,20 +182,12 @@ func start(application *tview.Application, args Args) { gomu.playingBar.setDefault() - isQueueLoop, err := getBool(gomu.env, "queue_loop") - if err != nil { - logError(err) - return - } + isQueueLoop := getBool(gomu.env, "queue_loop") gomu.player.isLoop = isQueueLoop gomu.queue.isLoop = gomu.player.isLoop - loadQueue, err := getBool(gomu.env, "load_prev_queue") - if err != nil { - logError(err) - return - } + loadQueue := getBool(gomu.env, "load_prev_queue") if !*args.empty && loadQueue { // load saved queue from previous session @@ -238,7 +228,7 @@ func start(application *tview.Application, args Args) { } // check for user defined keybindings - kb, err := gomu.env.Get("keybinds") + kb, err := gomu.env.Get("keybinds") if err == nil { keybinds, ok := kb.(map[interface{}]interface{}) if !ok { @@ -268,7 +258,6 @@ func start(application *tview.Application, args Args) { } } - cmds := map[rune]string{ 'q': "quit", ' ': "toggle_pause", diff --git a/utils.go b/utils.go index 7d6a466..cc1eb9b 100644 --- a/utils.go +++ b/utils.go @@ -202,44 +202,44 @@ func appendFile(path string, content string) error { return nil } -func getInt(e *env.Env, symbol string) (int, error) { +func getInt(e *env.Env, symbol string) int { v, err := e.Get(symbol) if err != nil { - return 0, err + return 0 } val, ok := v.(int64) if !ok { - return 0, tracerr.New("expected int") + return 0 } - return int(val), nil + return int(val) } -func getString(e *env.Env, symbol string) (string, error) { +func getString(e *env.Env, symbol string) string { v, err := e.Get(symbol) if err != nil { - return "", err + return "" } val, ok := v.(string) if !ok { - return "", tracerr.New("expected string") + return "" } - return val, nil + return val } -func getBool(e *env.Env, symbol string) (bool, error) { +func getBool(e *env.Env, symbol string) bool { v, err := e.Get(symbol) if err != nil { - return false, err + return false } val, ok := v.(bool) if !ok { - return false, tracerr.New("expected bool") + return false } - return val, nil + return val }