testdoor.go 23 KB

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