testdoor.go 23 KB

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