Skip to content

Commit

Permalink
Added flag for width. Closes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
ericm committed Oct 9, 2020
1 parent 35b98c4 commit 94591ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 13 additions & 3 deletions graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,27 @@ func GenerateGraph(chart *api.Chart, width int, height int, chartTheme ChartThem
colour = 91
}
info := fmt.Sprintf(
"\n\033[95m %s | \033[%dm%s %s (%s%% | %s)\033[95m on %s | Prev: %s | %s \033[0m",
"\n\033[95m %s | \033[%dm%s %s (%s%% | %s)\033[95m on %s | ",
chart.Ticker,
colour,
chart.Close.StringFixed(2),
chart.Currency,
chart.Change.StringFixed(2),
chart.ChangeVal.StringFixed(2),
chart.End.Time().Format(dateFormat),
chart.Prev.StringFixed(2),
chart.Exchange,
)
if len(info) > width {
info += fmt.Sprintf(
"%s \033[0m",
chart.Exchange,
)
} else {
info += fmt.Sprintf(
"Prev: %s | %s \033[0m",
chart.Prev.StringFixed(2),
chart.Exchange,
)
}
check:
if len(info) < width+maxSize+24 {
info += " "
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
week *bool
version *bool
extra *bool
width *int
theme *string
days *int

Expand Down Expand Up @@ -148,7 +149,7 @@ func main() {
fmt.Println(err.Error())
continue
}
g, _ := graph.GenerateGraph(chart, 80, viper.GetInt("config.favourites_height"), chartTheme)
g, _ := graph.GenerateGraph(chart, *width, viper.GetInt("config.favourites_height"), chartTheme)
fmt.Print(g)
}
}
Expand All @@ -164,7 +165,7 @@ func main() {
fmt.Println(err.Error())
os.Exit(1)
}
g, _ := graph.GenerateGraph(chart, 80, viper.GetInt("config.standalone_height"), chartTheme)
g, _ := graph.GenerateGraph(chart, *width, viper.GetInt("config.standalone_height"), chartTheme)
fmt.Print(g)
}
},
Expand All @@ -180,6 +181,7 @@ func main() {
name = rootCmd.PersistentFlags().StringP("name", "n", "", "Optional name for a stonk save")
version = rootCmd.PersistentFlags().BoolP("version", "v", false, "stonks version")
extra = rootCmd.PersistentFlags().BoolP("extra", "e", false, "Include extra pre + post time. (Only works for day)")
width = rootCmd.PersistentFlags().IntP("width", "W", 80, "Base width of the graph")

rootCmd.Execute()
}
Expand Down

0 comments on commit 94591ee

Please sign in to comment.