2021-10-12 12:30:16 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-10-17 11:00:57 -06:00
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
|
2021-12-25 11:48:23 -07:00
|
|
|
"github.com/aditya-K2/gomp/cache"
|
|
|
|
"github.com/aditya-K2/gomp/client"
|
|
|
|
"github.com/aditya-K2/gomp/config"
|
2022-08-28 23:34:12 -06:00
|
|
|
"github.com/aditya-K2/gomp/notify"
|
2021-12-22 08:49:37 -07:00
|
|
|
"github.com/aditya-K2/gomp/render"
|
|
|
|
"github.com/aditya-K2/gomp/ui"
|
2021-12-16 12:36:18 -07:00
|
|
|
"github.com/aditya-K2/gomp/utils"
|
2022-08-31 12:12:15 -06:00
|
|
|
"github.com/aditya-K2/gomp/views"
|
2021-12-12 13:05:40 -07:00
|
|
|
|
2021-11-28 11:03:34 -07:00
|
|
|
"github.com/aditya-K2/fuzzy"
|
2022-09-08 13:16:38 -06:00
|
|
|
"github.com/fhs/gompd/v2/mpd"
|
2021-10-14 10:34:16 -06:00
|
|
|
"github.com/gdamore/tcell/v2"
|
2021-11-05 01:10:46 -06:00
|
|
|
"github.com/spf13/viper"
|
2021-10-12 12:30:16 -06:00
|
|
|
)
|
|
|
|
|
2021-10-17 11:00:57 -06:00
|
|
|
func main() {
|
2021-11-11 09:27:01 -07:00
|
|
|
config.ReadConfig()
|
2021-11-12 23:02:00 -07:00
|
|
|
var mpdConnectionError error
|
2022-09-14 09:12:28 -06:00
|
|
|
client.Conn, mpdConnectionError = mpd.Dial(utils.GetNetwork())
|
2021-11-12 23:02:00 -07:00
|
|
|
if mpdConnectionError != nil {
|
2021-12-31 03:18:58 -07:00
|
|
|
utils.Print("RED", "Could Not Connect to MPD Server\n")
|
|
|
|
utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n")
|
2021-11-12 23:02:00 -07:00
|
|
|
panic(mpdConnectionError)
|
2021-10-14 10:34:16 -06:00
|
|
|
}
|
2022-09-08 14:03:13 -06:00
|
|
|
Conn := client.Conn
|
|
|
|
defer Conn.Close()
|
2021-12-22 08:49:37 -07:00
|
|
|
|
2022-09-08 14:03:13 -06:00
|
|
|
ui.SetConnection(Conn)
|
2021-12-22 08:49:37 -07:00
|
|
|
|
2021-11-20 09:17:29 -07:00
|
|
|
cache.SetCacheDir(viper.GetString("CACHE_DIR"))
|
2021-12-24 03:07:21 -07:00
|
|
|
|
2022-09-01 13:55:33 -06:00
|
|
|
render.Rendr = render.NewRenderer()
|
2021-12-24 03:07:21 -07:00
|
|
|
// Connecting the Renderer to the Main UI
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.ConnectRenderer(render.Rendr)
|
2021-12-24 03:07:21 -07:00
|
|
|
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui = ui.NewApplication()
|
2021-12-24 03:07:21 -07:00
|
|
|
|
2022-09-08 14:03:13 -06:00
|
|
|
fileMap, err := Conn.ListAllInfo("/")
|
2021-12-31 03:18:58 -07:00
|
|
|
if err != nil {
|
|
|
|
utils.Print("RED", "Could Not Generate the File Map\n")
|
|
|
|
utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n")
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-12-24 03:07:21 -07:00
|
|
|
|
|
|
|
// Generating the Directory Tree for File Navigation.
|
2022-09-01 13:55:33 -06:00
|
|
|
client.DirTree = client.GenerateDirectoryTree(fileMap)
|
2021-10-17 11:00:57 -06:00
|
|
|
|
2021-12-31 03:18:58 -07:00
|
|
|
var Volume int64
|
|
|
|
var Random, Repeat bool
|
2022-09-08 14:01:51 -06:00
|
|
|
var SeekOffset = viper.GetInt("SEEK_OFFSET")
|
2022-09-08 14:18:05 -06:00
|
|
|
var SeekFunc = func(back bool) {
|
|
|
|
if status, err := Conn.Status(); err != nil {
|
|
|
|
notify.Notify.Send("Could not get MPD Status")
|
|
|
|
} else {
|
|
|
|
if status["state"] == "play" {
|
|
|
|
var stime time.Duration
|
|
|
|
if back {
|
|
|
|
stime = -1 * time.Second * time.Duration(SeekOffset)
|
|
|
|
} else {
|
|
|
|
stime = time.Second * time.Duration(SeekOffset)
|
|
|
|
}
|
|
|
|
if err := Conn.SeekCur(stime, true); err != nil {
|
|
|
|
notify.Notify.Send("Could Not Seek Forward in the Song")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-31 03:18:58 -07:00
|
|
|
|
2022-09-08 14:03:13 -06:00
|
|
|
if _v, err := Conn.Status(); err != nil {
|
2021-12-31 03:18:58 -07:00
|
|
|
utils.Print("RED", "Could Not Get the MPD Status\n")
|
|
|
|
panic(err)
|
|
|
|
} else {
|
|
|
|
// Setting Volume, Random and Repeat Values
|
|
|
|
Volume, _ = strconv.ParseInt(_v["volume"], 10, 64)
|
|
|
|
Random, _ = strconv.ParseBool(_v["random"])
|
|
|
|
Repeat, _ = strconv.ParseBool(_v["repeat"])
|
|
|
|
}
|
2021-10-17 11:00:57 -06:00
|
|
|
|
2021-12-23 07:50:27 -07:00
|
|
|
ArtistTree, err := client.GenerateArtistTree()
|
2021-12-31 03:18:58 -07:00
|
|
|
if err != nil {
|
|
|
|
utils.Print("RED", "Could Not Generate the ArtistTree\n")
|
|
|
|
utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n")
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-12-24 03:07:21 -07:00
|
|
|
|
|
|
|
// Used for Fuzzy Searching
|
2021-12-22 08:11:48 -07:00
|
|
|
ArtistTreeContent := utils.ConvertToArray(ArtistTree)
|
2021-12-24 03:07:21 -07:00
|
|
|
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify = notify.NewNotificationServer()
|
|
|
|
notify.Notify.Start()
|
2021-12-24 03:07:21 -07:00
|
|
|
|
2022-09-08 14:03:13 -06:00
|
|
|
if c, err := Conn.CurrentSong(); err != nil {
|
2022-08-03 16:02:58 -06:00
|
|
|
utils.Print("RED", "Could Not Retrieve the Current Song\n")
|
|
|
|
panic(err)
|
|
|
|
} else {
|
|
|
|
if len(c) != 0 {
|
2022-09-01 13:55:33 -06:00
|
|
|
render.Rendr.Start(c["file"])
|
2022-08-03 16:02:58 -06:00
|
|
|
} else {
|
2022-09-01 13:55:33 -06:00
|
|
|
render.Rendr.Start("stop")
|
2022-08-03 16:02:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-24 03:07:21 -07:00
|
|
|
// This Function Is Responsible for Changing the Focus it uses the Focus Map and Based on it Chooses
|
|
|
|
// the Draw Function
|
2022-09-13 10:34:39 -06:00
|
|
|
views.PView.StartWatcher()
|
2022-09-14 08:21:06 -06:00
|
|
|
views.SetCurrentView(&views.PView)
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.ExpandedView.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
|
|
|
views.GetCurrentView().Update(ui.Ui.ExpandedView)
|
|
|
|
return ui.Ui.ExpandedView.GetInnerRect()
|
2021-10-18 00:48:51 -06:00
|
|
|
})
|
|
|
|
|
2021-12-24 03:07:21 -07:00
|
|
|
// Function Maps is used For Mapping Keys According to the Value mapped to the Key the respective Function is called
|
|
|
|
// For e.g. in the config if the User Maps T to togglePlayBack then whenever in the input handler the T is received
|
|
|
|
// the respective function in this case togglePlayBack is called.
|
2021-12-22 08:11:48 -07:00
|
|
|
var FuncMap = map[string]func(){
|
2021-11-11 09:27:01 -07:00
|
|
|
"showChildrenContent": func() {
|
2022-08-31 12:12:15 -06:00
|
|
|
views.GetCurrentView().ShowChildrenContent()
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
|
|
|
"togglePlayBack": func() {
|
2021-12-31 03:18:58 -07:00
|
|
|
if err := client.TogglePlayBack(); err != nil {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Could not Toggle Play Back")
|
2021-12-31 03:18:58 -07:00
|
|
|
}
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
|
|
|
"showParentContent": func() {
|
2022-08-31 12:12:15 -06:00
|
|
|
views.GetCurrentView().ShowParentContent()
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
|
|
|
"nextSong": func() {
|
2022-09-08 14:03:13 -06:00
|
|
|
if err := Conn.Next(); err != nil {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Could not Select the Next Song")
|
2021-12-31 03:18:58 -07:00
|
|
|
}
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
|
|
|
"clearPlaylist": func() {
|
2022-09-08 14:03:13 -06:00
|
|
|
if err := Conn.Clear(); err != nil {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Could not Clear the Playlist")
|
2021-12-31 03:18:58 -07:00
|
|
|
} else {
|
2022-09-14 08:21:06 -06:00
|
|
|
if views.PView.Playlist, err = client.Conn.PlaylistInfo(-1, -1); err != nil {
|
|
|
|
utils.Print("RED", "Couldn't get the current Playlist.\n")
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
notify.Notify.Send("Playlist Cleared!")
|
2021-12-31 03:18:58 -07:00
|
|
|
}
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
|
|
|
"previousSong": func() {
|
2022-09-08 14:03:13 -06:00
|
|
|
if err := Conn.Previous(); err != nil {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Could Not Select the Previous Song")
|
2021-12-31 03:18:58 -07:00
|
|
|
}
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
|
|
|
"addToPlaylist": func() {
|
2022-08-31 12:12:15 -06:00
|
|
|
views.GetCurrentView().AddToPlaylist()
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
|
|
|
"toggleRandom": func() {
|
2022-09-08 14:03:13 -06:00
|
|
|
if err := Conn.Random(!Random); err == nil {
|
2021-11-11 09:27:01 -07:00
|
|
|
Random = !Random
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"toggleRepeat": func() {
|
2022-09-08 14:03:13 -06:00
|
|
|
if err := Conn.Repeat(!Repeat); err == nil {
|
2021-11-11 09:27:01 -07:00
|
|
|
Repeat = !Repeat
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"decreaseVolume": func() {
|
|
|
|
if Volume <= 0 {
|
|
|
|
Volume = 0
|
|
|
|
} else {
|
|
|
|
Volume -= 10
|
|
|
|
}
|
2022-09-08 14:03:13 -06:00
|
|
|
if err := Conn.SetVolume(int(Volume)); err != nil {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Could Not Decrease the Volume")
|
2021-12-31 03:18:58 -07:00
|
|
|
}
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
|
|
|
"increaseVolume": func() {
|
|
|
|
if Volume >= 100 {
|
|
|
|
Volume = 100
|
|
|
|
} else {
|
|
|
|
Volume += 10
|
|
|
|
}
|
2022-09-08 14:03:13 -06:00
|
|
|
if err := Conn.SetVolume(int(Volume)); err != nil {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Could Not Increase the Volume")
|
2021-12-31 03:18:58 -07:00
|
|
|
}
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
|
|
|
"navigateToFiles": func() {
|
2022-08-31 12:12:15 -06:00
|
|
|
views.SetCurrentView(views.FView)
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.Navbar.Select(1, 0)
|
|
|
|
views.FView.Update(ui.Ui.ExpandedView)
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
|
|
|
"navigateToPlaylist": func() {
|
2022-09-14 08:21:06 -06:00
|
|
|
views.SetCurrentView(&views.PView)
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.Navbar.Select(0, 0)
|
|
|
|
views.PView.Update(ui.Ui.ExpandedView)
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
|
|
|
"navigateToMostPlayed": func() {
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.Navbar.Select(2, 0)
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
2021-11-16 08:23:22 -07:00
|
|
|
"navigateToSearch": func() {
|
2022-08-31 12:12:15 -06:00
|
|
|
views.SetCurrentView(views.SView)
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.Navbar.Select(3, 0)
|
|
|
|
views.SView.Update(ui.Ui.ExpandedView)
|
2021-11-16 08:23:22 -07:00
|
|
|
},
|
2021-11-11 09:27:01 -07:00
|
|
|
"quit": func() {
|
2022-08-31 12:12:15 -06:00
|
|
|
views.GetCurrentView().Quit()
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
|
|
|
"stop": func() {
|
2022-09-08 14:03:13 -06:00
|
|
|
if err := Conn.Stop(); err != nil {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Could not Stop the Playback")
|
2021-12-31 03:18:58 -07:00
|
|
|
} else {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Playback Stopped")
|
2021-12-31 03:18:58 -07:00
|
|
|
}
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
|
|
|
"updateDB": func() {
|
2022-09-08 14:03:13 -06:00
|
|
|
_, err = Conn.Update("")
|
2021-11-11 09:27:01 -07:00
|
|
|
if err != nil {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Could Not Update the Database")
|
2021-12-31 03:18:58 -07:00
|
|
|
} else {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Database Updated")
|
2021-11-11 09:27:01 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"deleteSongFromPlaylist": func() {
|
2022-08-31 12:12:15 -06:00
|
|
|
views.GetCurrentView().DeleteSongFromPlaylist()
|
2021-11-11 09:27:01 -07:00
|
|
|
},
|
2021-11-15 04:02:59 -07:00
|
|
|
"FocusSearch": func() {
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.App.SetFocus(ui.Ui.SearchBar)
|
2021-11-15 04:02:59 -07:00
|
|
|
},
|
2021-12-25 11:48:23 -07:00
|
|
|
"FocusBuffSearch": func() {
|
2022-08-31 12:12:15 -06:00
|
|
|
views.GetCurrentView().FocusBuffSearchView()
|
2021-12-25 11:48:23 -07:00
|
|
|
},
|
2022-09-08 14:01:51 -06:00
|
|
|
"SeekForward": func() {
|
2022-09-08 14:18:05 -06:00
|
|
|
SeekFunc(false)
|
2022-09-08 14:01:51 -06:00
|
|
|
},
|
|
|
|
"SeekBackward": func() {
|
2022-09-08 14:18:05 -06:00
|
|
|
SeekFunc(true)
|
2022-09-08 14:01:51 -06:00
|
|
|
},
|
2021-11-11 09:27:01 -07:00
|
|
|
}
|
|
|
|
|
2021-12-24 03:07:21 -07:00
|
|
|
// Generating the Key Map Based on the Function Map Here Basically the Values will be flipped
|
|
|
|
// In the config if togglePlayBack is mapped to [ T , P, SPACE ] then here Basically we will receive a map
|
|
|
|
// for each event T, P, SPACE mapped to the same function togglePlayBack
|
2021-12-22 08:11:48 -07:00
|
|
|
config.GenerateKeyMap(FuncMap)
|
2021-11-16 08:23:22 -07:00
|
|
|
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.SearchBar.SetAutocompleteFunc(func(c string) []string {
|
2022-08-31 12:12:15 -06:00
|
|
|
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
2021-12-25 11:48:23 -07:00
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
if c != "" && c != " " && c != " " {
|
2022-09-01 13:55:33 -06:00
|
|
|
_, _, w, _ := ui.Ui.SearchBar.GetRect()
|
2021-12-25 11:48:23 -07:00
|
|
|
matches := fuzzy.Find(c, ArtistTreeContent)
|
|
|
|
var suggestions []string
|
|
|
|
for i, match := range matches {
|
|
|
|
if i == 10 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
suggestions = append(suggestions, utils.GetFormattedString(match.Str, w-2))
|
2021-11-15 04:02:59 -07:00
|
|
|
}
|
2021-12-25 11:48:23 -07:00
|
|
|
return suggestions
|
|
|
|
} else {
|
|
|
|
return make([]string, 0)
|
2021-11-15 04:02:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2021-11-16 08:23:22 -07:00
|
|
|
|
2021-12-24 03:07:21 -07:00
|
|
|
// Input Handler
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.ExpandedView.SetInputCapture(func(e *tcell.EventKey) *tcell.EventKey {
|
2021-11-11 11:00:40 -07:00
|
|
|
if val, ok := config.KEY_MAP[int(e.Rune())]; ok {
|
2021-12-22 08:11:48 -07:00
|
|
|
FuncMap[val]()
|
2021-11-11 11:00:40 -07:00
|
|
|
return nil
|
|
|
|
} else {
|
2022-08-31 12:12:15 -06:00
|
|
|
if views.GetCurrentView().GetViewName() == "PlaylistView" {
|
2022-04-05 12:02:29 -06:00
|
|
|
if e.Rune() == 'j' || e.Rune() == 'k' {
|
2022-09-08 14:03:13 -06:00
|
|
|
if p, err := Conn.PlaylistInfo(-1, -1); err != nil {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Error Getting PlaylistInfo")
|
2022-04-05 12:02:29 -06:00
|
|
|
} else {
|
|
|
|
if len(p) == 0 {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Empty Playlist")
|
2022-04-05 12:02:29 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-31 12:42:17 -06:00
|
|
|
} else if views.GetCurrentView().GetViewName() == "SearchView" {
|
|
|
|
if e.Rune() == 'j' || e.Rune() == 'k' {
|
2022-09-01 13:55:33 -06:00
|
|
|
if client.SearchContentSlice == nil || len(client.SearchContentSlice) == 0 {
|
|
|
|
notify.Notify.Send("No Search Results")
|
2022-08-31 12:42:17 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2022-04-05 12:02:29 -06:00
|
|
|
}
|
2021-11-11 11:00:40 -07:00
|
|
|
return e
|
2021-10-17 11:00:57 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.SearchBar.SetDoneFunc(func(e tcell.Key) {
|
2021-11-16 08:23:22 -07:00
|
|
|
if e == tcell.KeyEnter {
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.ExpandedView.Select(0, 0)
|
2022-08-31 12:12:15 -06:00
|
|
|
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.App.SetFocus(ui.Ui.ExpandedView)
|
2021-12-25 11:48:23 -07:00
|
|
|
} else {
|
2022-08-31 12:12:15 -06:00
|
|
|
views.SetCurrentView(views.SView)
|
2022-09-01 13:55:33 -06:00
|
|
|
client.SearchContentSlice = nil
|
|
|
|
client.SearchContentSlice, err = client.GenerateContentSlice(ui.Ui.SearchBar.GetText())
|
2021-12-25 11:48:23 -07:00
|
|
|
if err != nil {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Could Not Retrieve the Results")
|
2021-12-25 11:48:23 -07:00
|
|
|
} else {
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.SearchBar.SetText("")
|
|
|
|
ui.Ui.App.SetFocus(ui.Ui.ExpandedView)
|
|
|
|
ui.Ui.Navbar.Select(3, 0)
|
2021-12-25 11:48:23 -07:00
|
|
|
}
|
2021-11-16 08:23:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if e == tcell.KeyEscape {
|
2022-09-06 23:57:20 -06:00
|
|
|
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
2022-09-01 13:55:33 -06:00
|
|
|
client.Matches = nil
|
2021-12-25 11:48:23 -07:00
|
|
|
}
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.SearchBar.SetText("")
|
|
|
|
ui.Ui.App.SetFocus(ui.Ui.ExpandedView)
|
2021-11-16 08:23:22 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.ExpandedView.SetDoneFunc(func(e tcell.Key) {
|
2021-12-26 06:53:58 -07:00
|
|
|
if e == tcell.KeyEscape {
|
2022-08-31 12:12:15 -06:00
|
|
|
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
|
|
|
views.SetCurrentView(views.FView)
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.SearchBar.SetText("")
|
|
|
|
client.Matches = nil
|
2021-12-26 06:53:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.SearchBar.SetChangedFunc(func(text string) {
|
2022-08-31 12:12:15 -06:00
|
|
|
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
2022-09-01 13:55:33 -06:00
|
|
|
var f client.FileNodes = client.DirTree.Children
|
|
|
|
client.Matches = fuzzy.FindFrom(text, f)
|
|
|
|
views.BuffSView.Update(ui.Ui.ExpandedView)
|
2021-12-25 11:48:23 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-10-17 11:00:57 -06:00
|
|
|
go func() {
|
|
|
|
for {
|
2022-10-07 15:21:22 -06:00
|
|
|
ui.Ui.App.Draw()
|
2021-10-17 11:00:57 -06:00
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2022-09-01 13:55:33 -06:00
|
|
|
if err := ui.Ui.App.Run(); err != nil {
|
2021-10-12 12:30:16 -06:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|