mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-25 13:48:49 +08:00
move variables into modules
This commit is contained in:
parent
fbd59e7d30
commit
d24a47e351
24
colors.go
24
colors.go
@ -17,12 +17,12 @@ type Colors struct {
|
||||
func newColor() *Colors {
|
||||
|
||||
defaultColors := map[string]string{
|
||||
"color_accent": "#008B8B",
|
||||
"color_foreground": "#FFFFFF",
|
||||
"color_background": "none",
|
||||
"color_popup": "#0A0F14",
|
||||
"color_now_playing_title": "#017702",
|
||||
"color_playlist": "#008B8B",
|
||||
"Color.accent": "#008B8B",
|
||||
"Color.foreground": "#FFFFFF",
|
||||
"Color.background": "none",
|
||||
"Color.popup": "#0A0F14",
|
||||
"Color.now_playing_title": "#017702",
|
||||
"Color.playlist": "#008B8B",
|
||||
}
|
||||
|
||||
anko := gomu.anko
|
||||
@ -42,7 +42,7 @@ func newColor() *Colors {
|
||||
|
||||
// handle none background color
|
||||
var bgColor tcell.Color
|
||||
bg := anko.GetString("color_background")
|
||||
bg := anko.GetString("Color.background")
|
||||
|
||||
if bg == "none" {
|
||||
bgColor = tcell.ColorDefault
|
||||
@ -50,11 +50,11 @@ func newColor() *Colors {
|
||||
bgColor = tcell.GetColor(bg)
|
||||
}
|
||||
|
||||
accent := anko.GetString("color_accent")
|
||||
foreground := anko.GetString("color_foreground")
|
||||
popup := anko.GetString("color_popup")
|
||||
title := anko.GetString("color_now_playing_title")
|
||||
playlist := anko.GetString("color_playlist")
|
||||
accent := anko.GetString("Color.accent")
|
||||
foreground := anko.GetString("Color.foreground")
|
||||
popup := anko.GetString("Color.popup")
|
||||
title := anko.GetString("Color.now_playing_title")
|
||||
playlist := anko.GetString("Color.playlist")
|
||||
|
||||
color := &Colors{
|
||||
accent: tcell.GetColor(accent),
|
||||
|
@ -205,7 +205,7 @@ func (c Command) defineCommands() {
|
||||
|
||||
c.define("bulk_add", func() {
|
||||
currNode := gomu.playlist.GetCurrentNode()
|
||||
bulkAdd := anko.GetBool("confirm_bulk_add")
|
||||
bulkAdd := anko.GetBool("General.confirm_bulk_add")
|
||||
|
||||
if !bulkAdd {
|
||||
gomu.playlist.addAllToQueue(currNode)
|
||||
@ -331,7 +331,7 @@ func (c Command) defineCommands() {
|
||||
/* Global */
|
||||
c.define("quit", func() {
|
||||
|
||||
confirmOnExit := anko.GetBool("confirm_on_exit")
|
||||
confirmOnExit := anko.GetBool("General.confirm_on_exit")
|
||||
|
||||
if !confirmOnExit {
|
||||
err := gomu.quit(gomu.args)
|
||||
|
@ -37,7 +37,7 @@ type Player struct {
|
||||
|
||||
func newPlayer() *Player {
|
||||
|
||||
volume := gomu.anko.GetInt("volume")
|
||||
volume := gomu.anko.GetInt("General.volume")
|
||||
// Read initial volume from config
|
||||
initVol := absVolume(volume)
|
||||
|
||||
|
12
playlist.go
12
playlist.go
@ -74,7 +74,7 @@ func newPlaylist(args Args) *Playlist {
|
||||
|
||||
anko := gomu.anko
|
||||
|
||||
m := anko.GetString("music_dir")
|
||||
m := anko.GetString("General.music_dir")
|
||||
rootDir, err := filepath.Abs(expandTilde(m))
|
||||
if err != nil {
|
||||
err = tracerr.Errorf("unable to find music directory: %e", err)
|
||||
@ -88,11 +88,11 @@ func newPlaylist(args Args) *Playlist {
|
||||
|
||||
var rootTextView string
|
||||
|
||||
useEmoji := anko.GetBool("use_emoji")
|
||||
useEmoji := anko.GetBool("General.use_emoji")
|
||||
|
||||
if useEmoji {
|
||||
|
||||
emojiPlaylist := anko.GetString("emoji_playlist")
|
||||
emojiPlaylist := anko.GetString("Emoji.playlist")
|
||||
rootTextView = fmt.Sprintf("%s %s", emojiPlaylist, path.Base(rootDir))
|
||||
|
||||
} else {
|
||||
@ -581,7 +581,7 @@ func ytdl(url string, selPlaylist *tview.TreeNode) error {
|
||||
playlistPath := dir
|
||||
audioPath := extractFilePath(stdout.Bytes(), playlistPath)
|
||||
|
||||
historyPath := gomu.anko.GetString("history_path")
|
||||
historyPath := gomu.anko.GetString("General.history_path")
|
||||
|
||||
err = appendFile(expandTilde(historyPath), url+"\n")
|
||||
if err != nil {
|
||||
@ -738,12 +738,12 @@ func (p *Playlist) paste() error {
|
||||
}
|
||||
|
||||
func setDisplayText(songName string) string {
|
||||
useEmoji := gomu.anko.GetBool("use_emoji")
|
||||
useEmoji := gomu.anko.GetBool("General.use_emoji")
|
||||
if !useEmoji {
|
||||
return songName
|
||||
}
|
||||
|
||||
emojiFile := gomu.anko.GetString("emoji_file")
|
||||
emojiFile := gomu.anko.GetString("Emoji.file")
|
||||
return fmt.Sprintf(" %s %s", emojiFile, songName)
|
||||
}
|
||||
|
||||
|
2
popup.go
2
popup.go
@ -67,7 +67,7 @@ func (s *Stack) pop() tview.Primitive {
|
||||
// Gets popup timeout from config file
|
||||
func getPopupTimeout() time.Duration {
|
||||
|
||||
dur := gomu.anko.GetString("popup_timeout")
|
||||
dur := gomu.anko.GetString("General.popup_timeout")
|
||||
m, err := time.ParseDuration(dur)
|
||||
|
||||
if err != nil {
|
||||
|
6
queue.go
6
queue.go
@ -97,17 +97,17 @@ func (q *Queue) updateTitle() string {
|
||||
|
||||
var loop string
|
||||
|
||||
isEmoji := gomu.anko.GetBool("use_emoji")
|
||||
isEmoji := gomu.anko.GetBool("General.use_emoji")
|
||||
|
||||
if q.isLoop {
|
||||
if isEmoji {
|
||||
loop = gomu.anko.GetString("emoji_loop")
|
||||
loop = gomu.anko.GetString("Emoji.loop")
|
||||
} else {
|
||||
loop = "Loop"
|
||||
}
|
||||
} else {
|
||||
if isEmoji {
|
||||
loop = gomu.anko.GetString("emoji_noloop")
|
||||
loop = gomu.anko.GetString("Emoji.noloop")
|
||||
} else {
|
||||
loop = "No loop"
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ func getRequest(url string, v interface{}) error {
|
||||
func getSearchResult(query string) ([]YoutubeVideo, error) {
|
||||
|
||||
query = url.QueryEscape(query)
|
||||
domain := gomu.anko.GetString("invidious_instance")
|
||||
domain := gomu.anko.GetString("General.invidious_instance")
|
||||
|
||||
targetUrl := domain + `/api/v1/search?q=` + query
|
||||
yt := []YoutubeVideo{}
|
||||
|
80
start.go
80
start.go
@ -68,43 +68,51 @@ func execConfig(config string) error {
|
||||
|
||||
const defaultConfig = `
|
||||
|
||||
// confirmation popup to add the whole playlist to the queue
|
||||
confirm_bulk_add = true
|
||||
confirm_on_exit = true
|
||||
queue_loop = false
|
||||
load_prev_queue = true
|
||||
popup_timeout = "5s"
|
||||
// change this to directory that contains mp3 files
|
||||
music_dir = "~/music"
|
||||
// url history of downloaded audio will be saved here
|
||||
history_path = "~/.local/share/gomu/urls"
|
||||
// some of the terminal supports unicode character
|
||||
// you can set this to true to enable emojis
|
||||
use_emoji = true
|
||||
// initial volume when gomu starts up
|
||||
volume = 80
|
||||
// if you experiencing error using this invidious instance, you can change it
|
||||
// to another instance from this list:
|
||||
// https://github.com/iv-org/documentation/blob/master/Invidious-Instances.md
|
||||
invidious_instance = "https://vid.puffyan.us"
|
||||
module General {
|
||||
# confirmation popup to add the whole playlist to the queue
|
||||
confirm_bulk_add = true
|
||||
confirm_on_exit = true
|
||||
queue_loop = false
|
||||
load_prev_queue = true
|
||||
popup_timeout = "5s"
|
||||
# change this to directory that contains mp3 files
|
||||
music_dir = "~/Music"
|
||||
# url history of downloaded audio will be saved here
|
||||
history_path = "~/.local/share/gomu/urls"
|
||||
# some of the terminal supports unicode character
|
||||
# you can set this to true to enable emojis
|
||||
use_emoji = true
|
||||
# initial volume when gomu starts up
|
||||
volume = 80
|
||||
# if you experiencing error using this invidious instance, you can change it
|
||||
# to another instance from this list:
|
||||
# https://github.com/iv-org/documentation/blob/master/Invidious-Instances.md
|
||||
invidious_instance = "https://vid.puffyan.us"
|
||||
}
|
||||
|
||||
// default emoji here is using awesome-terminal-fonts
|
||||
// you can change these to your liking
|
||||
emoji_playlist = ""
|
||||
emoji_file = ""
|
||||
emoji_loop = "ﯩ"
|
||||
emoji_noloop = ""
|
||||
module Emoji {
|
||||
# default emoji here is using awesome-terminal-fonts
|
||||
# you can change these to your liking
|
||||
playlist = ""
|
||||
file = ""
|
||||
loop = "ﯩ"
|
||||
noloop = ""
|
||||
}
|
||||
|
||||
// not all colors can be reproducible in terminal
|
||||
// changing hex colors may or may not produce expected result
|
||||
color_accent = "#008B8B"
|
||||
color_background = "none"
|
||||
color_foreground = "#FFFFFF"
|
||||
color_now_playing_title = "#017702"
|
||||
color_playlist = "#008B8B"
|
||||
color_popup = "#0A0F14"
|
||||
module Color {
|
||||
# not all colors can be reproducible in terminal
|
||||
# changing hex colors may or may not produce expected result
|
||||
accent = "#008B8B"
|
||||
background = "none"
|
||||
foreground = "#FFFFFF"
|
||||
now_playing_title = "#017702"
|
||||
playlist = "#008B8B"
|
||||
popup = "#0A0F14"
|
||||
}
|
||||
|
||||
// vim: syntax=go
|
||||
# you can get the syntax highlighting for this language here:
|
||||
# https://github.com/mattn/anko/tree/master/misc/vim
|
||||
# vim: ft=anko
|
||||
`
|
||||
|
||||
cfg := expandTilde(config)
|
||||
@ -190,12 +198,12 @@ func start(application *tview.Application, args Args) {
|
||||
|
||||
gomu.playingBar.setDefault()
|
||||
|
||||
isQueueLoop := gomu.anko.GetBool("queue_loop")
|
||||
isQueueLoop := gomu.anko.GetBool("General.queue_loop")
|
||||
|
||||
gomu.player.isLoop = isQueueLoop
|
||||
gomu.queue.isLoop = gomu.player.isLoop
|
||||
|
||||
loadQueue := gomu.anko.GetBool("load_prev_queue")
|
||||
loadQueue := gomu.anko.GetBool("General.load_prev_queue")
|
||||
|
||||
if !*args.empty && loadQueue {
|
||||
// load saved queue from previous session
|
||||
|
Loading…
x
Reference in New Issue
Block a user