testdoor.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "red-green/door"
  6. "runtime/debug"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. func pctUpdate(pct *int64) func() int64 {
  12. return func() int64 {
  13. return *pct
  14. }
  15. }
  16. // Can I add a function to Door?
  17. // NO: cannot define new methods on non-local type door.Door
  18. /*
  19. func (d *door.Door) PressAKey() {
  20. d.Write(door.Reset + door.CRNL + "Press a key to continue...")
  21. d.Key()
  22. d.Write(door.CRNL)
  23. }
  24. */
  25. func press_a_key(d *door.Door) int {
  26. d.Write(door.Reset + door.CRNL + "Press a key to continue...")
  27. var k int = d.Key()
  28. d.Write(door.CRNL)
  29. return k
  30. }
  31. func about_test_door(d *door.Door) {
  32. var W int = 60
  33. var center_x int = (door.Width - W) / 2
  34. var center_y int = (door.Height - 16) / 2
  35. var about door.Panel = door.Panel{X: center_x,
  36. Y: center_y,
  37. Width: W,
  38. Style: door.SINGLE_DOUBLE,
  39. BorderColor: door.ColorText("BOLD YELLOW ON BLUE"),
  40. }
  41. about.Lines = append(about.Lines, door.Line{Text: fmt.Sprintf("%*s", -W, "About This Door"),
  42. DefaultColor: door.ColorText("BOLD CYAN ON BLUE")})
  43. about.Lines = append(about.Lines, about.Spacer())
  44. about.Lines = append(about.Lines, door.Line{Text: fmt.Sprintf("%*s", -W, "Test Door written in go, using go door.")})
  45. var copyright string = "(C) 2022 Bugz, Red Green Software"
  46. if door.Unicode {
  47. copyright = strings.Replace(copyright, "(C)", "\u00a9", -1)
  48. }
  49. about.Lines = append(about.Lines,
  50. door.Line{Text: fmt.Sprintf("%*s", -W, copyright),
  51. DefaultColor: door.ColorText("BOLD WHITE ON BLUE")})
  52. for _, text := range []string{"",
  53. "This door was written by Bugz.",
  54. "",
  55. "It is written in Go, understands CP437 and unicode, adapts",
  56. "to screen sizes, uses door32.sys, supports TheDraw Fonts,",
  57. "has NoMoreSecrets effect, and runs on Linux and Windows."} {
  58. about.Lines = append(about.Lines, door.Line{Text: fmt.Sprintf("%*s", -W, text)})
  59. }
  60. var better door.NoMoreSecretsConfig = door.NoMoreSecretsDefault
  61. better.Color = door.ColorText("BRI CYAN ON BLUE")
  62. door.NoMoreSecrets(about.Output(), d, &better)
  63. }
  64. func MainMenu() door.Menu {
  65. // Make the main menu
  66. var m door.Menu = door.Menu{Panel: door.Panel{Width: 45,
  67. X: 5,
  68. Y: 5,
  69. Style: door.DOUBLE,
  70. Title: "[ Main Menu: ]",
  71. TitleOffset: 3,
  72. BorderColor: door.ColorText("BRI CYAN ON BLA")}}
  73. m.SelectedR = door.MakeMenuRender(door.ColorText("BOLD CYAN"),
  74. door.ColorText("BOLD BLUE"),
  75. door.ColorText("BOLD WHITE"),
  76. door.ColorText("BOLD CYAN"))
  77. m.UnselectedR = door.MakeMenuRender(door.ColorText("BOLD YEL ON BLUE"),
  78. door.ColorText("BOLD WHI ON BLUE"),
  79. door.ColorText("BOLD YEL ON BLUE"),
  80. door.ColorText("BOLD CYAN ON BLUE"))
  81. m.AddSelection("A", "ANSI Display")
  82. m.AddSelection("C", "Crash")
  83. m.AddSelection("D", "Display Information (dropfile, screen)")
  84. m.AddSelection("F", "Font Demo")
  85. m.AddSelection("I", "Input Prompt Demo")
  86. m.AddSelection("M", "Menu Demo")
  87. m.AddSelection("P", "Progress Bars Demo")
  88. m.AddSelection("S", "Show Panel")
  89. m.AddSelection("T", "Test Door About")
  90. m.AddSelection("W", "Screen Width")
  91. m.AddSelection("Q", "Quit")
  92. return m
  93. }
  94. func display_information(d *door.Door) {
  95. d.Write(door.Clrscr + door.CRNL)
  96. var keyColor string = door.ColorText("BRI GREEN")
  97. var sepColor string = door.ColorText("BRI YEL")
  98. var valColor string = door.ColorText("CYAN")
  99. var nice_format func(string, string) string = func(key string, value string) string {
  100. return fmt.Sprintf("%s%-20s %s: %s%s", keyColor, key, sepColor, valColor, value) + door.CRNL
  101. }
  102. d.Write(nice_format("BBS Software", d.Config.BBSID))
  103. d.Write(nice_format("Time Left", strconv.Itoa(d.Config.Time_left)))
  104. d.Write(nice_format("Real Name", d.Config.Real_name))
  105. d.Write(nice_format("Comm Type", strconv.Itoa(d.Config.Comm_type)))
  106. d.Write(nice_format("Comm Handle", strconv.Itoa(d.Config.Comm_handle)))
  107. d.Write(nice_format("Baudrate", strconv.Itoa(d.Config.Baudrate)))
  108. d.Write(nice_format("Handle", d.Config.Handle))
  109. d.Write(nice_format("User #", strconv.Itoa(d.Config.User_number)))
  110. d.Write(nice_format("Security Level", strconv.Itoa(d.Config.Security_level)))
  111. d.Write(nice_format("Node #", strconv.Itoa(d.Config.Node)))
  112. d.Write(nice_format("Emulation", strconv.Itoa(d.Config.Emulation)))
  113. d.Write(nice_format("Unicode", strconv.FormatBool(door.Unicode)))
  114. d.Write(nice_format("CP437", strconv.FormatBool(door.CP437)))
  115. d.Write(nice_format("Full CP437", strconv.FormatBool(door.Full_CP437)))
  116. d.Write(nice_format("Screen Size", fmt.Sprintf("%d X %d", door.Width, door.Height)))
  117. }
  118. func display_ansi(d *door.Door) {
  119. var art []string = ANSIGrowl()
  120. d.Write(door.Clrscr)
  121. for _, line := range art {
  122. d.Write(line + door.CRNL)
  123. }
  124. }
  125. func font_demo(d *door.Door) {
  126. var output []string
  127. var l int
  128. var centering string
  129. d.Write(door.Clrscr + door.CRNL) // + door.CRNL + door.CRNL)
  130. var fac door.ColorFont = FontAmazonCyan()
  131. output, l = fac.Output("ABCDEFGHIJKL")
  132. if l > door.Width {
  133. output, l = fac.Output("Cyan")
  134. }
  135. if l < door.Width {
  136. centering = strings.Repeat(" ", (door.Width-l)/2)
  137. for _, o := range output {
  138. d.Write(fmt.Sprintf("%s%s%s", centering, o, door.Reset) + door.CRNL)
  139. }
  140. d.Write(door.CRNL)
  141. }
  142. var patch door.ColorMap = fac.Scan(6)
  143. // log.Printf("Patch: %#v\n", patch)
  144. fac.Modify(4, patch)
  145. output, l = fac.Output("Blue")
  146. centering = strings.Repeat(" ", (door.Width-l)/2)
  147. for _, o := range output {
  148. d.Write(fmt.Sprintf("%s%s%s", centering, o, door.Reset) + door.CRNL)
  149. }
  150. d.Write(door.CRNL)
  151. fac.Modify(1, patch)
  152. output, l = fac.Output("Red")
  153. centering = strings.Repeat(" ", (door.Width-l)/2)
  154. for _, o := range output {
  155. d.Write(fmt.Sprintf("%s%s%s", centering, o, door.Reset) + door.CRNL)
  156. }
  157. d.Write(door.CRNL)
  158. press_a_key(d)
  159. var fab door.ColorFont = FontAnarchyBlue()
  160. output, l = fab.Output("Bugz is Here!")
  161. if l > door.Width {
  162. output, l = fab.Output("Hello")
  163. }
  164. if l < door.Width {
  165. centering = strings.Repeat(" ", (door.Width-l)/2)
  166. for _, o := range output {
  167. d.Write(centering + o + door.Reset + door.CRNL)
  168. }
  169. d.Write(door.CRNL)
  170. }
  171. var unchain door.ColorFont = FontUnchained()
  172. output, l = unchain.Output("Hi There!")
  173. if l > door.Width {
  174. output, l = unchain.Output("Meow")
  175. }
  176. if l < door.Width {
  177. centering = strings.Repeat(" ", (door.Width-l)/2)
  178. for _, o := range output {
  179. d.Write(centering + o + door.Reset + door.CRNL)
  180. }
  181. d.Write(door.CRNL)
  182. }
  183. press_a_key(d)
  184. var asylum door.ColorFont = FontAsylum()
  185. output, l = asylum.Output("Bugz ROCKS")
  186. if l > door.Width {
  187. output, l = asylum.Output("Aslym")
  188. }
  189. if l < door.Width {
  190. centering = strings.Repeat(" ", (door.Width-l)/2)
  191. for _, o := range output {
  192. d.Write(centering + o + door.Reset + door.CRNL)
  193. }
  194. d.Write(door.CRNL)
  195. }
  196. var brain door.ColorFont = FontBrainDmgBlu()
  197. output, l = brain.Output("I'm so BLUE")
  198. if l > door.Width {
  199. output, l = brain.Output("Blue")
  200. }
  201. if l < door.Width {
  202. centering = strings.Repeat(" ", (door.Width-l)/2)
  203. for _, o := range output {
  204. d.Write(centering + o + door.Reset + door.CRNL)
  205. }
  206. d.Write(door.CRNL)
  207. }
  208. var boner door.ColorFont = FontBoner()
  209. output, l = boner.Output("Welcome!")
  210. if l < door.Width {
  211. centering = strings.Repeat(" ", (door.Width-l)/2)
  212. for _, o := range output {
  213. d.Write(centering + o + door.Reset + door.CRNL)
  214. }
  215. d.Write(door.CRNL)
  216. }
  217. press_a_key(d)
  218. var descent door.ColorFont = FontDescent()
  219. output, l = descent.Output("Meanwhile...")
  220. if l > door.Width {
  221. output, l = descent.Output("BUGZ")
  222. }
  223. if l < door.Width {
  224. centering = strings.Repeat(" ", (door.Width-l)/2)
  225. for _, o := range output {
  226. d.Write(centering + o + door.Reset + door.CRNL)
  227. }
  228. d.Write(door.CRNL)
  229. }
  230. var remorse door.ColorFont = FontRemorse()
  231. output, l = remorse.Output("Enjoy the fonts")
  232. if l > door.Width {
  233. output, l = remorse.Output("Amazing")
  234. }
  235. if l < door.Width {
  236. centering = strings.Repeat(" ", (door.Width-l)/2)
  237. for _, o := range output {
  238. d.Write(centering + o + door.Reset + door.CRNL)
  239. }
  240. d.Write(door.CRNL)
  241. }
  242. var dungeon door.ColorFont = FontDungeon()
  243. output, l = dungeon.Output("Until NEXT time")
  244. if l > door.Width {
  245. output, l = dungeon.Output("Beware")
  246. }
  247. if l < door.Width {
  248. centering = strings.Repeat(" ", (door.Width-l)/2)
  249. for _, o := range output {
  250. d.Write(centering + o + door.Reset + door.CRNL)
  251. }
  252. d.Write(door.CRNL)
  253. }
  254. /*
  255. redgreen := FontArmageddon()
  256. white := redgreen.Scan(7)
  257. blue := redgreen.Scan(4)
  258. redgreen.Modify(1, white)
  259. redgreen.Modify(2, blue)
  260. */
  261. redgreen := FontRedGreen()
  262. output, l = redgreen.Output("Red-Green")
  263. if l < door.Width {
  264. press_a_key(d)
  265. centering = strings.Repeat(" ", (door.Width-l)/2)
  266. for _, o := range output {
  267. d.Write(centering + o + door.Reset + door.CRNL)
  268. }
  269. d.Write(door.CRNL)
  270. output, l = redgreen.Output("Software")
  271. centering = strings.Repeat(" ", (door.Width-l)/2)
  272. for _, o := range output {
  273. d.Write(centering + o + door.Reset + door.CRNL)
  274. }
  275. d.Write(door.CRNL)
  276. }
  277. }
  278. func input_demo(d *door.Door) {
  279. var ticker *time.Ticker = time.NewTicker(time.Second)
  280. go func() {
  281. for t := range ticker.C {
  282. const tf = "January 2, 2006 03:04:05 PM MST"
  283. output := door.SavePos + door.Goto(5, 2) + door.ColorText("BRI WHI ON GREEN") + t.Format(tf) + door.RestorePos
  284. d.Write(output)
  285. }
  286. }()
  287. var inputColor string = door.ColorText("BRI WHI ON BLUE")
  288. var inputColor2 string = door.ColorText("BRI WHI ON GREEN")
  289. var prompt door.Line = door.Line{Text: "What is YOUR Name: "}
  290. prompt.RenderF = door.RenderBlueYellow
  291. d.Write(prompt.Output() + inputColor)
  292. var name string = d.Input(25)
  293. d.Write(door.Reset + door.CRNL)
  294. prompt.Text = "What is Your Quest: "
  295. d.Write(prompt.Output() + inputColor2)
  296. var quest string = d.Input(35)
  297. d.Write(door.Reset + door.CRNL)
  298. prompt.Text = "What is your Favorite CoLoR: "
  299. d.Write(prompt.Output() + inputColor2)
  300. var color string = d.Input(15)
  301. d.Write(door.Reset + door.CRNL)
  302. ticker.Stop()
  303. d.Write(fmt.Sprintf("You're %s on the %s quest, and fond of %s."+door.CRNL, name, quest, color))
  304. }
  305. func progress_bars(d *door.Door) {
  306. d.Write(door.Clrscr)
  307. var bar door.BarLine = door.BarLine{Line: door.Line{DefaultColor: door.ColorText("BOLD YELLOW")}, Width: 20, Style: door.HALF_STEP}
  308. var bar2 door.BarLine = door.BarLine{Width: 30, Style: door.SOLID, PercentStyle: door.PERCENT_SPACE}
  309. bar2.ColorRange = []door.BarRange{
  310. {2500, door.ColorText("RED")},
  311. {5000, door.ColorText("BROWN")},
  312. {7500, door.ColorText("BOLD YEL")},
  313. {9500, door.ColorText("GREEN")},
  314. {10100, door.ColorText("BRI GRE")}}
  315. var bar3 door.BarLine = door.BarLine{Width: 15, Style: door.GRADIENT, Line: door.Line{DefaultColor: door.ColorText("CYAN")}}
  316. var percentage int64
  317. bar.UpdateP = pctUpdate(&percentage)
  318. bar2.UpdateP = pctUpdate(&percentage)
  319. bar3.UpdateP = pctUpdate(&percentage)
  320. update_bars := func() {
  321. bar.Update()
  322. bar2.Update()
  323. bar3.Update()
  324. }
  325. d.Write(door.Goto(3, 12) + "Half-Step")
  326. d.Write(door.Goto(25, 12) + "% with space and Color Range")
  327. d.Write(door.Goto(57, 12) + "Gradient")
  328. d.Write(door.HideCursor)
  329. bar_start := door.Goto(3, 15)
  330. for f := 0; f <= 100; f++ {
  331. percentage = int64(f * 100)
  332. update_bars()
  333. d.Write(bar_start + bar.Output() + " " + door.Reset + bar2.Output() + door.Reset + " " + bar3.Output())
  334. if d.Disconnect() {
  335. // don't continue to sleep if we're disconnected
  336. break
  337. }
  338. time.Sleep(time.Millisecond * 100)
  339. }
  340. d.Write(door.ShowCursor)
  341. }
  342. func width_demo(d *door.Door) {
  343. var w int = door.Width
  344. var panel door.Panel = door.Panel{X: 1, Y: 1, Width: w}
  345. var lineColor string = door.ColorText("WHI")
  346. var line string
  347. for y := 1; y <= door.Height; y++ {
  348. if y%10 == 0 {
  349. line = strings.Repeat("1234567890", w/10)
  350. for x := len(line); x < w; x++ {
  351. line += strconv.Itoa((x + 1) % 10)
  352. }
  353. } else {
  354. line = ""
  355. for x := 1; x < w; x++ {
  356. if x%10 == 0 {
  357. line += strconv.Itoa(y % 10)
  358. } else {
  359. line += " "
  360. }
  361. }
  362. }
  363. var l door.Line = door.Line{Text: line, DefaultColor: lineColor}
  364. panel.Lines = append(panel.Lines, l)
  365. }
  366. var message string = fmt.Sprintf("Screen Size: %d X %d", door.Width, door.Height)
  367. d.Write(panel.Output())
  368. // Output alert on top of panel
  369. var cx, cy int
  370. cx = (door.Width - len(message) + 2) / 2
  371. cy = (door.Height - 3) / 2
  372. var alert []string = door.AlertBox(message, 1)
  373. d.Write(door.ColorText("BRI YEL ON BLUE"))
  374. for idx, ab := range alert {
  375. d.Write(door.Goto(cx, cy+idx) + ab)
  376. }
  377. d.Write(door.Reset + panel.GotoEnd())
  378. // Pause for key
  379. d.Key()
  380. panel.Lines = make([]door.Line, 0)
  381. var background string = "BUGZ Test Door in GO "
  382. var bl int = len(background)
  383. for y := 1; y <= door.Height; y++ {
  384. offset := (y - 1) % bl
  385. line = background[offset:]
  386. for len(line) < w {
  387. if len(line)+bl <= w {
  388. line += background
  389. } else {
  390. line += background[0 : w-len(line)]
  391. }
  392. }
  393. var l door.Line = door.Line{Text: line, RenderF: door.RenderBlueYellow}
  394. panel.Lines = append(panel.Lines, l)
  395. }
  396. d.Write(panel.Output())
  397. d.Key()
  398. }
  399. func panel_demo(d *door.Door) {
  400. var width int = 55
  401. var fmtStr string = "%-55s"
  402. var p door.Panel = door.Panel{X: 5, Y: 5, Width: width, Style: door.DOUBLE, BorderColor: door.ColorText("CYAN ON BLUE"), Title: "[ Panel Demo ]"}
  403. var lineColor string = door.ColorText("BRIGHT WHI ON BLUE")
  404. // Add lines to the panel
  405. for _, line := range []string{"The BBS Door Panel Demo", "(C) 2021 Red Green Software, https://red-green.com"} {
  406. if door.Unicode {
  407. line = strings.Replace(line, "(C)", "\u00a9", -1)
  408. }
  409. var l door.Line = door.Line{Text: fmt.Sprintf(fmtStr, line), DefaultColor: lineColor}
  410. p.Lines = append(p.Lines, l)
  411. }
  412. p.Lines = append(p.Lines, p.Spacer())
  413. p.Lines = append(p.Lines, door.Line{Text: fmt.Sprintf(fmtStr, "Welcome to golang!"), DefaultColor: lineColor})
  414. var single door.Panel = door.Panel{X: 6, Y: 12, Width: 10, Style: door.SINGLE, BorderColor: door.ColorText("WHITE ON BLUE"), Title: "< Single >"}
  415. single.Lines = append(single.Lines, door.Line{Text: "Example ", DefaultColor: door.ColorText("WHI ON BLACK")})
  416. single.Lines = append(single.Lines, single.Spacer())
  417. single.Lines = append(single.Lines, door.Line{Text: "More Text ", DefaultColor: door.ColorText("BRI GREEN ON BLACK")})
  418. var ds door.Panel = door.Panel{X: 26, Y: 12, Width: 15, Style: door.DOUBLE_SINGLE, BorderColor: door.ColorText("BRI CYAN ON GREEN"), Title: "Double", TitleOffset: 3}
  419. ds.Lines = append(ds.Lines, door.Line{Text: "Double / Single", DefaultColor: door.ColorText("BRI WHI ON GREEN")})
  420. ds.Lines = append(ds.Lines, ds.Spacer())
  421. ds.Lines = append(ds.Lines, door.Line{Text: "Some Other Text", DefaultColor: door.ColorText("BRI CYAN ON GREEN")})
  422. var sd door.Panel = door.Panel{X: 46, Y: 12, Width: 15, Style: door.SINGLE_DOUBLE, BorderColor: door.ColorText("BRI YELL ON RED")}
  423. sd.Lines = append(sd.Lines, door.Line{Text: "Single / Double", DefaultColor: door.ColorText("BRI WHI ON RED")})
  424. sd.Lines = append(sd.Lines, sd.Spacer())
  425. sd.Lines = append(sd.Lines, door.Line{Text: "Text Goes Here ", DefaultColor: door.ColorText("BRI GREEN ON RED")})
  426. d.Write(door.Clrscr)
  427. d.Write(p.Output())
  428. d.Write(single.Output())
  429. d.Write(ds.Output())
  430. d.Write(sd.Output())
  431. }
  432. func main() {
  433. var message string
  434. fmt.Println("Starting testdoor.go")
  435. var d door.Door = door.Door{}
  436. d.Init("testdoor")
  437. defer func() {
  438. if err := recover(); err != nil {
  439. log.Println("FAILURE:", err)
  440. // Display error to user
  441. d.Write(fmt.Sprintf(door.Reset+door.CRNL+"Exception: %v"+door.CRNL, err))
  442. // This displays stack trace stderr
  443. debug.PrintStack()
  444. }
  445. }()
  446. defer d.Close()
  447. var ticker *time.Ticker = time.NewTicker(time.Second)
  448. go func() {
  449. var maxlen int = 0 // max length of timeinfo (sysops have 4 digits of mins)
  450. for t := range ticker.C {
  451. const tf = "03:04:05 PM"
  452. var timeinfo string = " " + t.Format(tf) + " " + fmt.Sprintf("(%3.1f mins)", d.TimeLeft().Minutes()) + " "
  453. if maxlen == 0 {
  454. maxlen = len(timeinfo)
  455. } else {
  456. if len(timeinfo) < maxlen {
  457. timeinfo += strings.Repeat(" ", maxlen-len(timeinfo))
  458. }
  459. }
  460. // maxlen = 12 + 7 + 5 = 24
  461. output := door.SavePos + door.Goto(door.Width-(maxlen+1), 0) + door.ColorText("BRI WHI ON BLUE") + timeinfo + door.RestorePos
  462. if !d.Disconnect() {
  463. d.Write(output)
  464. } else {
  465. ticker.Stop()
  466. return
  467. }
  468. }
  469. }()
  470. // bold := door.Color(1, 37, 40)
  471. var bolder string = door.ColorText("BLI BOLD YEL ON BLUE")
  472. d.Write("Welcome to " + bolder + "door32.sys" + door.Reset + door.CRNL + "..." + door.CRNL)
  473. press_a_key(&d)
  474. d.Write(door.CRNL)
  475. var b []string = door.AlertBox("Warning: golang is in use!", 1)
  476. d.Write(door.ColorText("BRI WHI ON GREEN"))
  477. for _, line := range b {
  478. d.Write(line + door.CRNL)
  479. }
  480. d.Write(door.Reset + door.CRNL)
  481. var left time.Duration = d.TimeLeft()
  482. message = fmt.Sprintf("You have %0.2f minutes / %0.2f seconds remaining..."+door.CRNL, left.Minutes(), left.Seconds())
  483. d.Write(message)
  484. press_a_key(&d)
  485. var mainmenu door.Menu = MainMenu()
  486. var choice int
  487. for choice >= 0 {
  488. d.Write(door.Clrscr + door.HideCursor)
  489. choice = mainmenu.Choose(&d)
  490. d.Write(door.ShowCursor)
  491. if choice < 0 {
  492. break
  493. }
  494. option := mainmenu.GetOption(choice)
  495. // fmt.Printf("Choice: %d, Option: %c\n", choice, option)
  496. switch option {
  497. case 'A':
  498. display_ansi(&d)
  499. press_a_key(&d)
  500. case 'D':
  501. display_information(&d)
  502. press_a_key(&d)
  503. case 'F':
  504. font_demo(&d)
  505. press_a_key(&d)
  506. case 'I':
  507. d.Write(door.Reset + door.CRNL + door.CRNL)
  508. input_demo(&d)
  509. press_a_key(&d)
  510. case 'M':
  511. d.Write(door.Reset + door.CRNL + "TO DO: Provide menu of options to select from..." + door.CRNL)
  512. press_a_key(&d)
  513. case 'P':
  514. progress_bars(&d)
  515. press_a_key(&d)
  516. case 'S':
  517. panel_demo(&d)
  518. press_a_key(&d)
  519. case 'T':
  520. about_test_door(&d)
  521. press_a_key(&d)
  522. case 'W':
  523. width_demo(&d)
  524. case 'Q':
  525. choice = -1
  526. case 'C':
  527. var a, z int
  528. z = 0
  529. a = 10 / z
  530. z = a
  531. _ = a
  532. _ = z
  533. }
  534. }
  535. d.Write(door.Reset + door.CRNL)
  536. message = fmt.Sprintf("Returning to the %s BBS..."+door.CRNL, d.Config.BBSID)
  537. d.Write(message)
  538. d.WaitKey(1, 0)
  539. left = d.TimeLeft()
  540. ticker.Stop()
  541. message = fmt.Sprintf("You had %0.2f minutes / %0.2f seconds remaining!"+door.CRNL, left.Minutes(), left.Seconds())
  542. d.Write(message)
  543. left = d.TimeUsed()
  544. d.Write(fmt.Sprintf("You used %0.2f seconds / %0.2f minutes."+door.CRNL, left.Seconds(), left.Minutes()))
  545. fmt.Println("Ending testdoor.go")
  546. }