mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-09 22:08:04 -05:00
Use utils.MergeMaps
This commit is contained in:
@@ -132,18 +132,9 @@ func GenerateMappings() map[string]map[Key]string {
|
||||
}
|
||||
}
|
||||
}
|
||||
mergeMaps := func(maps ...map[Key]string) map[Key]string {
|
||||
result := make(map[Key]string)
|
||||
for _, m := range maps {
|
||||
for k, v := range m {
|
||||
result[k] = v
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
for k := range keys {
|
||||
if k != "global" {
|
||||
keys[k] = mergeMaps(keys["global"], keys[k])
|
||||
keys[k] = utils.MergeMaps(keys["global"], keys[k])
|
||||
}
|
||||
}
|
||||
return keys
|
||||
|
||||
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module github.com/aditya-K2/gspt
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/aditya-K2/utils v0.0.0-20230324221547-e982ed1e980e
|
||||
github.com/aditya-K2/utils v0.0.0-20230416002345-2f8487d8c111
|
||||
github.com/fsnotify/fsnotify v1.6.0
|
||||
github.com/gdamore/tcell/v2 v2.5.3
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
|
||||
4
go.sum
4
go.sum
@@ -49,6 +49,10 @@ github.com/BurntSushi/xgbutil v0.0.0-20190907113008-ad855c713046 h1:O/r2Sj+8QcMF
|
||||
github.com/BurntSushi/xgbutil v0.0.0-20190907113008-ad855c713046/go.mod h1:uw9h2sd4WWHOPdJ13MQpwK5qYWKYDumDqxWWIknEQ+k=
|
||||
github.com/aditya-K2/utils v0.0.0-20230324221547-e982ed1e980e h1:blLZ2IHGPfAo2zOEpj4FsuqliHmpLw4u2Zp6GR0VMZ8=
|
||||
github.com/aditya-K2/utils v0.0.0-20230324221547-e982ed1e980e/go.mod h1:M5vD+szIYMn9sAmBGSzwTiwfI63qtzCwguujFy8wybI=
|
||||
github.com/aditya-K2/utils v0.0.0-20230416002208-527506a25c18 h1:du8ANNF3XwAV2yCwUBh08hxQMzefwWTzMVS4WNuDUXQ=
|
||||
github.com/aditya-K2/utils v0.0.0-20230416002208-527506a25c18/go.mod h1:M5vD+szIYMn9sAmBGSzwTiwfI63qtzCwguujFy8wybI=
|
||||
github.com/aditya-K2/utils v0.0.0-20230416002345-2f8487d8c111 h1:nRszo2Av5WTgmZa3TX86Ohs3Fi73YOgMEKbmTZ3CJoE=
|
||||
github.com/aditya-K2/utils v0.0.0-20230416002345-2f8487d8c111/go.mod h1:M5vD+szIYMn9sAmBGSzwTiwfI63qtzCwguujFy8wybI=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
|
||||
34
ui/app.go
34
ui/app.go
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/aditya-K2/gspt/config"
|
||||
"github.com/aditya-K2/utils"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
@@ -133,19 +134,8 @@ func NewApplication() *Application {
|
||||
}, nil),
|
||||
}
|
||||
|
||||
generateActions := func(m map[string]*Action) map[string]*Action {
|
||||
res := make(map[string]*Action)
|
||||
for k, v := range globalMaps {
|
||||
res[k] = v
|
||||
}
|
||||
for k, v := range m {
|
||||
res[k] = v
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// Actions
|
||||
playlistNav.SetActions(generateActions(map[string]*Action{
|
||||
playlistNav.SetActions(utils.MergeMaps(globalMaps, map[string]*Action{
|
||||
"play_entry": NewAction(playlistNav.PlaySelectEntry, pBar),
|
||||
"open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey {
|
||||
r, _ := playlistNav.Table.GetSelection()
|
||||
@@ -155,36 +145,36 @@ func NewApplication() *Application {
|
||||
return nil
|
||||
}, nil),
|
||||
}))
|
||||
navMenu.SetActions(generateActions(map[string]*Action{
|
||||
navMenu.SetActions(utils.MergeMaps(globalMaps, map[string]*Action{
|
||||
"open_entry": NewAction(navMenu.SelectEntry, nil),
|
||||
}))
|
||||
playlistView.SetActions(generateActions(map[string]*Action{
|
||||
playlistView.SetActions(utils.MergeMaps(globalMaps, map[string]*Action{
|
||||
"open_entry": NewAction(func(*tcell.EventKey) *tcell.EventKey {
|
||||
playlistView.PlaySelectEntry()
|
||||
return nil
|
||||
}, pBar),
|
||||
}))
|
||||
recentlyPlayedView.SetActions(generateActions(map[string]*Action{
|
||||
recentlyPlayedView.SetActions(utils.MergeMaps(globalMaps, map[string]*Action{
|
||||
"open_entry": NewAction(recentlyPlayedView.SelectEntry, pBar),
|
||||
}))
|
||||
topTracksView.SetActions(generateActions(map[string]*Action{
|
||||
topTracksView.SetActions(utils.MergeMaps(globalMaps, map[string]*Action{
|
||||
"open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { topTracksView.OpenSelectEntry(); return nil }, pBar),
|
||||
"play_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { topTracksView.PlaySelectedEntry(); return nil }, pBar),
|
||||
}))
|
||||
likedSongsView.SetActions(generateActions(map[string]*Action{
|
||||
likedSongsView.SetActions(utils.MergeMaps(globalMaps, map[string]*Action{
|
||||
"open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey {
|
||||
likedSongsView.OpenEntry()
|
||||
return nil
|
||||
}, pBar),
|
||||
}))
|
||||
searchView.SetActions(generateActions(map[string]*Action{}))
|
||||
artistsView.SetActions(generateActions(map[string]*Action{
|
||||
searchView.SetActions(utils.MergeMaps(globalMaps, map[string]*Action{}))
|
||||
artistsView.SetActions(utils.MergeMaps(globalMaps, map[string]*Action{
|
||||
"open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey {
|
||||
artistsView.OpenArtist()
|
||||
return nil
|
||||
}, nil),
|
||||
}))
|
||||
artistView.SetActions(generateActions(map[string]*Action{
|
||||
artistView.SetActions(utils.MergeMaps(globalMaps, map[string]*Action{
|
||||
"open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey {
|
||||
artistView.OpenEntry()
|
||||
return nil
|
||||
@@ -194,7 +184,7 @@ func NewApplication() *Application {
|
||||
return nil
|
||||
}, pBar),
|
||||
}))
|
||||
albumsView.SetActions(generateActions(map[string]*Action{
|
||||
albumsView.SetActions(utils.MergeMaps(globalMaps, map[string]*Action{
|
||||
"open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey {
|
||||
albumsView.OpenAlbum()
|
||||
return nil
|
||||
@@ -204,7 +194,7 @@ func NewApplication() *Application {
|
||||
return nil
|
||||
}, pBar),
|
||||
}))
|
||||
albumView.SetActions(generateActions(map[string]*Action{
|
||||
albumView.SetActions(utils.MergeMaps(globalMaps, map[string]*Action{
|
||||
"open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey {
|
||||
albumView.PlaySelectEntry()
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user