testdoor.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package main
  2. import (
  3. "fmt"
  4. "red-green/door"
  5. "time"
  6. )
  7. func pctUpdate(pct *int64) func() int64 {
  8. return func() int64 {
  9. return *pct
  10. }
  11. }
  12. func main() {
  13. fmt.Println("Starting testdoor.go")
  14. d := door.Door{}
  15. d.Init()
  16. reset := door.Reset
  17. bold := door.Color(1, 37, 40)
  18. bolder := door.ColorText("BLI BOLD YEL ON BLUE")
  19. d.Write("Welcome to " + bolder + "door32.sys" + reset + door.CRNL + "..." + door.CRNL)
  20. key := d.WaitKey(door.Inactivity, 0)
  21. message := fmt.Sprintf("Key %s%d / %x%s"+door.CRNL, bold, key, key, reset)
  22. d.Write(message)
  23. b := door.Box{20, 1}
  24. d.Write(b.Top() + door.CRNL)
  25. // or %-20s
  26. message = fmt.Sprintf("%20s", "SHAZAM!")
  27. d.Write(b.Row(message) + door.CRNL)
  28. d.Write(b.Middle() + door.CRNL)
  29. d.Write(b.Row(fmt.Sprintf("%-20s", "Meow?")) + door.CRNL)
  30. d.Write(b.Bottom() + door.CRNL)
  31. left := d.TimeLeft()
  32. message = fmt.Sprintf("You have %0.2f minutes / %0.2f seconds remaining..."+door.CRNL, left.Minutes(), left.Seconds())
  33. d.Write(message)
  34. inputColor := door.ColorText("BRI WHI ON BLUE")
  35. prompt := door.Line{Text: "What is YOUR Name: "}
  36. prompt.RenderF = door.RenderBlueYellow
  37. d.Write(prompt.Output() + inputColor)
  38. // d.Write("What is your name: " + inputColor)
  39. name := d.Input(25)
  40. d.Write(door.Reset + door.CRNL)
  41. bar := door.BarLine{Line: door.Line{DefaultColor: door.ColorText("BOLD YELLOW")}, Width: 20, Style: door.HALF_STEP}
  42. bar2 := door.BarLine{Width: 30, Style: door.PERCENT_SPACE}
  43. bar2.ColorRange = []door.BarRange{
  44. {2500, door.ColorText("RED")},
  45. {5000, door.ColorText("BROWN")},
  46. {7500, door.ColorText("BOLD YEL")},
  47. {9500, door.ColorText("GREEN")},
  48. {10100, door.ColorText("BRI GRE")}}
  49. bar3 := door.BarLine{Width: 15, Style: door.GRADIENT, Line: door.Line{DefaultColor: door.ColorText("CYAN")}}
  50. var percentage int64
  51. bar.UpdateP = pctUpdate(&percentage)
  52. bar2.UpdateP = pctUpdate(&percentage)
  53. bar3.UpdateP = pctUpdate(&percentage)
  54. bar_start := door.Goto(3, 15)
  55. for f := 0; f <= 100; f++ {
  56. percentage = int64(f * 100)
  57. d.Write(bar_start)
  58. bar.Update()
  59. d.Write(bar.Output())
  60. d.Write(" " + door.Reset)
  61. bar2.Update()
  62. d.Write(bar2.Output())
  63. d.Write(door.Reset + " ")
  64. bar3.Update()
  65. d.Write(bar3.Output())
  66. if d.Disconnected {
  67. break
  68. }
  69. time.Sleep(time.Millisecond * 100)
  70. // d.WaitKey(0, 55000)
  71. }
  72. d.Write(door.CRNL)
  73. message = fmt.Sprintf("Returning %s to the BBS..."+door.CRNL, name)
  74. d.Write(message)
  75. d.WaitKey(3, 0)
  76. left = d.TimeLeft()
  77. message = fmt.Sprintf("You had %0.2f minutes / %0.2f seconds remaining!"+door.CRNL, left.Minutes(), left.Seconds())
  78. d.Write(message)
  79. fmt.Println("Ending testdoor.go")
  80. }