testdoor.go 23 KB

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