mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-28 13:48:53 +08:00
add variable dimension to timedPopup
This commit is contained in:
parent
77c8c7615b
commit
8e3515f19c
@ -83,7 +83,7 @@ func (p *Player) Run(currSong *AudioFile) {
|
|||||||
|
|
||||||
popupMessage := fmt.Sprintf("%s\n\n[ %s ]", currSong.Name, fmtDuration(p.length))
|
popupMessage := fmt.Sprintf("%s\n\n[ %s ]", currSong.Name, fmtDuration(p.length))
|
||||||
|
|
||||||
timedPopup(" Current Song ", popupMessage, getPopupTimeout())
|
timedPopup(" Current Song ", popupMessage, getPopupTimeout(), 0, 0)
|
||||||
|
|
||||||
done := make(chan bool, 1)
|
done := make(chan bool, 1)
|
||||||
|
|
||||||
|
24
playlist.go
24
playlist.go
@ -121,11 +121,11 @@ func NewPlaylist() *Playlist {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
timedPopup(
|
timedPopup(
|
||||||
" Error ",
|
" Error ",
|
||||||
"Unable to delete dir "+selectedDir.Name, getPopupTimeout())
|
"Unable to delete dir "+selectedDir.Name, getPopupTimeout(), 0, 0)
|
||||||
} else {
|
} else {
|
||||||
timedPopup(
|
timedPopup(
|
||||||
" Success ",
|
" Success ",
|
||||||
selectedDir.Name+"\nhas been deleted successfully", getPopupTimeout())
|
selectedDir.Name+"\nhas been deleted successfully", getPopupTimeout(), 0, 0)
|
||||||
|
|
||||||
playlist.Refresh()
|
playlist.Refresh()
|
||||||
}
|
}
|
||||||
@ -155,11 +155,11 @@ func NewPlaylist() *Playlist {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
timedPopup(
|
timedPopup(
|
||||||
" Error ", "Unable to delete "+audioFile.Name, getPopupTimeout())
|
" Error ", "Unable to delete "+audioFile.Name, getPopupTimeout(), 0, 0)
|
||||||
} else {
|
} else {
|
||||||
timedPopup(
|
timedPopup(
|
||||||
" Success ",
|
" Success ",
|
||||||
audioFile.Name+"\nhas been deleted successfully", getPopupTimeout())
|
audioFile.Name+"\nhas been deleted successfully", getPopupTimeout(), 0, 0)
|
||||||
|
|
||||||
playlist.Refresh()
|
playlist.Refresh()
|
||||||
}
|
}
|
||||||
@ -260,7 +260,8 @@ func populate(root *tview.TreeNode, rootPath string) {
|
|||||||
|
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
child := tview.NewTreeNode(GetName(file.Name()))
|
songName := GetName(file.Name())
|
||||||
|
child := tview.NewTreeNode(songName)
|
||||||
|
|
||||||
if !file.IsDir() {
|
if !file.IsDir() {
|
||||||
|
|
||||||
@ -284,7 +285,7 @@ func populate(root *tview.TreeNode, rootPath string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
audioFile := &AudioFile{
|
audioFile := &AudioFile{
|
||||||
Name: file.Name(),
|
Name: songName,
|
||||||
Path: path,
|
Path: path,
|
||||||
IsAudioFile: true,
|
IsAudioFile: true,
|
||||||
Length: audioLength,
|
Length: audioLength,
|
||||||
@ -298,7 +299,7 @@ func populate(root *tview.TreeNode, rootPath string) {
|
|||||||
if file.IsDir() {
|
if file.IsDir() {
|
||||||
|
|
||||||
audioFile := &AudioFile{
|
audioFile := &AudioFile{
|
||||||
Name: file.Name(),
|
Name: songName,
|
||||||
Path: path,
|
Path: path,
|
||||||
IsAudioFile: false,
|
IsAudioFile: false,
|
||||||
Length: 0,
|
Length: 0,
|
||||||
@ -495,7 +496,7 @@ func Ytdl(url string, selPlaylist *tview.TreeNode) {
|
|||||||
_, err := exec.LookPath("youtube-dl")
|
_, err := exec.LookPath("youtube-dl")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
timedPopup(" Error ", "youtube-dl is not in your $PATH", getPopupTimeout())
|
timedPopup(" Error ", "youtube-dl is not in your $PATH", getPopupTimeout(), 0, 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,7 +505,7 @@ func Ytdl(url string, selPlaylist *tview.TreeNode) {
|
|||||||
selAudioFile := selPlaylist.GetReference().(*AudioFile)
|
selAudioFile := selPlaylist.GetReference().(*AudioFile)
|
||||||
selPlaylistName := selAudioFile.Name
|
selPlaylistName := selAudioFile.Name
|
||||||
|
|
||||||
timedPopup(" Ytdl ", "Downloading", getPopupTimeout())
|
timedPopup(" Ytdl ", "Downloading", getPopupTimeout(), 0, 0)
|
||||||
|
|
||||||
// specify the output path for ytdl
|
// specify the output path for ytdl
|
||||||
outputDir := fmt.Sprintf(
|
outputDir := fmt.Sprintf(
|
||||||
@ -530,7 +531,7 @@ func Ytdl(url string, selPlaylist *tview.TreeNode) {
|
|||||||
|
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
timedPopup(" Error ", "Error running youtube-dl", getPopupTimeout())
|
timedPopup(" Error ", "Error running youtube-dl", getPopupTimeout(), 0, 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -551,8 +552,7 @@ func Ytdl(url string, selPlaylist *tview.TreeNode) {
|
|||||||
timedPopup(
|
timedPopup(
|
||||||
" Ytdl ",
|
" Ytdl ",
|
||||||
downloadFinishedMessage,
|
downloadFinishedMessage,
|
||||||
getPopupTimeout(),
|
getPopupTimeout(), 0, 0)
|
||||||
)
|
|
||||||
|
|
||||||
gomu.App.Draw()
|
gomu.App.Draw()
|
||||||
|
|
||||||
|
17
popup.go
17
popup.go
@ -71,7 +71,12 @@ func topRight(p tview.Primitive, width, height int) tview.Primitive {
|
|||||||
AddItem(nil, 0, 1, false)
|
AddItem(nil, 0, 1, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func timedPopup(title string, desc string, timeout time.Duration) {
|
func timedPopup(title string, desc string, timeout time.Duration, width, height int) {
|
||||||
|
|
||||||
|
if width == 0 && height == 0 {
|
||||||
|
width = 70
|
||||||
|
height = 7
|
||||||
|
}
|
||||||
|
|
||||||
textView := tview.NewTextView().
|
textView := tview.NewTextView().
|
||||||
SetText(desc).
|
SetText(desc).
|
||||||
@ -79,13 +84,13 @@ func timedPopup(title string, desc string, timeout time.Duration) {
|
|||||||
|
|
||||||
textView.SetTextAlign(tview.AlignCenter).SetBackgroundColor(gomu.PopupBg)
|
textView.SetTextAlign(tview.AlignCenter).SetBackgroundColor(gomu.PopupBg)
|
||||||
|
|
||||||
box := tview.NewFrame(textView).SetBorders(1, 1, 1, 1, 1, 1)
|
box := tview.NewFrame(textView).SetBorders(1, 0, 0, 0, 0, 0)
|
||||||
box.SetTitle(title).SetBorder(true).SetBackgroundColor(gomu.PopupBg)
|
box.SetTitle(title).SetBorder(true).SetBackgroundColor(gomu.PopupBg)
|
||||||
|
|
||||||
popupId := fmt.Sprintf("%s %d", "timeout-popup", popupCounter)
|
popupId := fmt.Sprintf("%s %d", "timeout-popup", popupCounter)
|
||||||
popupCounter++
|
popupCounter++
|
||||||
|
|
||||||
gomu.Pages.AddPage(popupId, topRight(box, 70, 7), true, true)
|
gomu.Pages.AddPage(popupId, topRight(box, width, height), true, true)
|
||||||
gomu.App.SetFocus(gomu.PrevPanel.(tview.Primitive))
|
gomu.App.SetFocus(gomu.PrevPanel.(tview.Primitive))
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -106,7 +111,7 @@ func volumePopup(volume float64) {
|
|||||||
"50",
|
"50",
|
||||||
)
|
)
|
||||||
|
|
||||||
timedPopup(" Volume ", progress, getPopupTimeout())
|
timedPopup(" Volume ", progress, getPopupTimeout(), 0, 0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,8 +128,8 @@ func helpPopup() {
|
|||||||
"l add song to queue",
|
"l add song to queue",
|
||||||
"L add playlist to queue",
|
"L add playlist to queue",
|
||||||
"h close node in playlist",
|
"h close node in playlist",
|
||||||
"d remove from queue",
|
"d delete song/remove from queue",
|
||||||
"D delete playlist",
|
"D delete playlist/clear queue",
|
||||||
"+ volume up",
|
"+ volume up",
|
||||||
"- volume down",
|
"- volume down",
|
||||||
"? toggle help",
|
"? toggle help",
|
||||||
|
13
queue.go
13
queue.go
@ -72,7 +72,7 @@ func (q *Queue) UpdateTitle() {
|
|||||||
|
|
||||||
fmtTime := fmtDuration(totalLength)
|
fmtTime := fmtDuration(totalLength)
|
||||||
|
|
||||||
q.SetTitle(fmt.Sprintf("┤ Queue ├──┤%s├", fmtTime))
|
q.SetTitle(fmt.Sprintf("┤ Queue ├──┤%d|%s├", len(q.Items), fmtTime))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,6 +266,17 @@ func NewQueue() *Queue {
|
|||||||
queue.DeleteItem(queue.GetCurrentItem())
|
queue.DeleteItem(queue.GetCurrentItem())
|
||||||
case 'D':
|
case 'D':
|
||||||
queue.ClearQueue()
|
queue.ClearQueue()
|
||||||
|
case 'z':
|
||||||
|
isLoop := gomu.Player.ToggleLoop()
|
||||||
|
var msg string
|
||||||
|
|
||||||
|
if isLoop {
|
||||||
|
msg = "on"
|
||||||
|
} else {
|
||||||
|
msg = "off"
|
||||||
|
}
|
||||||
|
|
||||||
|
timedPopup("Loop", msg, getPopupTimeout(), 30, 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user