testdoor.go 23 KB

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