From f095dd57cbc45923355c1fad02a06c7be0bf15d0 Mon Sep 17 00:00:00 2001 From: emile Date: Mon, 8 Oct 2018 17:51:50 +0200 Subject: Implement the fancy llog log printing system --- draw/draw.go | 7 ------- llog/llog.go | 11 +++++++++-- main.go | 7 ++++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/draw/draw.go b/draw/draw.go index 785f7b1..74e9a10 100644 --- a/draw/draw.go +++ b/draw/draw.go @@ -2,7 +2,6 @@ package draw import ( "../structs" - "fmt" "github.com/fogleman/gg" "math" ) @@ -93,18 +92,12 @@ func drawStars(dc *gg.Context, slice []structs.Star) { // Slice draws the stars and the forces acting on them and saves the result to the given path func Slice(slice []structs.Star, path string) { - fmt.Printf("%-60s", "Plot init") // initialize the plot dc := initializePlot() - fmt.Printf("Done\n") - fmt.Printf("%-60s", "Drawing the Stars") // draw all the stars in the given slice drawStars(dc, slice) - fmt.Printf("Done\n") - fmt.Printf("%-60s", "Saving image") // save the plot to the given path saveImage(dc, path) - fmt.Printf("Done\n") } diff --git a/llog/llog.go b/llog/llog.go index e02af74..54620ed 100644 --- a/llog/llog.go +++ b/llog/llog.go @@ -2,14 +2,21 @@ package llog import ( "fmt" + "time" ) // Good prints a "good" (green) message with a timestamp and the given message func Good(text string) { - fmt.Printf("\033[36m [+] \033[0m%-60s\t", text) + fmt.Printf("%s\033[36m [+] \033[0m%-60s\t", currentTime(), text) } // Bad prints a "good" (green) message with a timestamp and the given message func Bad(text string) { - fmt.Printf("\033[31m [+] \033[0m%-60s\t", text) + fmt.Printf("%s\033[31m [+] \033[0m%-60s\t", currentTime(), text) +} + +// current_time returns the current time as a string in the HH:MM:SS format +func currentTime() string { + t := time.Now() + return fmt.Sprintf("%02d:%02d:%02d", t.Hour(), t.Minute(), t.Second()) } diff --git a/main.go b/main.go index 43240ef..be836c4 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "./csv" "./draw" "./forces" + "./llog" "./structs" "fmt" ) @@ -16,15 +17,15 @@ func main() { {structs.Coord{X: 100, Y: 500}, structs.Force{0, 0}, 1000}, } - fmt.Printf("%-60s", "Opening the csv") + llog.Good("Opening the csv") starsSlice = csv.Import("data/structure03.ita.uni-heidelberg.de_26635.csv", 0, 4000, starsSlice) fmt.Printf("Done\n") - fmt.Printf("%-60s", "Calculate the forces") + llog.Good("Calculate the forces acting") forces.CalcAllForces(starsSlice) fmt.Printf("Done\n") - fmt.Printf("%-60s", "Plotting the stars") + llog.Good("Drawing the slice") draw.Slice(starsSlice, "out.png") fmt.Printf("Done\n") } -- cgit 1.4.1