From 38fe18fc9b89365566359d075335a8d474f16709 Mon Sep 17 00:00:00 2001 From: Simon Garrelou Date: Wed, 7 Dec 2022 20:21:55 +0100 Subject: Use methods instead of functions (makes more sense) --- src/alert.go | 2 +- src/app.go | 22 +++++++++++----------- src/page_artists.go | 8 ++++---- src/page_config.go | 12 ++++++------ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/alert.go b/src/alert.go index 917d089..bfa7321 100644 --- a/src/alert.go +++ b/src/alert.go @@ -6,7 +6,7 @@ import ( "github.com/rivo/tview" ) -func alert(a *app, format string, params ...interface{}) { +func (a *app) alert(format string, params ...interface{}) { modal := tview.NewModal(). SetText(fmt.Sprintf(format, params...)). AddButtons([]string{"OK"}). diff --git a/src/app.go b/src/app.go index c7e38a6..d9ed0cb 100644 --- a/src/app.go +++ b/src/app.go @@ -44,14 +44,14 @@ func Run(cfg *Config) { cur, _ := a.pages.GetFrontPage() if hl != cur { - switchToPage(a, hl) + a.switchToPage(hl) } }) fmt.Fprintf(a.header, `["artists"]F1: Artists[""] | ["playlists"]F2: Playlists[""] | ["config"]F3: Configuration[""]`) a.pages.SetBorder(true) - a.pages.AddPage("config", configPage(a), true, false) - a.pages.AddPage("artists", artistsPage(a), true, false) + a.pages.AddPage("config", a.configPage(), true, false) + a.pages.AddPage("artists", a.artistsPage(), true, false) mainLayout := tview.NewFlex(). SetDirection(tview.FlexRow). @@ -60,14 +60,14 @@ func Run(cfg *Config) { AddItem(a.footer, 1, 1, false) if testConfig(a.cfg) != nil { - switchToPage(a, "config") + a.switchToPage("config") } else { a.sub, _ = buildSubsonicClient(a.cfg) - err := refreshArtists(a) + err := a.refreshArtists() if err != nil { - alert(a, "Could not refresh artists: %v", err) + a.alert("Could not refresh artists: %v", err) } else { - switchToPage(a, "artists") + a.switchToPage("artists") } } @@ -75,13 +75,13 @@ func Run(cfg *Config) { a.tv.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { switch event.Key() { case tcell.KeyF1: - switchToPage(a, "artists") + a.switchToPage("artists") return nil case tcell.KeyF2: - switchToPage(a, "playlists") + a.switchToPage("playlists") return nil case tcell.KeyF3: - switchToPage(a, "config") + a.switchToPage("config") return nil } @@ -99,7 +99,7 @@ func Run(cfg *Config) { } } -func switchToPage(a *app, name string) { +func (a *app) switchToPage(name string) { switch name { case "artists": a.pages.SwitchToPage("artists") diff --git a/src/page_artists.go b/src/page_artists.go index 0e1cc72..23d9a1e 100644 --- a/src/page_artists.go +++ b/src/page_artists.go @@ -13,7 +13,7 @@ type selection struct { id string } -func artistsPage(a *app) tview.Primitive { +func (a *app) artistsPage() tview.Primitive { grid := tview.NewGrid(). SetColumns(40, 0). SetBorders(true) @@ -35,7 +35,7 @@ func artistsPage(a *app) tview.Primitive { return } - loadAlbumInPanel(a, sel.id) + a.loadAlbumInPanel(sel.id) a.tv.SetFocus(a.songsList) }) @@ -66,7 +66,7 @@ func artistsPage(a *app) tview.Primitive { return grid } -func refreshArtists(a *app) error { +func (a *app) refreshArtists() error { artistsID3, err := a.sub.GetArtists(nil) if err != nil { return err @@ -104,7 +104,7 @@ func refreshArtists(a *app) error { return nil } -func loadAlbumInPanel(a *app, id string) error { +func (a *app) loadAlbumInPanel(id string) error { album, err := a.sub.GetMusicDirectory(id) if err != nil { return err diff --git a/src/page_config.go b/src/page_config.go index 090a70b..71662ec 100644 --- a/src/page_config.go +++ b/src/page_config.go @@ -8,7 +8,7 @@ import ( "github.com/rivo/tview" ) -func configPage(a *app) *tview.Form { +func (a *app) configPage() *tview.Form { var err error form := tview.NewForm(). @@ -17,23 +17,23 @@ func configPage(a *app) *tview.Form { AddPasswordField("Password", a.cfg.Password, 20, '*', func(txt string) { a.cfg.Password = txt }). AddButton("Test", func() { if err = testConfig(a.cfg); err != nil { - alert(a, "Could not auth: %v", err) + a.alert("Could not auth: %v", err) } else { - alert(a, "Success.") + a.alert("Success.") } }). AddButton("Save", func() { err := a.cfg.Save() if err != nil { - alert(a, "Error saving: %v", err) + a.alert("Error saving: %v", err) return } a.sub, err = buildSubsonicClient(a.cfg) if err != nil { - alert(a, "Could not auth: %v", err) + a.alert("Could not auth: %v", err) } else { - alert(a, "All good!") + a.alert("All good!") } }) return form -- cgit v1.2.3