🚸 Add main menu
This commit is contained in:
parent
5b2896c032
commit
d8e671d5ca
4 changed files with 83 additions and 28 deletions
69
app/menu.go
Normal file
69
app/menu.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"codeberg.org/danjones000/strip-beats/input/list"
|
||||
)
|
||||
|
||||
func (st AppStep) Title() string {
|
||||
mustpick := "You need to pick a file"
|
||||
switch st {
|
||||
case Pick:
|
||||
return "Pick a new show"
|
||||
case Watch:
|
||||
if file == nil {
|
||||
return mustpick
|
||||
}
|
||||
return fmt.Sprintf("Watch %s", file.ShortPath())
|
||||
case Fade:
|
||||
if file == nil {
|
||||
return mustpick
|
||||
}
|
||||
return fmt.Sprintf("Trim and/or add fade to %s", file.ShortPath())
|
||||
case Restart:
|
||||
return "Forget current selection"
|
||||
case Quit:
|
||||
return "Quit"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (st AppStep) Text() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (st AppStep) Rune() rune {
|
||||
switch st {
|
||||
case Pick:
|
||||
return 'p'
|
||||
case Watch:
|
||||
return 'w'
|
||||
case Fade:
|
||||
return 'f'
|
||||
case Restart:
|
||||
return 'r'
|
||||
case Quit:
|
||||
return 'q'
|
||||
default:
|
||||
return '0'
|
||||
}
|
||||
}
|
||||
|
||||
func (st AppStep) Selected() func() {
|
||||
return nil
|
||||
}
|
||||
|
||||
func mainMenu() AppStep {
|
||||
var steps []list.Option
|
||||
if file == nil {
|
||||
steps = []list.Option{Pick, Quit}
|
||||
} else {
|
||||
steps = []list.Option{Pick, Watch, Fade, Quit}
|
||||
}
|
||||
|
||||
step := list.List("What would you like to do next?", steps, nil)
|
||||
|
||||
return step.(AppStep)
|
||||
}
|
||||
13
app/run.go
13
app/run.go
|
|
@ -13,6 +13,7 @@ type AppStep int
|
|||
const (
|
||||
Pick AppStep = iota
|
||||
Watch
|
||||
Fade
|
||||
Restart
|
||||
Quit
|
||||
)
|
||||
|
|
@ -39,7 +40,6 @@ func testTrim() {
|
|||
}
|
||||
|
||||
func Run(step AppStep) {
|
||||
testTrim()
|
||||
for step < Quit {
|
||||
switch step {
|
||||
case Pick:
|
||||
|
|
@ -51,12 +51,21 @@ func Run(step AppStep) {
|
|||
watch := boolean.Choose(fmt.Sprintf("Would you like to watch %s?", file.ShortPath()))
|
||||
if watch {
|
||||
step = Watch
|
||||
} else {
|
||||
step = mainMenu()
|
||||
}
|
||||
case Watch:
|
||||
media.Watch(file.Format.Path)
|
||||
step = Quit // @todo
|
||||
fade := boolean.Choose(fmt.Sprintf("Would you like to trim/fade %s?", file.ShortPath()))
|
||||
if fade {
|
||||
step = Fade
|
||||
} else {
|
||||
step = mainMenu()
|
||||
}
|
||||
case Quit:
|
||||
quit()
|
||||
default:
|
||||
step = mainMen()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
cmd/root.go
23
cmd/root.go
|
|
@ -8,7 +8,6 @@ import (
|
|||
"os"
|
||||
|
||||
"codeberg.org/danjones000/strip-beats/app"
|
||||
// "codeberg.org/danjones000/strip-beats/input/list"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
|
@ -20,28 +19,6 @@ var rootCmd = &cobra.Command{
|
|||
// has an action associated with it:
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
app.Run(0)
|
||||
/*
|
||||
opt := list.List([]list.Option{
|
||||
list.SimpleItem("Yes", "", 'y'),
|
||||
list.SimpleItem("No", "", 'n'),
|
||||
list.SimpleItem("Maybe", "perhaps", 'm'),
|
||||
}, nil)
|
||||
fmt.Printf("%+v\n", opt)
|
||||
// out := app.PickFileWithConf()
|
||||
out := app.SetFile("/home/drj/nothing.mkv")
|
||||
fmt.Println("first", out.Format.Path)
|
||||
// tmp, _ := os.CreateTemp("", "audio.*.mka")
|
||||
// defer os.Remove(tmp.Name())
|
||||
// fmt.Println("temp", tmp.Name())
|
||||
app.Finish()
|
||||
fmt.Printf("%+v\n", out)
|
||||
// media.Watch(out.Format.Path)
|
||||
show := boolean.Choose("Show stream?")
|
||||
if show {
|
||||
stream := out.WantedAudioStream()
|
||||
fmt.Printf("Stream %d of %s: %+v\n", stream.Index, out.Format.Path, stream)
|
||||
}
|
||||
*/
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func SimpleItem(title, text string, char rune) Option {
|
|||
return opt{title, text, char}
|
||||
}
|
||||
|
||||
func List(items []Option, cb func(*tview.List)) Option {
|
||||
func List(title string, items []Option, cb func(*tview.List)) Option {
|
||||
if len(items) == 0 {
|
||||
return opt{}
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ func List(items []Option, cb func(*tview.List)) Option {
|
|||
for _, item := range items {
|
||||
list.AddItem(item.Title(), item.Text(), item.Rune(), item.Selected())
|
||||
}
|
||||
list.Box.SetBorder(true) //.SetTitle(title)
|
||||
list.Box.SetBorder(true).SetTitle(title)
|
||||
|
||||
if cb != nil {
|
||||
cb(list)
|
||||
|
|
@ -58,7 +58,7 @@ func List(items []Option, cb func(*tview.List)) Option {
|
|||
app.Stop()
|
||||
})
|
||||
|
||||
if err := app.SetRoot(list, false).EnableMouse(true).Run(); err != nil {
|
||||
if err := app.SetRoot(list, true).EnableMouse(true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue