testdoor.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. d.Write(door.CRNL)
  77. m := door.Menu{Panel: door.Panel{Width: 25,
  78. X: 5,
  79. Y: 5,
  80. Style: door.DOUBLE,
  81. Title: "Please Select:",
  82. TitleOffset: 3,
  83. BorderColor: door.ColorText("BRI CYAN ON BLA")}}
  84. m.SelectedR = door.MakeMenuRender(door.ColorText("BOLD CYAN"),
  85. door.ColorText("BOLD BLUE"),
  86. door.ColorText("BOLD CYAN"),
  87. door.ColorText("BOLD BLUE"))
  88. m.UnselectedR = door.MakeMenuRender(door.ColorText("BOLD YEL ON BLUE"),
  89. door.ColorText("BOLD WHI ON BLUE"),
  90. door.ColorText("BOLD YEL ON BLUE"),
  91. door.ColorText("BOLD CYAN ON BLUE"))
  92. m.MenuOptions = []door.MenuOption{{rune('1'), "Play A Game"},
  93. {rune('A'), "Ask BUGZ for Help"},
  94. {rune('D'), "Drop to DOS"},
  95. {rune('Q'), "Quit"}}
  96. m.Build()
  97. // Yes, the render functions are working
  98. /*
  99. test := door.Line{Text: "[T] Testing Render...", RenderF: m.SelectedR}
  100. d.Write(test.Output() + door.Reset + door.CRNL)
  101. test.RenderF = m.UnselectedR
  102. d.Write(test.Output() + door.Reset + door.CRNL)
  103. d.Write(door.Reset + door.CRNL + "Press a key to continue...")
  104. d.WaitKey(120, 0)
  105. */
  106. d.Write(door.Clrscr)
  107. _ = m.Choose(&d)
  108. // d.Write(m.Output())
  109. // d.WaitKey(120, 0)
  110. d.Write(door.Reset + door.CRNL + door.CRNL)
  111. SPACE := [...]string{
  112. "\x1b[?7h\x1b[255D\x1b[0;1;32m\xdc\x1b[42m\xb2\xb2\xb2\xb2\xdb\x1b[40m\xdc \x1b[42m\xb1\xb1\xb2\xb2\xdb\xdb\x1b[4C\xb1\xb2\xb2\xdb\x1b[4C\xb1\xb2\xb2\xdb\xdb\x1b[3C\xb1\xb2\xb2\xdb\xdb\x1b[11C\xb1\xb2\xb2\xdb\x1b[4C\xb1\xb2\xb2\xdb\xdb\x1b[3C\xb1\xb2\xb2\xdb\xdb\x1b[40m",
  113. "\x1b[42m\xb1\xb1\x1b[4C\xdb\x1b[2C\xb1\xb1\x1b[2C\xdb\xdb\x1b[2C\xb0\xb1\x1b[2C\xb2\xdb\x1b[2C\xb0\xb1\x1b[3C\xdb\xdb\x1b[1C\xb0\xb1\x1b[3C\xdb\xdb\x1b[9C\xb0\xb1\x1b[2C\xb2\xdb\x1b[2C\xb0\xb1\x1b[3C\xdb\xdb\x1b[1C\xb0\xb1\x1b[3C\xdb\xdb\x1b[40m",
  114. "\x1b[42m\xb0\xb1\x1b[40m\xdc\xdc\xdc\xdc \x1b[42m\xb0\xb1\x1b[2C\xb2\xdb\x1b[1C \xb0\x1b[4C\xb2\xdb\x1b[1C\xb0\xb0\x1b[6C\xb0\xb0\x1b[0;32m\xdc\xdc\x1b[11C\x1b[42m \x1b[1m\xb0\x1b[4C\xb2\xdb\x1b[1C\xb0\xb0\x1b[6C\xb0\xb0\x1b[0;32m\xdc\xdc",
  115. " \x1b[1m\xdf\xdf\xdf\xdf\x1b[42m\xb2\xb2\x1b[2C\xb0\xb0\xb1\xb1\xb2\x1b[2C \xb0\xb0\xb1\xb1\xb2\xb2\x1b[1C \xb0\x1b[6C \xb0\x1b[0;32m\xdf\xdf\x1b[11C\x1b[42m \x1b[1m\xb0\xb0\xb1\xb1\xb2\xb2\x1b[1C \xb0\x1b[6C \xb0\x1b[0;32m\xdf\xdf",
  116. "\xdb \x1b[1;42m\xb1\xb2\x1b[2C \xb0\x1b[5C \x1b[4C\xb1\xb2\x1b[1C \x1b[3C\xb1\xb2\x1b[1C \x1b[3C\xb1\xb2\x1b[8C \x1b[4C\xb1\xb2\x1b[1C \x1b[3C\xb1\xb2\x1b[1C \x1b[3C\xb1\xb2\x1b[40m",
  117. "\x1b[0;32m\xdf\x1b[42m \x1b[40m\xdb\x1b[1;42m\xb0\xb0\xb1\x1b[0;32m\xdf \x1b[42m \x1b[7C \x1b[2C\x1b[1m\xb0\xb1\x1b[3C \xb0\xb0\xb1\x1b[3C \xb0\xb0\xb1\x1b[10C \x1b[2C\xb0\xb1\x1b[3C \xb0\xb0\xb1\x1b[3C \xb0\xb0\xb1\x1b[40m",
  118. "",
  119. "",
  120. "\x1b[37mBugz in space, with a deck of cards",
  121. "\x1b[0m",
  122. }
  123. d.Write(door.Clrscr)
  124. for _, line := range SPACE {
  125. if door.Unicode {
  126. d.Write(door.CP437_to_Unicode(line) + door.CRNL)
  127. } else {
  128. d.Write(line + door.CRNL)
  129. }
  130. }
  131. d.Write(door.Reset + door.CRNL + "Press a key to continue...")
  132. d.WaitKey(120, 0)
  133. message = fmt.Sprintf("Returning %s to the BBS..."+door.CRNL, name)
  134. d.Write(message)
  135. d.WaitKey(3, 0)
  136. left = d.TimeLeft()
  137. message = fmt.Sprintf("You had %0.2f minutes / %0.2f seconds remaining!"+door.CRNL, left.Minutes(), left.Seconds())
  138. d.Write(message)
  139. fmt.Println("Ending testdoor.go")
  140. }