Skip to content

Commit

Permalink
fix bug in update function
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcoder04 committed May 15, 2022
1 parent f64a8e6 commit 3fbecfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func main() {
fmt.Printf(
`[{"full_text": "loading status line...", "color": "%s"}],`,
config.Colors["WHITE"])
fmt.Println("")

go ReadInput()
for _, m := range config.Modules {
Expand Down
18 changes: 9 additions & 9 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ func UpdateModuleByName(name string, counter int, env []string) {
}
}

func UpdateModule(i int, counter int, env []string) {
func UpdateModule(mod int, counter int, env []string) {
// don't update if interval didn't pass
if counter%config.Modules[i].Interval != 0 {
if counter%config.Modules[mod].Interval != 0 {
return
}

cmd := exec.Command(config.Modules[i].Command, config.Modules[i].Args...)
cmd := exec.Command(config.Modules[mod].Command, config.Modules[mod].Args...)
cmd.Env = append(os.Environ(), env...)
out, err := cmd.Output()

if err != nil {
config.Modules[i].Text = " error"
config.Modules[mod].Text = " error"
} else {
lines := strings.Split(string(out), "\n")
for i := 0; i <= 3; i++ {
Expand All @@ -36,16 +36,16 @@ func UpdateModule(i int, counter int, env []string) {
switch i {
// first line is text
case 0:
config.Modules[i].Text = fmt.Sprintf("%s%s%s",
config.Modules[i].Pre,
config.Modules[mod].Text = fmt.Sprintf("%s%s%s",
config.Modules[mod].Pre,
strings.Replace(lines[i], "\n", " ", -1),
config.Modules[i].Post)
config.Modules[mod].Post)
// third line is ForegroundColor
case 2:
config.Modules[i].ForegroundColor = lines[i]
config.Modules[mod].ForegroundColor = lines[i]
// fourth line is BackgroundColor
case 3:
config.Modules[i].BackgroundColor = lines[i]
config.Modules[mod].BackgroundColor = lines[i]
}
}
}
Expand Down

0 comments on commit 3fbecfe

Please sign in to comment.