-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
4rkal
committed
Mar 14, 2024
1 parent
7f80506
commit 4e57750
Showing
12 changed files
with
347 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/charmbracelet/bubbles/progress" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/charmbracelet/lipgloss" | ||
"github.com/martinlindhe/notify" | ||
) | ||
|
||
const ( | ||
padding = 2 | ||
maxWidth = 80 | ||
) | ||
|
||
type Routine struct { | ||
Reps int `json:"reps"` | ||
Rest int `json:"rest"` | ||
Increase int `json:"increase"` | ||
} | ||
|
||
var routine Routine | ||
|
||
var helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#626262")).Render | ||
|
||
var amount_done int = 0 | ||
|
||
func do(reps, rest, increase int) int { | ||
if increase != 0 { | ||
reps += reps * increase / 100 | ||
} | ||
amount_done += reps | ||
return reps | ||
} | ||
|
||
func alert(reps int) { | ||
message := fmt.Sprintf("Do %v pushups", reps) | ||
notify.Alert("go-pushups", "Pushup time!", message, "assets/logo.png") | ||
} | ||
|
||
func run(should_save bool) error { | ||
var tmp string | ||
var confirmation bool | ||
routine, err := form1(tmp) | ||
if err != nil { | ||
fmt.Println("oh oh") | ||
os.Exit(1) | ||
} | ||
|
||
confirmation, err2 := form2() | ||
if err2 != nil { | ||
fmt.Println("oh oh") | ||
os.Exit(1) | ||
} | ||
if routine.Reps <= 0 || routine.Rest <= 0 { | ||
fmt.Println("Not positive input") | ||
os.Exit(1) | ||
} | ||
|
||
if confirmation == true && should_save == true { | ||
save(routine) | ||
} | ||
|
||
m := model{ | ||
progress: progress.New(progress.WithDefaultGradient()), | ||
} | ||
|
||
for round := 1; ; round++ { | ||
if _, err := tea.NewProgram(m).Run(); err != nil { | ||
fmt.Println("Oh no!", err) | ||
os.Exit(1) | ||
} | ||
reps := do(routine.Reps, routine.Rest, routine.Increase) | ||
fmt.Printf("Round %d: Do %d pushups\n", round, reps) | ||
alert(reps) | ||
quit, err := form3() | ||
if err != nil { | ||
fmt.Println("oh oh %s", err) | ||
os.Exit(1) | ||
} | ||
if quit == false { | ||
fmt.Printf("You did %v pushups\n", amount_done) | ||
os.Exit(0) | ||
} | ||
} | ||
} | ||
|
||
func run2(routinee Routine) error { | ||
clearScreen() | ||
routine = routinee | ||
m := model{ | ||
progress: progress.New(progress.WithDefaultGradient()), | ||
} | ||
|
||
for round := 1; ; round++ { | ||
if _, err := tea.NewProgram(m).Run(); err != nil { | ||
fmt.Println("Oh no!", err) | ||
os.Exit(1) | ||
} | ||
reps := do(routine.Reps, routine.Rest, routine.Increase) | ||
fmt.Printf("Round %d: Do %d pushups\n", round, reps) | ||
alert(reps) | ||
quit, err := form3() | ||
if err != nil { | ||
fmt.Println("oh oh %s", err) | ||
os.Exit(1) | ||
} | ||
if quit == false { | ||
fmt.Printf("You did %v pushups\n", amount_done) | ||
os.Exit(0) | ||
} | ||
} | ||
} | ||
|
||
func clearScreen() { | ||
cmd := exec.Command("clear") | ||
cmd.Stdout = os.Stdout | ||
cmd.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// loadCmd represents the load command | ||
var loadCmd = &cobra.Command{ | ||
Use: "load", | ||
Short: "Loads an existing routine", | ||
Long: `Load an existing pushup routine. | ||
Example usage: | ||
go-pushups load glorious-mindworm`, | ||
Args: cobra.RangeArgs(0, 1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) == 0 { | ||
show_files() | ||
} else { | ||
routine, error := loadRoutine(args[0]) | ||
if error != nil { | ||
fmt.Println(error) | ||
os.Exit(1) | ||
} | ||
run2(routine) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(loadCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// loadCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// loadCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "go-pushups", | ||
Short: "Your cli pushup companion", | ||
Long: `go-pushups is a simple command-line application designed to help you stay active by reminding you to do pushups at regular intervals, with a percentage increase over time.`, | ||
// Uncomment the following line if your bare application | ||
// has an action associated with it: | ||
// Run: func(cmd *cobra.Command, args []string) { }, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
// Here you will define your flags and configuration settings. | ||
// Cobra supports persistent flags, which, if defined here, | ||
// will be global for your application. | ||
|
||
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.go-pushups.yaml)") | ||
|
||
// Cobra also supports local flags, which will only run | ||
// when this action is called directly. | ||
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// runCmd represents the run command | ||
var runCmd = &cobra.Command{ | ||
Use: "run", | ||
Short: "Runs go-pushups", | ||
Long: `Runs go-pushups`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
run(true) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(runCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// runCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// runCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
Oops, something went wrong.