testdoor.go 22 KB

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