Skip to content

Commit

Permalink
[style]<main>: add config home option (#15)
Browse files Browse the repository at this point in the history
Signed-off-by: o98k-ok <hggend@gmail.com>
  • Loading branch information
o98k-ok authored Mar 13, 2024
1 parent a2d1b96 commit 8f2f154
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
17 changes: 13 additions & 4 deletions cmd/terminal/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"

tea "github.com/charmbracelet/bubbletea"
Expand All @@ -9,12 +10,20 @@ import (
"github.com/o98k-ok/voice/internal/ui"
)

const (
ROOT = "./data"
)
type Options struct {
RootPath string
}

func options() *Options {
var option Options
flag.StringVar(&option.RootPath, "home", "./data", "voice working home path[must exist]")

flag.Parse()
return &option
}

func main() {
localIndex := storage.NewLocalFileStorage(ROOT)
localIndex := storage.NewLocalFileStorage(options().RootPath)
player := player.NewVoicePlayer(48000)
player.InitPlayList(localIndex)
player.Run()
Expand Down
Binary file removed data/screenshot.jpg
Binary file not shown.
Binary file removed data/voice.png
Binary file not shown.
4 changes: 4 additions & 0 deletions internal/storage/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type LocalFileStorage struct {
}

func NewLocalFileStorage(root string) *LocalFileStorage {
if _, err := os.Stat(root); err != nil {
panic(err)
}

return &LocalFileStorage{
Root: root,
}
Expand Down
4 changes: 3 additions & 1 deletion internal/ui/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ func (hl *HistoryList) MsgKeyBindings() map[string]map[string]func(interface{})
}

hl.list.table.Focus()
hl.list.ResetList(hl.fechByBvID(hl.player.CurrentElem.Value.(*music.Music).BvID, 10))
if hl.player.CurrentElem != nil {
hl.list.ResetList(hl.fechByBvID(hl.player.CurrentElem.Value.(*music.Music).BvID, 10))
}
hl.list.table.SetCursor(hl.current)
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewInputElem(player *player.VoicePlayer, storage storage.Storage, headers [
logo: &LogoElem{},
result: NewListElem(headers, widths, nil),
fetcher: bilibili.NewBlibliFetcher(netutil.NewHttpClient()),
mconvertor: convertor.NewAfconvertConvertor("./data"),
mconvertor: convertor.NewAfconvertConvertor(storage.GetRootPath()),
fetcherIdx: 1,
storage: storage,
player: player,
Expand Down

0 comments on commit 8f2f154

Please sign in to comment.