testdoor.go 20 KB

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