summaryrefslogtreecommitdiff
path: root/utils.go
diff options
context:
space:
mode:
authorNikolaus Gotsche <n@softwarefools.com>2018-09-05 04:10:54 +0200
committerNikolaus Gotsche <n@softwarefools.com>2018-09-05 04:10:54 +0200
commit4a4f372605d56f2241699da6a5bf8dae7eda2b86 (patch)
tree80025d8ee00a1ea37ff94b351ca720b7e2fc110e /utils.go
parentd6dd3088da980467909a5a43fb393260c3ff7c93 (diff)
TOML Configuration added. texification working. outsourced some functions to my utilitys. billed tasks not yet checked
Diffstat (limited to 'utils.go')
-rw-r--r--utils.go97
1 files changed, 97 insertions, 0 deletions
diff --git a/utils.go b/utils.go
new file mode 100644
index 0000000..c94f94b
--- /dev/null
+++ b/utils.go
@@ -0,0 +1,97 @@
+package main
+
+import (
+ "fmt"
+ "bufio"
+ "os"
+ "strings"
+ "strconv"
+ "runtime"
+)
+
+func isSure(quest string) bool {
+ fmt.Printf("%s (type 'y/Y/yes' to confirm) : ",quest)
+ in := bufio.NewReader(os.Stdin)
+ line, err := in.ReadString('\n')
+ if(runtime.GOOS == "windows"){
+ line = strings.TrimSuffix(line, "\r\n") //for Windows
+ }else{
+ line = strings.TrimSuffix(line, "\n")
+ }
+ checkErr(err)
+
+ if ( line == "yes" || line == "y" || line == "Y") {
+ return true
+ } else {
+ return false
+ }
+}
+
+func checkErr(err error) {
+ if err != nil {
+ panic(err)
+ }
+}
+
+func getInput(quest string) string {
+ fmt.Print(quest)
+ in := bufio.NewReader(os.Stdin)
+ line, err := in.ReadString('\n')
+ if(runtime.GOOS == "windows"){
+ line = strings.TrimSuffix(line, "\r\n") //for Windows
+ }else{
+ line = strings.TrimSuffix(line, "\n")
+ }
+ checkErr(err)
+ return line
+}
+
+func getNewInput(quest,old string) string {
+ if old != "" {
+ fmt.Println("Current:",old)
+ }
+ fmt.Print(quest)
+ in := bufio.NewReader(os.Stdin)
+ line, err := in.ReadString('\n')
+ if(runtime.GOOS == "windows"){
+ line = strings.TrimSuffix(line, "\r\n") //for Windows
+ }else{
+ line = strings.TrimSuffix(line, "\n")
+ }
+ checkErr(err)
+ if line == "" {
+ return old
+ }else{
+ return line
+ }
+}
+
+func stringArray2String(in []string, delim string) (string) {
+ var out string
+ for i,a := range in {
+ if i==0 {
+ out=a
+ }else{
+ out=fmt.Sprintf("%s%s%s",out,delim,a)
+ }
+ }
+ return out
+}
+
+func string2FloatArray(in string,delim string)(out []float64) {
+ read := strings.Split(in,delim)
+ for _,s := range read{
+ fs,err := strconv.ParseFloat(s,64)
+ checkErr(err)
+ out = append(out,fs)
+ }
+ return
+}
+
+func string2StringArray(in string,delim string)(out []string) {
+ read := strings.Split(in,delim)
+ for _,s := range read{
+ out = append(out,s)
+ }
+ return
+}