Skip to content

Commit

Permalink
remove some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Grantley Cullar authored and Grantley Cullar committed Nov 11, 2022
1 parent b6f6a58 commit 09f89b9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
6 changes: 1 addition & 5 deletions internal/filepath.go
Expand Up @@ -23,22 +23,19 @@ import (
"github.com/spf13/viper"
)

// Create new json file that stores filepath
// Get new filepath from user then store it in json config file
func NewFilepath(newPath string) {
vp := viper.New()

// get user's home directory
home, err := os.UserHomeDir()
if err != nil {
fmt.Println(err)
}

// stub init
configHome := home
configName := "config"
configType := "json"
configPath := filepath.Join(configHome, configName+"."+configType)
// ----

vp.AddConfigPath(configHome)
vp.SetConfigName(configName)
Expand All @@ -51,7 +48,6 @@ func NewFilepath(newPath string) {
}
}

// Reading config file
err1 := vp.ReadInConfig()
if err1 != nil {
fmt.Print()
Expand Down
13 changes: 3 additions & 10 deletions internal/menu.go
Expand Up @@ -29,7 +29,6 @@ import (

// Returns true if filename is a supported format
func isAudioFile(filename string) bool {
// convert filename to lowercase to include uppercase extensions (i.e. "filename.MP3")
filename = strings.ToLower(filename)

for _, ext := range []string{".wav", ".mp3", ".ogg", ".flac"} {
Expand All @@ -40,43 +39,38 @@ func isAudioFile(filename string) bool {
return false
}

// Increase the length of the list to fit all items until 10 items
func DynamicHeight(items []string) int {
if len(items) >= 10 {
return 12
}
return len(items)+2
}

// Menu list all the audio files from the path set from newpath
// Menu list all the audio files from the path set from newpath then play the selected file
func Menu() {
// init viper
vp := viper.New()

// get user's home directory
home, err := os.UserHomeDir()
if err != nil {
fmt.Println(err)
}

// set target config file
vp.SetConfigName("config")
vp.SetConfigType("json")
vp.AddConfigPath(home)

// Reading config file
err1 := vp.ReadInConfig()
if err1 != nil {
fmt.Println("Error: Cannot read config file")
}

// Read
path, err := os.ReadDir(vp.GetString("path"))
if err != nil {
fmt.Println("No filepath detected, to add new filepath run: lunar newpath")
os.Exit(1)
}

// get widget theme
TitleThemeColor := vp.GetInt("titlethemecolor")
BorderThemeColor := vp.GetInt("borderthemecolor")
SelectedRowThemeColor := vp.GetInt("SelectedRowThemeColor")
Expand All @@ -89,7 +83,6 @@ func Menu() {

var items []string

// Get file names in folder
for _, f := range path {
if isAudioFile(f.Name()) {
items = append(items, f.Name())
Expand Down Expand Up @@ -123,7 +116,7 @@ func Menu() {
l.ScrollDown()
case "<Up>":
l.ScrollUp()
case "<Enter>": // Play selected file
case "<Enter>":
selected := items[l.SelectedRow]
AudioPlayer(vp.GetString("path")+"/"+selected, selected)
}
Expand Down
5 changes: 1 addition & 4 deletions internal/player.go
Expand Up @@ -52,7 +52,7 @@ func GenrericDecoder(name string, f *os.File) (beep.StreamSeekCloser, beep.Forma
return mp3.Decode(f)
}

// Plays mp3 file
// Play and control an audio file
func AudioPlayer(file string, name string) {
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
Expand Down Expand Up @@ -84,7 +84,6 @@ func AudioPlayer(file string, name string) {

vp := viper.New()

// get user's home directory
home, err := os.UserHomeDir()
if err != nil {
fmt.Println(err)
Expand All @@ -94,13 +93,11 @@ func AudioPlayer(file string, name string) {
vp.SetConfigType("json")
vp.AddConfigPath(home)

// Reading config file
err1 := vp.ReadInConfig()
if err1 != nil {
fmt.Println("Error: Cannot read config file")
}

// get widget theme
TitleThemeColor := vp.GetInt("titlethemecolor")
BorderThemeColor := vp.GetInt("borderthemecolor")

Expand Down
3 changes: 1 addition & 2 deletions internal/theme.go
Expand Up @@ -29,6 +29,7 @@ var (
SelectedRowTheme ui.Color
)

// ChangeTheme receive an argument and change the color theme
func ChangeTheme(theme string) {
switch theme {
case "powershell":
Expand All @@ -51,7 +52,6 @@ func ChangeTheme(theme string) {

vp := viper.New()

// get user's home directory
home, err := os.UserHomeDir()
if err != nil {
fmt.Println(err)
Expand All @@ -61,7 +61,6 @@ func ChangeTheme(theme string) {
vp.SetConfigType("json")
vp.AddConfigPath(home)

// Reading config file
err1 := vp.ReadInConfig()
if err1 != nil {
fmt.Println("Error: Cannot read config file")
Expand Down

0 comments on commit 09f89b9

Please sign in to comment.