summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.go32
-rw-r--r--interact.go33
-rw-r--r--sqlite.go258
-rw-r--r--utils.go35
4 files changed, 226 insertions, 132 deletions
diff --git a/config.go b/config.go
index a0b3626..72b56eb 100644
--- a/config.go
+++ b/config.go
@@ -87,22 +87,22 @@ func makeNewTOML(gibts bool) {
config = Config{file, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n}
}
//fmt.Println("Whats Your Namecount\n")
- database := getNewInterInput("DB File Path: ", config.Database)
- name := getNewInterInput("Whats your Name?: ", config.Name)
- street := getNewInterInput("Street: ", config.Street)
- zip := getNewInterInput("Zip Code: ", config.Zip)
- city := getNewInterInput("City: ", config.City)
- country := getNewInterInput("Country: ", config.City)
- telefon := getNewInterInput("Telefone number: ", config.Telefon)
- mobile := getNewInterInput("Mobile number: ", config.Mobile)
- mail := getNewInterInput("Email: ", config.Mail)
- url := getNewInterInput("URL: ", config.Url)
- taxid := getNewInterInput("Tax ID: ", config.Taxid)
- bankname := getNewInterInput("Bank Name: ", config.Bankname)
- bankacc := getNewInterInput("Bank Account: ", config.Bankacc)
- banklz := getNewInterInput("BLZ: ", config.Banklz)
- iban := getNewInterInput("IBAN: ", config.Iban)
- bic := getNewInterInput("BIC: ", config.Bic)
+ database := getNewInterInput("DB File Path: ", config.Database, nli)
+ name := getNewInterInput("Whats your Name?: ", config.Name, nli)
+ street := getNewInterInput("Street: ", config.Street, nli)
+ zip := getNewInterInput("Zip Code: ", config.Zip, nli)
+ city := getNewInterInput("City: ", config.City, nli)
+ country := getNewInterInput("Country: ", config.Country, nli)
+ telefon := getNewInterInput("Telefone number: ", config.Telefon, nli)
+ mobile := getNewInterInput("Mobile number: ", config.Mobile, nli)
+ mail := getNewInterInput("Email: ", config.Mail, nli)
+ url := getNewInterInput("URL: ", config.Url, nli)
+ taxid := getNewInterInput("Tax ID: ", config.Taxid, nli)
+ bankname := getNewInterInput("Bank Name: ", config.Bankname, nli)
+ bankacc := getNewInterInput("Bank Account: ", config.Bankacc, nli)
+ banklz := getNewInterInput("BLZ: ", config.Banklz, nli)
+ iban := getNewInterInput("IBAN: ", config.Iban, nli)
+ bic := getNewInterInput("BIC: ", config.Bic, nli)
conf := Config{database, name, street, zip, city, country, telefon, mobile, mail, url, taxid, bankacc, banklz, bankname, iban, bic}
diff --git a/interact.go b/interact.go
index 14e591f..3f3339b 100644
--- a/interact.go
+++ b/interact.go
@@ -21,7 +21,7 @@ func interact() {
//fmt.Println(os.Args)
//cyan := color.New(color.FgCyan).SprintFunc()
//yellow := color.New(color.FgYellow).SprintFunc()
- green := color.New(color.FgGreen).SprintFunc()
+ //green := color.New(color.FgGreen).SprintFunc()
boldBlue := color.New(color.FgBlue, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
boldMag := color.New(color.FgMagenta, color.Bold).SprintFunc()
@@ -359,7 +359,7 @@ func interact() {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
- newTaskTime(currproject.id, arg)
+ newTaskTime(arg)
stdOut()
} else {
c.Println(boldRed("start <DateTime> - Please enter a Datetime"))
@@ -670,7 +670,7 @@ func interact() {
}
}
billid, billident := newBill(billprojid)
- c.Println(green("Bill Completed"))
+ //c.Println(green("Bill Completed"))
fullbill := bill{billid, billident, dur, proj.id, proj.name, time.Time{}, time.Time{}, allitems}
saveBill(fullbill)
checkTasks(selids, billid)
@@ -740,15 +740,15 @@ func getInterInput(question string) (out string) {
return
}
-func getNewInterInput(question, old string) string {
+func getNewInterInput(question, old, border string) string {
shell := ishell.New()
shell.ShowPrompt(false)
defer shell.ShowPrompt(true)
if old != "" {
- shell.Println("Current:", old)
+ shell.Println(border+"Current:", old)
}
- shell.Print(question)
+ shell.Print(border+question)
line := shell.ReadLine()
if line == "" {
@@ -762,29 +762,32 @@ func getInterMultiInput(question string) (out string) {
shell := ishell.New()
//shell.ShowPrompt(false)
//defer shell.ShowPrompt(true)
-
+ shell.SetPrompt(nli+">>>")
+ shell.SetMultiPrompt(nli+"...")
shell.Println(question, "(Multiline input, end with ';')")
out = shell.ReadMultiLines(";")
- shell.Println(" -Done-")
+ shell.Println(sli+" -Done-")
return
}
-func getNewInterMultiInput(question, old string) (out string) {
+func getNewInterMultiInput(question, old, border string) (out string) {
shell := ishell.New()
//shell.ShowPrompt(false)
//defer shell.ShowPrompt(true)
+ shell.SetPrompt(border+">>>")
+ shell.SetMultiPrompt(border+"...")
if old != "" {
- shell.Println("Current:\n", old)
+ shell.Println(border,"Current:\n", old)
}
- shell.Println("Should current entry be replaced? A Newline will be added otherwise")
- if isInterSure(" ") {
- shell.Println(question, "(Multiline input, end with ';')")
+ shell.Println(border,"Should current entry be replaced? A Newline will be added otherwise")
+ if isInterSure(border+" ") {
+ shell.Println(border, question, "(Multiline input, end with ';')")
out = shell.ReadMultiLines(";")
- shell.Println(" -Done-")
+ shell.Println(border," -Done-")
} else {
- shell.Print(question)
+ shell.Print(nli+question)
txt := shell.ReadLine()
if txt == "" {
out = old
diff --git a/sqlite.go b/sqlite.go
index 7da7237..d41c7dd 100644
--- a/sqlite.go
+++ b/sqlite.go
@@ -176,10 +176,10 @@ func setPauseTask(id int) {
pausetask = id
}
-func newTaskTime(proj int, tim string) {
+func newTaskTime(tim string) {
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
- fmt.Println(boldGreen("Start Project at ", tim))
+ fmt.Println(frame(boldGreen("Starting Task at ", tim),true))
if opentask.id == 0 {
timstr := "1791-09-30 19:07"
//zone, _ := time.Now().Zone()
@@ -191,26 +191,29 @@ func newTaskTime(proj int, tim string) {
timstr = currdate + " " + getTime(tim)
//timst = timstr+" "+zone
} else {
- fmt.Println(tim, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM' or 'HH:MM'")
+ fmt.Println(nli,tim, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM' or 'HH:MM'")
+ fmt.Println(frame(negR(),false))
return
//os.Exit(0)
}
stmt, err := db.Prepare("INSERT INTO timetable(project, start, task, checkout) values(?, datetime(?,'utc'), ?, ?)")
- fmt.Println(timstr)
- task := getInterInput("Specify Task: ")
+ fmt.Println(nli+timstr)
+ task := getInterInput(sli+"Specify Task: ")
checkErr(err)
- if proj == 0 {
- _, err = stmt.Exec(currproject.id, timstr, task, 0)
- } else {
- _, err = stmt.Exec(proj, timstr, task, 0)
- }
+ //if proj == 0 {
+ _, err = stmt.Exec(currproject.id, timstr, task, 0)
+ //} else {
+ // _, err = stmt.Exec(proj, timstr, task, 0)
+ //}
checkErr(err)
- fmt.Println("...new task inserted into", currproject.name, ": ", task)
+ fmt.Println(nli+"...new task inserted into", currproject.name, ": ", task)
+ fmt.Println(frame(posR(),false))
getOpenTask()
updateProject(currproject.id)
} else {
- fmt.Println(boldRed("Another Task is already Open"))
+ fmt.Println(nli+boldRed("Another Task is already Open"))
+ fmt.Println(frame("Close Task First",false))
showOpenTask()
}
@@ -220,34 +223,42 @@ func newTask(resume bool) {
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
task := ""
+ if resume {
+ fmt.Println(frame(boldGreen("Resuming Task"),true))
+ }else{
+ fmt.Println(frame(boldGreen("Starting Task Now"),true))
+ }
if opentask.id > 0 {
- fmt.Println(boldRed("Another Task is already Open"))
- showOpenTask()
+ fmt.Println(nli+boldRed("Another Task is already Open"))
+ //showOpenTask()
+ fmt.Println(frame(negR(),false))
return
}
if resume {
if pausetask == 0 {
- fmt.Println(boldRed("No Task was Paused"))
+ fmt.Println(nli+boldRed("No Task was Paused"))
+ fmt.Println(frame(negR(),false))
return
} else {
idx := []int{pausetask}
tsks := getSelectedTasks(idx)
fulltask := tsks[0]
- fmt.Println(boldGreen("Resuming Task ", pausetask, " - ", fulltask.taskname))
+ fmt.Println(nli+"Resuming Task ", pausetask, " - ", fulltask.taskname)
//fmt.Println()
task = fulltask.taskname
}
} else {
- fmt.Println(boldGreen("Starting new Task"))
- task = getInterInput("Specify Task: ")
+ //fmt.Println(boldGreen("Starting new Task"))
+ task = getInterInput(sli+"Specify Task: ")
}
stmt, err := db.Prepare("INSERT INTO timetable(project, task, checkout) values(?, ?, ?)")
checkErr(err)
_, err = stmt.Exec(currproject.id, task, 0)
checkErr(err)
if !resume {
- fmt.Println("...New Task inserted into", currproject.name, ": ", task)
+ fmt.Println(nli+"...New Task inserted into", currproject.name, ": ", task)
}
+ fmt.Println(frame(posR(),false))
getOpenTask()
updateProject(currproject.id)
}
@@ -255,37 +266,39 @@ func newTask(resume bool) {
func newBill(proj int) (int, string) {
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
//boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
- fmt.Println(boldGreen("Creating New Bill"))
//Show 5 recent bills
showLastBills(5)
- invno := getInterInput("Invoice Number: ")
+ fmt.Println(frame(boldGreen("Creating New Bill"),true))
+ invno := getInterInput(sli+"Invoice Number: ")
stmt, err := db.Prepare("INSERT INTO bills (identity, project, date) values(?, ?, datetime('now'))")
checkErr(err)
answ, err := stmt.Exec(invno, proj)
checkErr(err)
lid, _ := answ.LastInsertId()
- fmt.Println("Bill", invno, "Created with ID", lid)
+ //fmt.Println(frame("Bill "+ invno+" Created with ID "+lid),false)
+ fmt.Println(nli+"Bill", invno, "Created with ID", lid)
return int(lid), invno
}
func saveBill(in bill) {
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
tasks, times, hours, moneys := items2strings(in.items)
- fmt.Println(boldGreen("Saving Bill"), in.id)
+ fmt.Println(nli+boldGreen("Saving Bill"), in.id)
stmt, err := db.Prepare("UPDATE bills SET identity = ?, timerange = ?, tasks = ?, times = ?, hours = ?, moneys = ? WHERE id = ?")
checkErr(err)
_, err = stmt.Exec(in.identity, in.timerange, tasks, times, hours, moneys, in.id)
checkErr(err)
+ fmt.Println(frame(posR(),false))
}
func showLastBills(count int) {
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
- cn := "all"
- if count > 0 {
- cn = fmt.Sprint(count)
- }
- fmt.Printf(boldGreen("Loading %s Bills\n"), cn)
+ //cn := "all"
+ //if count > 0 {
+ // cn = fmt.Sprint(count)
+ //}
+ //fmt.Printf(boldGreen("Loading %s Bills\n"), cn)
rows, err := db.Query("SELECT * FROM timetable")
if count == 0 {
rows, err = db.Query("SELECT * FROM bills ORDER BY date ASC")
@@ -301,9 +314,11 @@ func showLastBills(count int) {
//fmt.Println("___Open Task________________")
if count == 0 {
- fmt.Print("___All Previous Bills_______\n")
+ fmt.Println(frame(boldGreen("All Bills"),true))
+ //fmt.Print("___All Previous Bills_______\n")
} else {
- fmt.Printf("___Previous %v Bills________\n", count)
+ str := fmt.Sprintf("Previous %v Bills", count)
+ fmt.Println(frame(boldGreen(str),true))
}
i := 0
for rows.Next() {
@@ -313,7 +328,7 @@ func showLastBills(count int) {
prn, _ := getProjectName(proj)
hsum := sumFloatArray(string2FloatArray(hourstr, ";"))
msum := sumFloatArray(string2FloatArray(moneystr, ";"))
- fmt.Printf(" %v:%s - %s (%v) %.1f[h]: %.2f[€] - ", id, ident, prn, date.Local().Format("2006.01.02"), hsum, msum)
+ fmt.Printf("%s %v:%s - %s (%v) %.1f[h]: %.2f[€] - ",nli, id, ident, prn, date.Local().Format("2006.01.02"), hsum, msum)
p := fmt.Sprintf("%v", paid)
if p == "1791-09-30 19:07:00 +0000 UTC" {
fmt.Print(boldRed("OPEN\n"))
@@ -322,9 +337,10 @@ func showLastBills(count int) {
}
}
if i == 0 {
- fmt.Println(boldRed("\n NONE"))
+ fmt.Println(nli+"\n"+nli,boldRed(" NONE"))
}
- fmt.Println(" ")
+ fmt.Println(nli)
+ fmt.Println(frame("",false))
}
func loadBills(in []int) (out []bill) {
@@ -379,10 +395,14 @@ func items2strings(in []billitem) (tasks, times, hours, moneys string) {
func closeTaskTime(tim string) {
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
- fmt.Println(boldGreen("Stoping Task ", opentask.id, ":", opentask.taskname))
+ //fmt.Println(boldGreen("Stoping Task ", opentask.id, ":", opentask.taskname))
+ fmt.Println(frame(boldGreen("Stoping Task"),true))
if opentask.id == 0 {
- fmt.Println(boldRed("There is no Open Task"))
+ fmt.Println(nli+boldRed("There is no Open Task"))
+ fmt.Println(frame(negR(),false))
return
+ }else{
+ fmt.Println(nli,"ID ",opentask.id, ":", opentask.taskname)
}
//timt,err := time.Parse("2006-01-02 15:04",tim)
timst, timstr := "1791-09-30 19:07", "1791-09-30 19:07"
@@ -394,7 +414,8 @@ func closeTaskTime(tim string) {
timstr = time.Now().Local().Format("2006-01-02") + " " + getTime(tim)
timst = timstr + " " + zone
} else {
- fmt.Println(tim, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM' or 'HH:MM'")
+ fmt.Println(nli,tim, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM' or 'HH:MM'")
+ fmt.Println(frame(negR(),false))
return
//os.Exit(0)
@@ -406,18 +427,21 @@ func closeTaskTime(tim string) {
if timt.After(opentask.start) {
//timstr := timt.UTC().Format("2006-01-02 15:04")
com := ""
- if isInterSure("Do You Want to enter a Comment?") {
- com = getInterMultiInput("Comment:")
+ if isInterSure(sli+"Do You Want to enter a Comment?") {
+ com = getInterMultiInput(nli+"Comment:")
}
- fmt.Println("...Closing Task", opentask.id, "at", timst)
+ fmt.Println(nli,"...Closing Task", opentask.id, "at", timst)
stmt, err := db.Prepare("UPDATE timetable SET stop = datetime(?,'utc'), comment = ? WHERE id = ?")
checkErr(err)
_, err = stmt.Exec(timstr, com, opentask.id)
checkErr(err)
opentask.id = 0
updateProject(opentask.projectid)
+ fmt.Println(frame(posR(),false))
} else {
- fmt.Println(boldRed("Cannot Stop before the Beginning!"))
+ fmt.Println(nli,boldRed("Cannot Stop before the Beginning!"))
+ fmt.Println(frame(negR(),false))
+ return
}
//fmt.Println(tim,timt)
}
@@ -426,19 +450,28 @@ func closeTask(loud bool) {
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
if loud {
- fmt.Println(boldGreen("Stoping Task ", opentask.id, ":", opentask.taskname))
- }
- if opentask.id == 0 {
- fmt.Println(boldRed("There is no Open Task"))
- return
+ fmt.Println(frame(boldGreen("Stoping Task"),true))
+ if opentask.id == 0 {
+ fmt.Println(nli,boldRed("There is no Open Task"))
+ fmt.Println(frame(negR(),false))
+ return
+ }else{
+ fmt.Println(nli,"ID ",opentask.id, ":", opentask.taskname)
+ }
+ //fmt.Println(boldGreen("Stoping Task ", opentask.id, ":", opentask.taskname))
+ }else{
+ if opentask.id == 0 {
+ fmt.Println(boldRed("There is no Open Task"))
+ }
}
if time.Now().After(opentask.start.Local()) {
com := ""
if loud {
- if isInterSure("Do You Want to enter a Comment?") {
- com = getInterMultiInput("Comment:")
+ if isInterSure(sli+"Do You Want to enter a Comment?") {
+ com = getInterMultiInput(nli+"Comment:")
}
- fmt.Println("...Closing Task", opentask.id)
+ fmt.Println(nli+"...Closing Task", opentask.id)
+ fmt.Println(frame(posR(),false))
}
stmt, err := db.Prepare("UPDATE timetable SET stop = datetime('now'), comment = ? WHERE id = ?")
checkErr(err)
@@ -447,7 +480,12 @@ func closeTask(loud bool) {
opentask.id = 0
updateProject(opentask.projectid)
} else {
- fmt.Println(boldRed("Cannot Stop before the Beginning!"))
+ if loud {
+ fmt.Println(nli,boldRed("Cannot Stop before the Beginning!"))
+ fmt.Println(frame(negR(),false))
+ }else{
+ fmt.Println(boldRed("Cannot Stop before the Begining!"))
+ }
}
}
@@ -455,9 +493,10 @@ func checkBill(bid int) {
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
var custid int
-
+ fmt.Println(frame(boldGreen("Checking Bill"),true))
if !isBill(bid) {
- fmt.Println(bid, boldRed("is not a known bill ID"))
+ fmt.Println(nli,bid, boldRed("is not a known bill ID"))
+ fmt.Println(frame(negR(),false))
return
}
@@ -465,16 +504,18 @@ func checkBill(bid int) {
bill := loadBills(bar)
if len(bill) < 1 {
+ fmt.Println(nli, boldRed("The Bill cannot be loaded."))
+ fmt.Println(frame(negR(),false))
return
} else {
pr, cu := getProjectName(bill[0].project)
custid = getCustomerId(bill[0].project)
//fmt.Println(bill[0])
- fmt.Println(boldGreen("Checking Bill ", bid, " as Paid:\n", bill[0].identity), "\n For", cu, " :", pr)
+ fmt.Println(nli+"Marking Bill ", bid, " as Paid:\n"+nli, bill[0].identity, "\n"+nli+" For", cu, " :", pr)
_, _, ho, ma := items2strings(bill[0].items)
hsum := sumFloatArray(string2FloatArray(ho, ";"))
msum := sumFloatArray(string2FloatArray(ma, ";"))
- fmt.Printf(" Date: %s Hours: %.1f[h] Sum: %.2f[€]\n", bill[0].date.Local().Format("2006-01-02"), hsum, msum)
+ fmt.Printf(nli+" Date: %s Hours: %.1f[h] Sum: %.2f[€]\n"+nli, bill[0].date.Local().Format("2006-01-02"), hsum, msum)
//fmt.Println(ta)
}
@@ -482,7 +523,7 @@ func checkBill(bid int) {
//zone, _ := time.Now().Zone()
timstr := "1791-09-30 19:07"
- timin := getInterInput("Specify Date (YYYY-MM-DD): ")
+ timin := getInterInput(sli+"Specify Date (YYYY-MM-DD): ")
if isDateTime(timin) {
timstr = getDateTime(timin)
@@ -490,10 +531,11 @@ func checkBill(bid int) {
//currdate := time.Now().Local().Format("2006-01-02")
timstr = getDate(timin) + " 12:00"
} else {
- fmt.Println(timin, boldRed("is Not a Valid Datestring!"), "use: 'YYYY-MM-DD'")
+ fmt.Println(nli+timin, boldRed("is Not a Valid Datestring!"), "use: 'YYYY-MM-DD'")
+ fmt.Println(frame(negR(),false))
return
}
- fmt.Println(boldGreen(timstr))
+ fmt.Println(nli+boldGreen(timstr))
stmt, err := db.Prepare("UPDATE bills SET paid = datetime(?,'utc') WHERE id = ?")
checkErr(err)
_, err = stmt.Exec(timstr, bid)
@@ -502,6 +544,7 @@ func checkBill(bid int) {
checkErr(err)
_, err = stmt.Exec(timstr, custid)
checkErr(err)
+ fmt.Println(frame(posR(),false))
}
func checkTasks(in []int, billid int) {
@@ -1213,7 +1256,7 @@ func deleteTask(id int) {
func editCustomer(id int) {
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
- fmt.Println(boldGreen("Editing Customer ", id))
+ fmt.Println(frame(boldGreen("Editing Customer ", id),true))
var comp, name, addr string
var satz float64
rows, err := db.Query("SELECT company, name, address, satz FROM customers WHERE id = $1", id)
@@ -1222,7 +1265,7 @@ func editCustomer(id int) {
err = rows.Scan(&comp, &name, &addr, &satz)
checkErr(err)
} else {
- fmt.Println(boldRed("There Is No Customer"), id)
+ fmt.Println(nli+boldRed("There Is No Customer"), id)
return
//os.Exit(0)
}
@@ -1234,25 +1277,25 @@ func editCustomer(id int) {
if in!=""{
comp=in
}*/
- comp = getNewInterInput("New Company Name: ", comp)
+ comp = getNewInterInput("New Company Name: ", comp, nli)
/*fmt.Println("Old Name:",name)
in = getInterInput("Enter New:")
if in!=""{
name=in
}*/
- name = getNewInterInput("New Customer Name: ", name)
+ name = getNewInterInput("New Customer Name: ", name, nli)
/*fmt.Println("Old Adress:",addr)
in = getInterInput("Enter New:")
if in!=""{
addr=in
}*/
- addr = getNewInterInput("New Adress: ", addr)
+ addr = getNewInterInput("New Adress: ", addr, nli)
//fmt.Println("Old Hourly Rate:",satz)
for {
- satzstr := getNewInterInput("New Hourly Rate: ", fmt.Sprintf("%.2f", satz))
+ satzstr := getNewInterInput("New Hourly Rate: ", fmt.Sprintf("%.2f", satz), nli)
satz, err = strconv.ParseFloat(satzstr, 64)
if err != nil {
- fmt.Println(satzstr, boldRed("can not be Parsed as a Float."), "Try a shape of X.X")
+ fmt.Println(nli,satzstr, boldRed("can not be Parsed as a Float."), "Try a shape of X.X")
//os.Exit(0)
} else {
break
@@ -1270,13 +1313,14 @@ func editCustomer(id int) {
checkErr(err)
_, err = stmt.Exec(comp, name, addr, satz, id)
checkErr(err)
- fmt.Println("...Customer", id, "Updated")
+ fmt.Println(nli,"...Customer", id, "Updated")
+ fmt.Println(frame("",false))
}
func editTask(id int) {
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
- fmt.Println(boldGreen("Edit Task ", id))
+ fmt.Println(frame(boldGreen("Edit Task ", id),true))
var chk, prj int
var start, stop time.Time
var task, startstr, stopstr, comm string
@@ -1286,7 +1330,7 @@ func editTask(id int) {
err = rows.Scan(&prj, &start, &stop, &task, &comm, &chk)
checkErr(err)
} else {
- fmt.Println(boldRed("There Is No Task"), id)
+ fmt.Println(nli,boldRed("There Is No Task"), id)
return
//os.Exit(0)
}
@@ -1297,14 +1341,14 @@ func editTask(id int) {
if in!=""{
task=in
}*/
- task = getNewInterInput("New Task Name: ", task)
+ task = getNewInterInput("New Task Name: ", task, nli)
startstr = start.Local().Format("2006-01-02 15:04")
stopstr = stop.Local().Format("2006-01-02 15:04")
for {
- newstartstr := getNewInterInput("New Start time: ", startstr)
+ newstartstr := getNewInterInput("New Start time: ", startstr, nli)
if !isDateTime(newstartstr) {
- fmt.Println(newstartstr, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM'")
+ fmt.Println(nli, newstartstr, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM'")
} else {
startstr = newstartstr
break
@@ -1312,41 +1356,42 @@ func editTask(id int) {
}
//fmt.Println("Old End:",stopstr)
for {
- newend := getNewInterInput("New Stop time: ", stopstr)
+ newend := getNewInterInput("New Stop time: ", stopstr, nli)
if isDateTime(newend) {
stopstr = newend
break
} else {
- fmt.Println(newend, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM' or 'HH:MM'")
+ fmt.Println(nli, newend, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM' or 'HH:MM'")
}
}
//fmt.Println("Old Project:",prj)
for {
- newprj := getNewInterInput("New Project id: ", fmt.Sprint(prj))
+ newprj := getNewInterInput("New Project id: ", fmt.Sprint(prj), nli)
prj, err = strconv.Atoi(newprj)
if err != nil {
- fmt.Println(newprj, boldRed("is Not a Valid id."), "Try an Integer instead")
+ fmt.Println(nli,newprj, boldRed("is Not a Valid id."), "Try an Integer instead")
}
if !isProject(prj) {
- fmt.Println(boldRed("There is no project"), prj)
+ fmt.Println(nli, boldRed("There is no project"), prj)
} else {
break
}
}
- comm = getNewInterMultiInput("New Comment: ", comm)
+ comm = getNewInterMultiInput("New Comment: ", comm, nli)
stmt, err := db.Prepare("UPDATE timetable SET task = ?, comment = ?, start = datetime(?,'utc'), stop = datetime(?,'utc'), project = ? WHERE id = ?")
checkErr(err)
_, err = stmt.Exec(task, comm, startstr, stopstr, prj, id)
checkErr(err)
updateProject(prj)
- fmt.Println("...Task", id, "Updated")
+ fmt.Println(nli, "...Task", id, "Updated")
+ fmt.Println(frame("",false))
}
func editProject(id int) {
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
- fmt.Println(boldGreen("Edit Project ", id))
+ fmt.Println(frame(boldGreen("Edit Project ", id),true))
var fin, cust int
var first time.Time
var name, nfirst, comm string
@@ -1356,13 +1401,13 @@ func editProject(id int) {
err = rows.Scan(&name, &comm, &first, &fin, &cust)
checkErr(err)
- name = getNewInterInput("New Name: ", name)
+ name = getNewInterInput("New Name: ", name, nli)
nfirst = first.Local().Format("2006-01-02 15:04")
// Get New PRoject Begin Date
for {
- newfirststr := getNewInterInput("New Begin time: ", nfirst)
+ newfirststr := getNewInterInput("New Begin time: ", nfirst, nli)
if !isDateTime(newfirststr) {
- fmt.Println(newfirststr, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM'")
+ fmt.Println(nli,newfirststr, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM'")
} else {
nfirst = newfirststr
break
@@ -1370,21 +1415,22 @@ func editProject(id int) {
}
// Get New Customer
for {
- newcu := getNewInterInput("New Customer id: ", fmt.Sprint(cust))
+ newcu := getNewInterInput("New Customer id: ", fmt.Sprint(cust), nli)
icust, err := strconv.Atoi(newcu)
if err != nil {
- fmt.Println(newcu, boldRed("is Not a Valid id."), "Try an Integer instead")
+ fmt.Println(nli,newcu, boldRed("is Not a Valid id."), "Try an Integer instead")
} else if !isCustomer(icust) {
- fmt.Println(boldRed("There is no Customer"), icust)
+ fmt.Println(nli,boldRed("There is no Customer"), icust)
} else {
cust = icust
break
}
}
// Get Comment
- comm = getNewInterMultiInput("New Comment: ", comm)
+ comm = getNewInterMultiInput("New Comment: ", comm, nli)
} else {
- fmt.Println(boldRed("There Is No Project"), id)
+ fmt.Println(nli,boldRed("There Is No Project"), id)
+ fmt.Println(frame(negR(),false))
return
//os.Exit(0)
}
@@ -1394,7 +1440,8 @@ func editProject(id int) {
_, err = stmt.Exec(name, comm, nfirst, cust, id)
checkErr(err)
updateProject(id)
- fmt.Println("...Project", id, "Updated")
+ fmt.Println(nli,"...Project", id, "Updated")
+ fmt.Println(frame("",false))
}
func isBill(id int) bool {
@@ -1446,32 +1493,55 @@ func isCustomer(id int) bool {
func getDateTime(in string) string {
r := regexp.MustCompile(`(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})`)
+ //r := regexp.MustCompile(`(\d{4})-(((0)[0-9])|((1)[0-2]))-([0-2][0-9]|(3)[0-1]) ([01]?[0-9]|2[0-3]):[0-5][0-9]`)
return r.FindString(in)
}
func getDate(in string) string {
- r := regexp.MustCompile(`(\d{4})-(\d{2})-(\d{2})`)
+ //r := regexp.MustCompile(`(\d{4})-(\d{2})-(\d{2})`)
+ r := regexp.MustCompile(`(\d{4})-(((0)[0-9])|((1)[0-2]))-([0-2][0-9]|(3)[0-1])`)
return r.FindString(in)
}
func getTime(in string) string {
- r := regexp.MustCompile(`(\d{2}):(\d{2})`)
+ //r := regexp.MustCompile(`(\d{2}):(\d{2})`)
+ r := regexp.MustCompile(`([01]?[0-9]|2[0-3]):[0-5][0-9]`)
return r.FindString(in)
}
func isDateTime(in string) bool {
- match, _ := regexp.MatchString(`(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})`, in)
- return match
+ //match, _ := regexp.MatchString(`(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})`, in)
+ //match, _ := regexp.MatchString(`(\d{4})-(((0)[0-9])|((1)[0-2]))-([0-2][0-9]|(3)[0-1]) ([01]?[0-9]|2[0-3]):[0-5][0-9]`, in)
+ const form = "2006-01-02 15:04"
+ _,err := time.Parse(form,in)
+ if err == nil {
+ return true
+ }
+ return false
}
func isDate(in string) bool {
- match, _ := regexp.MatchString(`(\d{4})-(\d{2})-(\d{2})`, in)
- return match
+ //match, _ := regexp.MatchString(`(\d{4})-(\d{2})-(\d{2})`, in)
+ //match, _ := regexp.MatchString(`(\d{4})-(((0)[0-9])|((1)[0-2]))-([0-2][0-9]|(3)[0-1])`, in)
+ //return match
+ const form = "2006-01-02"
+ _,err := time.Parse(form,in)
+ if err == nil {
+ return true
+ }
+ return false
}
func isTime(in string) bool {
- match, _ := regexp.MatchString(`(\d{2}):(\d{2})`, in)
- return match
+ //match, _ := regexp.MatchString(`(\d{2}):(\d{2})`, in)
+ //match, _ := regexp.MatchString(`([01]?[0-9]|2[0-3]):[0-5][0-9]`, in)
+ //return match
+ const form = "15:04"
+ _,err := time.Parse(form,in)
+ if err == nil {
+ return true
+ }
+ return false
}
/*
diff --git a/utils.go b/utils.go
index 9d6fc91..bed36aa 100644
--- a/utils.go
+++ b/utils.go
@@ -10,17 +10,38 @@ import (
"strconv"
"strings"
"unicode/utf8"
+ "math/rand"
+ "time"
)
const (
framewidth int = 40
- li = "\u2501"
- mli = "\u2501\u252f\u2501\u2501" //Masterline -T-
- sli = " \u251c\u2500 " //Slave Line L_
- nli = " \u2502 " //noone Line |
- fli = " \u2515\u2501\u2501" //Footer Line L
+ li string = "\u2500"
+ mli string = "\u2500\u2530\u2500\u2500" //Masterline -T-
+ sli string = " \u2520\u2500 " //Slave Line L_
+ nli string = " \u2503 " //noone Line |
+ fli string = " \u2516\u2500\u2500" //Footer Line L
)
+var positive = [...]string {"Done","Accomplished","Finished","Congrats","Completed"}
+var negative = [...]string {"Failed","Try Again","Sorry","Not Quite Yet","Incomplete"}
+
+func posR() (out string){
+ s1 := rand.NewSource(time.Now().UnixNano())
+ r1 := rand.New(s1)
+ n := r1.Intn(len(positive))
+ out = positive[n]
+ return
+}
+
+func negR() (out string){
+ s1 := rand.NewSource(time.Now().UnixNano())
+ r1 := rand.New(s1)
+ n := r1.Intn(len(negative))
+ out = negative[n]
+ return
+}
+
func frame(text string, head bool) (out string) {
if head {
out = mli + text
@@ -36,8 +57,8 @@ func frame(text string, head bool) (out string) {
}
if head {
out = "\n" + out
- }else{
- out = out + "\n"
+ //}else{
+ // out = out + "\n"
}
return
}