diff options
| author | Nikolaus Gotsche <n@softwarefools.com> | 2018-09-10 04:59:43 +0200 |
|---|---|---|
| committer | Nikolaus Gotsche <n@softwarefools.com> | 2018-09-10 04:59:43 +0200 |
| commit | fd4a4409ee8e6b772db30611e968778b68eca0d6 (patch) | |
| tree | 8f14136fcbb5d7f5b3c94e80bf64ed7230bd7d51 | |
| parent | 3b4bc634700694a4d84a23f6b6700a5484065736 (diff) | |
Beautify output
| -rw-r--r-- | config.go | 6 | ||||
| -rw-r--r-- | main.go | 34 | ||||
| -rw-r--r-- | sqlite.go | 65 |
3 files changed, 77 insertions, 28 deletions
@@ -74,13 +74,9 @@ func makeNewTOML(gibts bool) { fmt.Println("Editing Configuration File\nPress [Enter] to keep the Current setting") }else{ fmt.Println("Making new Configuration File") - - //arr := []string{"", "", ""} - //ma0 := MailAccount{"","","",0,"",""} - //mm0 := MassMail{"","","",arr,""} //Examplenames Coming soon n := "" - config = Config{"mytimes.db",n,n,n,n,n,n,n,n,n,n,n,n,n,n,n} + config = Config{".mytimes.db",n,n,n,n,n,n,n,n,n,n,n,n,n,n,n} } //fmt.Println("Whats Your Namecount\n") database := getNewInput("DB File Path: ",config.Database) @@ -9,7 +9,7 @@ import ( "os" //"strings" _ "os/exec" - //"github.com/fatih/color" + "github.com/fatih/color" ) //var svar string @@ -22,6 +22,24 @@ var newproject, newtask, stoptask, allproj, runinter, test, newconfig bool //var red, green, yellow, cyan color //var boldRed, boldGreen color +func title() { + bR := color.New(color.FgRed, color.Bold).SprintFunc() + bHiR := color.New(color.FgHiRed, color.Bold).SprintFunc() + bHiY := color.New(color.FgHiYellow, color.Bold).SprintFunc() + bHiG := color.New(color.FgHiGreen, color.Bold).SprintFunc() + bHiC := color.New(color.FgHiCyan, color.Bold).SprintFunc() + bHiB := color.New(color.FgHiBlue, color.Bold).SprintFunc() + bHiM := color.New(color.FgHiMagenta, color.Bold).SprintFunc() + bM := color.New(color.FgMagenta, color.Bold).SprintFunc() + line := "___" + + fmt.Printf("%s%s%s%s%s%s%s%s\n\n",bR(line),bHiR(line),bHiY(line),bHiG(line),bHiC(line),bHiB(line),bHiM(line),bM(line)) + fmt.Println(" ",bR("L"),bHiR("A"),bHiY("B"),bHiG("O"),bHiC("R"),bHiB("A"),bHiM("V"),bM("I")) + fmt.Printf("%s%s%s%s%s%s%s%s\n",bR(line),bHiR(line),bHiY(line),bHiG(line),bHiC(line),bHiB(line),bHiM(line),bM(line)) + fmt.Println("(c) 2018 - n@gotsche.at\n") +} + + func init() { //red := color.New(color.FgRed).SprintFunc @@ -114,9 +132,15 @@ func stdOut() { } func main() { - fmt.Println("Laboravi Started") - initConf() + //fmt.Println("Laboravi Started") dbname := "./.mytimes.db" + if flag.NFlag() > 0 { + title() + }else{ + fmt.Println("Laboravi Started") + } + initConf() + dbname = config.Database if len(flag.Args())>0 { aar := flag.Args() @@ -138,13 +162,15 @@ func main() { fmt.Println("Unknown Commands: ",uar) } } + initDB(dbname) getLastProject() //getProjects() getOpenTask() if test { - tmpltest() + fmt.Println("Nothing to test") + //tmpltest() //newBill(1) //c := []int{2,3} //a,b := getUnfinishedList(c) @@ -111,6 +111,10 @@ func initDB(filename string) { checkErr(err) _, err = stmt.Exec(0,"None","Annonymus") checkErr(err) + stmt, err = db.Prepare("INSERT INTO projects(id,name,customer) values(?, ?, ?)") + checkErr(err) + _, err = stmt.Exec(0,"None",0) + checkErr(err) }else{ db, err = sql.Open("sqlite3", filename) checkErr(err) @@ -613,14 +617,11 @@ func showOpenTask() { } func showLastProject() { - if (currproject.id==0) { - fmt.Println("Empty DB") - } else { - fmt.Println("___Last Project_____________") - fmt.Println(currproject.id,":", currproject.name,"- Started:",currproject.first.Local().Format("Mon _2 Jan 2006")) - fmt.Println(" Last Changes",currproject.last.Local().Format("2006 Mon Jan _2 15:04")) - } + fmt.Println("___Last Project_____________") + fmt.Println(currproject.id,":", currproject.name,"- Started:",currproject.first.Local().Format("Mon _2 Jan 2006")) + fmt.Println(" Last Changes",currproject.last.Local().Format("2006 Mon Jan _2 15:04")) } + func addCustomer() { com := getInput("Enter Customer Company: ") nam := getInput("Enter Customer Name: ") @@ -664,7 +665,6 @@ func newProject() { } func getClosedTasks(num int) { - fmt.Println("___Billed Tasks_______________") rows,err := db.Query("SELECT * FROM timetable WHERE stop != '1791-09-30 19:07' ORDER BY datetime(start)",currproject.id) checkErr(err) if num > 0 { @@ -679,8 +679,15 @@ func getClosedTasks(num int) { var tas string var sum, dur float64 = 0.0, 0.0 checkErr(err) - + first := true + //if err != nil && err != sql.ErrNoRows { + // fmt.Println("___Billed Tasks_______________") + //} for rows.Next() { + if first { + fmt.Println("___Billed Tasks_______________") + first = false + } err = rows.Scan(&id, &proj, &sta, &sto, &tas, &check) checkErr(err) dur = float64(sto.Sub(sta))/(1000000000*60*60) @@ -688,9 +695,11 @@ func getClosedTasks(num int) { //fmt.Println(id,tas,sta.Local().Format("2006 Mon Jan _2 15:04"),sto.Local().Format("15:04"),dur,"h") sum += dur } + if !first{ + fmt.Println("____________________________") + fmt.Printf("Billed: %.2f h\n",sum) + } rows.Close() - fmt.Printf("Billed: %.2f h\n",sum) - fmt.Println("___Past Tasks_______________") if num > 0 { rows,err = db.Query("SELECT * FROM timetable WHERE project = $1 AND checkout = 0 AND stop != '1791-09-30 19:07'ORDER BY datetime(start) DESC LIMIT $2",currproject.id,num) @@ -700,7 +709,15 @@ func getClosedTasks(num int) { checkErr(err) } sum2 := 0.0 + first = true + //if err != nil && err != sql.ErrNoRows{ + // fmt.Println("___Past Tasks_______________") + //} for rows.Next() { + if first { + fmt.Println("___Past Tasks_______________") + first = false + } err = rows.Scan(&id, &proj, &sta, &sto, &tas, &check) checkErr(err) dur = float64(sto.Sub(sta))/(1000000000*60*60) @@ -708,9 +725,12 @@ func getClosedTasks(num int) { //fmt.Println(id,tas,sta.Local().Format("2006 Mon Jan _2 15:04"),sto.Local().Format("15:04"),dur,"h") sum2 += dur } + //if err != nil && err != sql.ErrNoRows{ + if !first{ + fmt.Println("____________________________") + fmt.Printf("Unbilled: %.2f[h] Total: %.2f[h]\n",sum2,sum+sum2) + } rows.Close() - fmt.Println("____________________________") - fmt.Printf("Unbilled: %.2f[h] Total: %.2f[h]\n",sum2,sum+sum2) } func getLastProject() { @@ -828,23 +848,30 @@ func allProjects() { var first time.Time var last time.Time var finish int - var customer int + var customer,check int var start,stop time.Time fmt.Println("____For",com,nam) for rows.Next() { err = rows.Scan(&uid, &prname, &first, &last, &finish, &customer) checkErr(err) - rows2,err := db.Query("SELECT start, stop FROM timetable WHERE project = $1 AND stop != '1791-09-30 19:07'",uid) + rows2,err := db.Query("SELECT start, stop, checkout FROM timetable WHERE project = $1 AND stop != '1791-09-30 19:07'",uid) checkErr(err) - sum := 0.0 + sumb,sumo := 0.0,0.0 for rows2.Next() { - err = rows2.Scan(&start,&stop) + err = rows2.Scan(&start,&stop,&check) checkErr(err) - sum += float64(stop.Sub(start))/(1000000000*60*60) + if check == 0 { + sumo += float64(stop.Sub(start))/(1000000000*60*60) + }else{ + sumb += float64(stop.Sub(start))/(1000000000*60*60) + } } - fmt.Printf(" %v:%s \n First: %s, Last:%s, Total:%.2f(h) ,Fin:%v, For:%v\n",uid,prname,first.Local().Format("2006-01-02 15:04 MST"),last.Local().Format("2006-01-02 15:04 MST"),sum,finish,customer) + //fmt.Printf(" %v:%s \n First: %s, Last:%s, Total:%.2f(h) ,Fin:%v, For:%v\n",uid,prname,first.Local().Format("2006-01-02 15:04 MST"),last.Local().Format("2006-01-02 15:04 MST"),sum,finish,customer) + fmt.Printf(" %v:%s \n",uid,prname) + fmt.Printf(" Unbilled: %.2f[h] Billed: %.2f[h] | Total: %.2f[h]\n",sumo,sumb,sumo+sumb) + fmt.Printf(" First: %s, Last:%s, Fin:%v, For:%v\n",first.Local().Format("2006-01-02 15:04 MST"),last.Local().Format("2006-01-02 15:04 MST"),finish,customer) rows2.Close() //good habit to close } rows.Close() //good habit to close |
