helpers.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package helpers
  2. import (
  3. "bufio"
  4. "fmt"
  5. "os"
  6. "github.com/logrusorgru/aurora"
  7. )
  8. // GetUserInputChoice will prompt the user if there are only two choices (like a or b)
  9. func GetUserInputChoice(_prompt string, _selection1 string, _selection2 string) string {
  10. reader := bufio.NewReader(os.Stdin)
  11. var answer string
  12. for answer != _selection1 && answer != _selection2 {
  13. Printf(_prompt+" ("+_selection1+"/"+_selection2+"): ", 0)
  14. answer, _ = reader.ReadString('\n')
  15. answer = answer[0:1]
  16. }
  17. return answer
  18. }
  19. // GetUserInput will prompt the user if there are more possibilies than 2
  20. func GetUserInput(_prompt string) string {
  21. reader := bufio.NewReader(os.Stdin)
  22. Printf(_prompt+": ", 0)
  23. answer, _ := reader.ReadString('\n')
  24. answer = answer[0 : len(answer)-1]
  25. return answer
  26. }
  27. func ColorizeCommand(_command string) string {
  28. return fmt.Sprintf("%s", aurora.Green("dit "+_command))
  29. }
  30. func PrintLine(_line string, _level int) {
  31. switch _level {
  32. case 0:
  33. fmt.Println(fmt.Sprintf("%s %s", aurora.Green("dit >"), _line))
  34. case 1:
  35. fmt.Println(fmt.Sprintf("%s %s %s", aurora.Bold(aurora.Brown("warn")), aurora.Bold(aurora.Brown(">")), _line))
  36. case 2:
  37. fmt.Println(fmt.Sprintf("%s %s %s", aurora.Bold(aurora.BgRed(aurora.Gray("err"))), aurora.Bold(aurora.Red(" >")), _line))
  38. case 3:
  39. fmt.Println(fmt.Sprintf("%s %s %s", aurora.Cyan("demo"), aurora.Cyan(">"), _line))
  40. }
  41. }
  42. func Printf(_line string, _level int) {
  43. switch _level {
  44. case 0:
  45. fmt.Printf(fmt.Sprintf("%s %s", aurora.Green("dit >"), _line))
  46. case 1:
  47. fmt.Printf(fmt.Sprintf("%s %s %s", aurora.Bold(aurora.Brown("warn")), aurora.Bold(aurora.Brown(">")), _line))
  48. case 2:
  49. fmt.Printf(fmt.Sprintf("%s %s %s", aurora.Bold(aurora.BgRed(aurora.Gray("err"))), aurora.Bold(aurora.Red(" >")), _line))
  50. case 3:
  51. fmt.Printf(fmt.Sprintf("%s %s %s", aurora.Cyan("demo"), aurora.Cyan(">"), _line))
  52. }
  53. }