testdoor.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. if false {
  42. bar := door.BarLine{Line: door.Line{DefaultColor: door.ColorText("BOLD YELLOW")}, Width: 20, Style: door.HALF_STEP}
  43. bar2 := door.BarLine{Width: 30, Style: door.PERCENT_SPACE}
  44. bar2.ColorRange = []door.BarRange{
  45. {2500, door.ColorText("RED")},
  46. {5000, door.ColorText("BROWN")},
  47. {7500, door.ColorText("BOLD YEL")},
  48. {9500, door.ColorText("GREEN")},
  49. {10100, door.ColorText("BRI GRE")}}
  50. bar3 := door.BarLine{Width: 15, Style: door.GRADIENT, Line: door.Line{DefaultColor: door.ColorText("CYAN")}}
  51. var percentage int64
  52. bar.UpdateP = pctUpdate(&percentage)
  53. bar2.UpdateP = pctUpdate(&percentage)
  54. bar3.UpdateP = pctUpdate(&percentage)
  55. bar_start := door.Goto(3, 15)
  56. for f := 0; f <= 100; f++ {
  57. percentage = int64(f * 100)
  58. d.Write(bar_start)
  59. bar.Update()
  60. d.Write(bar.Output())
  61. d.Write(" " + door.Reset)
  62. bar2.Update()
  63. d.Write(bar2.Output())
  64. d.Write(door.Reset + " ")
  65. bar3.Update()
  66. d.Write(bar3.Output())
  67. if d.Disconnected {
  68. break
  69. }
  70. time.Sleep(time.Millisecond * 100)
  71. // d.WaitKey(0, 55000)
  72. }
  73. }
  74. d.Write(door.Reset + door.CRNL + "Press a key to continue...")
  75. d.WaitKey(120, 0)
  76. m := door.Menu{Panel: door.Panel{Width: 25,
  77. X: 5,
  78. Y: 5,
  79. Style: door.DOUBLE,
  80. Title: "Please Select:",
  81. TitleOffset: 3,
  82. BorderColor: door.ColorText("BRI CYAN ON BLA")}}
  83. m.SelectedR = door.MakeMenuRender(door.ColorText("BOLD CYAN"),
  84. door.ColorText("BOLD BLUE"),
  85. door.ColorText("BOLD CYAN"),
  86. door.ColorText("BOLD BLUE"))
  87. m.UnselectedR = door.MakeMenuRender(door.ColorText("BOLD YEL ON BLUE"),
  88. door.ColorText("BOLD WHI ON BLUE"),
  89. door.ColorText("BOLD YEL ON BLUE"),
  90. door.ColorText("BOLD CYAN ON BLUE"))
  91. m.MenuOptions = []door.MenuOption{{rune('1'), "Play A Game"},
  92. {rune('A'), "Ask BUGZ for Help"},
  93. {rune('D'), "Drop to DOS"},
  94. {rune('Q'), "Quit"}}
  95. m.Build()
  96. test := door.Line{Text: "[T] Testing Render...", RenderF: m.SelectedR}
  97. d.Write(test.Output() + door.Reset + door.CRNL)
  98. test.RenderF = m.UnselectedR
  99. d.Write(test.Output() + door.Reset + door.CRNL)
  100. d.Write(door.Reset + door.CRNL + "Press a key to continue...")
  101. d.WaitKey(120, 0)
  102. d.Write(door.Clrscr)
  103. _ = m.Choose(&d)
  104. // d.Write(m.Output())
  105. // d.WaitKey(120, 0)
  106. d.Write(door.Reset + door.CRNL + door.CRNL)
  107. message = fmt.Sprintf("Returning %s to the BBS..."+door.CRNL, name)
  108. d.Write(message)
  109. d.WaitKey(3, 0)
  110. left = d.TimeLeft()
  111. message = fmt.Sprintf("You had %0.2f minutes / %0.2f seconds remaining!"+door.CRNL, left.Minutes(), left.Seconds())
  112. d.Write(message)
  113. fmt.Println("Ending testdoor.go")
  114. }