123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822 |
- package main
- import (
- "fmt"
- "log"
- "red-green/door"
- "runtime/debug"
- "strconv"
- "strings"
- "time"
- // "net/http"
- // _ "net/http/pprof"
- "github.com/mitchellh/go-wordwrap"
- )
- //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"
- //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"
- func pctUpdate(pct *int64) func() int64 {
- return func() int64 {
- return *pct
- }
- }
- func press_keys(d *door.Door) {
- d.Write(door.Reset + door.CRNL + "Press some keys... <ENTER> to exit.")
- var r rune
- var ex door.Extended
- var err error
- for (r != 0x0d) && (err == nil) {
- r, ex, err = d.WaitKey(door.Inactivity)
- if ex == door.MOUSE {
- m, ok := d.GetMouse()
- if ok {
- // var m door.MouseInfo = door.Mouse
- d.Write(fmt.Sprintf("M %d (%d,%d) ", m.Button, m.X, m.Y))
- }
- } else {
- if ex == door.NOP {
- d.Write(fmt.Sprintf("%d (%x) ", r, r))
- } else {
- d.Write(fmt.Sprintf("<%s> ", ex.String()))
- }
- }
- }
- d.Write(door.Reset + door.CRNL)
- }
- func press_a_key(d *door.Door) error {
- var err error
- var ex door.Extended
- d.Write(door.Reset + door.CRNL + "Press a key, or LEFT mouse click to continue...")
- for {
- _, ex, err = d.WaitKey(door.Inactivity)
- if ex == door.MOUSE {
- m, ok := d.GetMouse()
- if ok {
- if m.Button == 1 {
- break
- }
- }
- } else {
- break
- }
- }
- d.Write(door.CRNL)
- return err
- }
- func about_test_door(d *door.Door) {
- var W int = 60
- var center_x int = (door.Width - W) / 2
- var center_y int = (door.Height - 16) / 2
- var about door.Panel = door.Panel{X: center_x,
- Y: center_y,
- Width: W,
- Style: door.SINGLE_DOUBLE,
- BorderColor: door.ColorText("BOLD YELLOW ON BLUE"),
- }
- about.Lines = append(about.Lines, door.Line{Text: fmt.Sprintf("%*s", -W, "About This Door"),
- DefaultColor: door.ColorText("BOLD CYAN ON BLUE")})
- about.Lines = append(about.Lines, about.Spacer())
- about.Lines = append(about.Lines, door.Line{Text: fmt.Sprintf("%*s", -W, "Test Door written in go, using go door.")})
- var copyright string = "(C) 2022 Bugz, Red Green Software"
- if door.Unicode {
- copyright = strings.Replace(copyright, "(C)", "\u00a9", -1)
- }
- about.Lines = append(about.Lines,
- door.Line{Text: copyright, Width: W,
- DefaultColor: door.ColorText("BOLD WHITE ON BLUE")})
- for _, text := range []string{"",
- "This door was written by Bugz.",
- "",
- "It is written in Go, understands CP437 and unicode, adapts",
- "to screen sizes, uses door32.sys, supports TheDraw Fonts",
- "(the fonts are compiled into the door), has NoMoreSecrets",
- "effect, and runs on Linux and Windows."} {
- about.Lines = append(about.Lines, door.Line{Text: text, Width: W})
- }
- var better door.NoMoreSecretsConfig = door.NoMoreSecretsDefault
- better.Jumble_Loop_Speed = 75 // 35
- better.Reveal_Loop_Speed = 100 // 50
- better.Color = door.ColorText("BRI CYAN ON BLUE")
- door.NoMoreSecrets(about.Output(), d, &better)
- }
- func MainMenu() door.Menu {
- // Make the main menu
- // Width was 45
- var menu door.Menu = door.Menu{Panel: door.Panel{Width: 35,
- X: 2,
- Y: 5,
- Style: door.DOUBLE,
- Title: "[ Main Menu: ]",
- TitleOffset: 3,
- BorderColor: door.ColorText("BRI CYAN ON BLA")}}
- menu.SelectedR = door.MakeMenuRender(door.ColorText("BOLD CYAN"),
- door.ColorText("BOLD BLUE"),
- door.ColorText("BOLD WHITE"),
- door.ColorText("BOLD CYAN"))
- menu.UnselectedR = door.MakeMenuRender(door.ColorText("BOLD YEL ON BLUE"),
- door.ColorText("BOLD WHI ON BLUE"),
- door.ColorText("BOLD YEL ON BLUE"),
- door.ColorText("BOLD CYAN ON BLUE"))
- menu.AddSelection("A", "ANSI Display")
- // m.AddSelection("C", "Crash")
- menu.AddSelection("D", "Display Information")
- menu.AddSelection("F", "Font Demo")
- menu.AddSelection("I", "Input Prompt Demo")
- menu.AddSelection("M", "Menu Demo")
- menu.AddSelection("P", "Progress Bars Demo")
- menu.AddSelection("S", "Show Panel")
- menu.AddSelection("T", "Test Door About")
- menu.AddSelection("W", "Screen Width")
- menu.AddSelection("Q", "Quit")
- var descriptions []string = []string{
- // 12345678901234567890123456789012345678901234567890
- "Display an ANSI file. It is compiled into the door itself.",
- // "Crash go, see a handled error.", // The error shows up in the logs.
- "Display dropfile information.",
- "Display TheDraw Fonts. Font information is compiled into the door.",
- "Input some values, while updating the time.",
- "Isn't this is a menu?",
- "Display various progress bar styles. Half step, display percentage, and gradient.",
- "Show multiple panels.",
- "Show more information about the door, using NoMoreSecrets effect.",
- "Examples using the full width of the screen.",
- "Exit this door.",
- }
- var widthLeft int = door.Width - (menu.Width + menu.X + 2)
- var panelWidth int = widthLeft - (2 + 2)
- var maxLines int = 1
- var maxLineLength int
- // Calculate the max lines needed for each line.
- for _, line := range descriptions {
- var wrapped string = wordwrap.WrapString(line, uint(panelWidth))
- var lines int = len(strings.Split(wrapped, "\n"))
- if lines > maxLines {
- maxLines = lines
- }
- if len(line) > maxLineLength {
- maxLineLength = len(line)
- }
- }
- if maxLines == 1 {
- // Ok! Everything fits into one line, SO use max line length as width of panel.
- panelWidth = maxLineLength
- }
- // Position the description panel beside the menu. m.Width + m.X + 2 (1 one to give it a space)
- 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")}
- for x := 0; x < maxLines; x++ {
- descPanel.Lines = append(descPanel.Lines, door.Line{Text: "", Width: panelWidth})
- }
- menu.Activated = func(item int, d *door.Door) {
- var line string = descriptions[item]
- var lines []string = strings.Split(wordwrap.WrapString(line, uint(panelWidth)), "\n")
- for idx := range descPanel.Lines {
- if idx >= len(lines) {
- descPanel.Lines[idx].Text = ""
- } else {
- descPanel.Lines[idx].Text = lines[idx]
- }
- }
- d.Write(door.SavePos + descPanel.Output() + door.RestorePos)
- }
- return menu
- }
- func display_information(d *door.Door) {
- d.Write(door.Clrscr)
- var headerColor string = door.ColorText("BRI CYAN")
- var keyColor string = door.ColorText("BRI GREEN")
- var sepColor string = door.ColorText("BRI YEL")
- var valColor string = door.ColorText("CYAN")
- var nice_format func(string, string) string = func(key string, value string) string {
- return fmt.Sprintf("%s%-20s %s: %s%s", keyColor, key, sepColor, valColor, value) + door.CRNL
- }
- var offset string
- var header string = "DropFile: "
- offset = strings.Repeat(" ", len(header))
- d.Write(headerColor + header)
- d.Write(nice_format("Comm Type", strconv.Itoa(d.Config.Comm_type)))
- if d.Config.BBSID != "" {
- d.Write(offset + nice_format("BBS Software", d.Config.BBSID))
- }
- d.Write(offset + nice_format("Time Left", strconv.Itoa(d.Config.Time_left)))
- d.Write(offset + nice_format("Real Name", d.Config.Real_name))
- // d.Write(nice_format("Comm Handle", strconv.Itoa(d.Config.Comm_handle)))
- d.Write(offset + nice_format("Handle", d.Config.Handle))
- d.Write(offset + nice_format("User #", strconv.Itoa(d.Config.User_number)))
- d.Write(offset + nice_format("Security Level", strconv.Itoa(d.Config.Security_level)))
- d.Write(offset + nice_format("Node #", strconv.Itoa(d.Config.Node)))
- header = "Detected: "
- offset = strings.Repeat(" ", len(header))
- d.Write(headerColor + header)
- d.Write(nice_format("Unicode", strconv.FormatBool(door.Unicode)))
- d.Write(offset + nice_format("CP437", strconv.FormatBool(door.CP437)))
- d.Write(offset + nice_format("Full CP437", strconv.FormatBool(door.Full_CP437)))
- d.Write(offset + nice_format("Screen Size", fmt.Sprintf("%d X %d", door.Width, door.Height)))
- var time time.Duration = d.TimeLeft()
- d.Write(offset + nice_format("Door Time Left", fmt.Sprintf("%d Hours, %d Minutes, %d Seconds", int(time.Hours()), int(time.Minutes())%60, int(time.Seconds())%60)))
- time = d.TimeUsed()
- d.Write(offset + nice_format("Door Time Used", fmt.Sprintf("%d Minutes, %d Seconds", int(time.Minutes()), int(time.Seconds())%60)))
- modules := GetModules()
- header = "Build: "
- offset = strings.Repeat(" ", len(header))
- d.Write(headerColor + header)
- gover, gitver := GetVersion()
- d.Write(nice_format("go version", gover))
- d.Write(offset + nice_format("git commit", gitver))
- for mod, version := range modules {
- d.Write(offset + nice_format(mod, version))
- }
- }
- func display_ansi(d *door.Door) {
- var art []string = ANSIGrowl()
- d.Write(door.Clrscr)
- for _, line := range art {
- d.Write(line + door.CRNL)
- }
- }
- func font_demo(d *door.Door) {
- var output []string
- var l int
- var centering string
- d.Write(door.Clrscr + door.CRNL) // + door.CRNL + door.CRNL)
- var fac door.ColorFont = FontAmazonCyan()
- output, l = fac.Output("ABCDEFGHIJKL")
- if l > door.Width {
- output, l = fac.Output("Cyan")
- }
- if l < door.Width {
- centering = strings.Repeat(" ", (door.Width-l)/2)
- for _, o := range output {
- d.Write(fmt.Sprintf("%s%s%s", centering, o, door.Reset) + door.CRNL)
- }
- d.Write(door.CRNL)
- }
- var patch door.ColorMap = fac.Scan(6)
- // log.Printf("Patch: %#v\n", patch)
- fac.Modify(4, patch)
- output, l = fac.Output("Blue")
- centering = strings.Repeat(" ", (door.Width-l)/2)
- for _, o := range output {
- d.Write(fmt.Sprintf("%s%s%s", centering, o, door.Reset) + door.CRNL)
- }
- d.Write(door.CRNL)
- fac.Modify(1, patch)
- output, l = fac.Output("Red")
- centering = strings.Repeat(" ", (door.Width-l)/2)
- for _, o := range output {
- d.Write(fmt.Sprintf("%s%s%s", centering, o, door.Reset) + door.CRNL)
- }
- d.Write(door.CRNL)
- press_a_key(d)
- var fab door.ColorFont = FontAnarchyBlue()
- output, l = fab.Output("Bugz is Here!")
- if l > door.Width {
- output, l = fab.Output("Hello")
- }
- if l < door.Width {
- centering = strings.Repeat(" ", (door.Width-l)/2)
- for _, o := range output {
- d.Write(centering + o + door.Reset + door.CRNL)
- }
- d.Write(door.CRNL)
- }
- var unchain door.ColorFont = FontUnchained()
- output, l = unchain.Output("Hi There!")
- if l > door.Width {
- output, l = unchain.Output("Meow")
- }
- if l < door.Width {
- centering = strings.Repeat(" ", (door.Width-l)/2)
- for _, o := range output {
- d.Write(centering + o + door.Reset + door.CRNL)
- }
- d.Write(door.CRNL)
- }
- press_a_key(d)
- var asylum door.ColorFont = FontAsylum()
- output, l = asylum.Output("Bugz ROCKS")
- if l > door.Width {
- output, l = asylum.Output("Aslym")
- }
- if l < door.Width {
- centering = strings.Repeat(" ", (door.Width-l)/2)
- for _, o := range output {
- d.Write(centering + o + door.Reset + door.CRNL)
- }
- d.Write(door.CRNL)
- }
- var brain door.ColorFont = FontBrainDmgBlu()
- output, l = brain.Output("I'm so BLUE")
- if l > door.Width {
- output, l = brain.Output("Blue")
- }
- if l < door.Width {
- centering = strings.Repeat(" ", (door.Width-l)/2)
- for _, o := range output {
- d.Write(centering + o + door.Reset + door.CRNL)
- }
- d.Write(door.CRNL)
- }
- var boner door.ColorFont = FontBoner()
- output, l = boner.Output("Welcome!")
- if l < door.Width {
- centering = strings.Repeat(" ", (door.Width-l)/2)
- for _, o := range output {
- d.Write(centering + o + door.Reset + door.CRNL)
- }
- d.Write(door.CRNL)
- }
- press_a_key(d)
- var descent door.ColorFont = FontDescent()
- output, l = descent.Output("Meanwhile...")
- if l > door.Width {
- output, l = descent.Output("BUGZ")
- }
- if l < door.Width {
- centering = strings.Repeat(" ", (door.Width-l)/2)
- for _, o := range output {
- d.Write(centering + o + door.Reset + door.CRNL)
- }
- d.Write(door.CRNL)
- }
- var remorse door.ColorFont = FontRemorse()
- output, l = remorse.Output("Enjoy the fonts")
- if l > door.Width {
- output, l = remorse.Output("Amazing")
- }
- if l < door.Width {
- centering = strings.Repeat(" ", (door.Width-l)/2)
- for _, o := range output {
- d.Write(centering + o + door.Reset + door.CRNL)
- }
- d.Write(door.CRNL)
- }
- var dungeon door.ColorFont = FontDungeon()
- output, l = dungeon.Output("Until NEXT time")
- if l > door.Width {
- output, l = dungeon.Output("Beware")
- }
- if l < door.Width {
- centering = strings.Repeat(" ", (door.Width-l)/2)
- for _, o := range output {
- d.Write(centering + o + door.Reset + door.CRNL)
- }
- d.Write(door.CRNL)
- }
- /*
- redgreen := FontArmageddon()
- white := redgreen.Scan(7)
- blue := redgreen.Scan(4)
- redgreen.Modify(1, white)
- redgreen.Modify(2, blue)
- */
- redgreen := FontRedGreen()
- output, l = redgreen.Output("Red-Green")
- if l < door.Width {
- press_a_key(d)
- centering = strings.Repeat(" ", (door.Width-l)/2)
- for _, o := range output {
- d.Write(centering + o + door.Reset + door.CRNL)
- }
- d.Write(door.CRNL)
- output, l = redgreen.Output("Software")
- centering = strings.Repeat(" ", (door.Width-l)/2)
- for _, o := range output {
- d.Write(centering + o + door.Reset + door.CRNL)
- }
- d.Write(door.CRNL)
- }
- }
- func input_demo(d *door.Door) {
- var ticker *time.Ticker = time.NewTicker(time.Second)
- go func() {
- for t := range ticker.C {
- const tf = "January 2, 2006 03:04:05 PM MST"
- output := door.SavePos + door.Goto(5, 2) + door.ColorText("BRI WHI ON CYAN") + t.Format(tf) + door.RestorePos
- d.Write(output)
- }
- }()
- var inputColor string = door.ColorText("BRI WHI ON BLUE")
- var inputColor2 string = door.ColorText("BRI WHI ON GREEN")
- var prompt door.Line = door.Line{Text: "What is YOUR Name: "}
- prompt.RenderF = door.RenderBlueYellow
- d.Write(prompt.Output() + inputColor)
- var name string = d.Input(25)
- d.Write(door.Reset + door.CRNL)
- prompt.Text = "What is Your Quest: "
- d.Write(prompt.Output() + inputColor2)
- var quest string = d.Input(35)
- d.Write(door.Reset + door.CRNL)
- prompt.Text = "What is your Favorite CoLoR: "
- d.Write(prompt.Output() + inputColor)
- var color string = d.Input(15)
- d.Write(door.Reset + door.CRNL)
- ticker.Stop()
- d.Write(fmt.Sprintf("You're %s on the %s quest, and fond of %s."+door.CRNL, name, quest, color))
- }
- func progress_bars(d *door.Door) {
- d.Write(door.Clrscr)
- var bar door.BarLine = door.BarLine{Line: door.Line{DefaultColor: door.ColorText("BOLD YELLOW")}, Width: 20, Style: door.HALF_STEP}
- var bar2 door.BarLine = door.BarLine{Width: 30, Style: door.SOLID, PercentStyle: door.PERCENT_SPACE}
- bar2.ColorRange = []door.BarRange{
- {Percent: 2500, Color: door.ColorText("RED")},
- {Percent: 5000, Color: door.ColorText("BROWN")},
- {Percent: 7500, Color: door.ColorText("BOLD YEL")},
- {Percent: 9500, Color: door.ColorText("GREEN")},
- {Percent: 10100, Color: door.ColorText("BRI GRE")}}
- var bar3 door.BarLine = door.BarLine{Width: 15, Style: door.GRADIENT, Line: door.Line{DefaultColor: door.ColorText("CYAN")}}
- var percentage int64
- bar.UpdateP = pctUpdate(&percentage)
- bar2.UpdateP = pctUpdate(&percentage)
- bar3.UpdateP = pctUpdate(&percentage)
- update_bars := func() {
- bar.Update()
- bar2.Update()
- bar3.Update()
- }
- d.Write(door.Goto(3, 12) + "Half-Step")
- d.Write(door.Goto(25, 12) + "% with space and Color Range")
- d.Write(door.Goto(57, 12) + "Gradient")
- d.Write(door.HideCursor)
- bar_start := door.Goto(3, 15)
- for f := 0; f <= 100; f++ {
- d.Write(door.Goto(3, 10) + door.Reset + fmt.Sprintf("Value: %d", f))
- percentage = int64(f * 100)
- update_bars()
- d.Write(bar_start + bar.Output() + " " + door.Reset + bar2.Output() + door.Reset + " " + bar3.Output())
- if d.Disconnect() {
- // don't continue to sleep if we're disconnected
- break
- }
- time.Sleep(time.Millisecond * 100)
- }
- d.Write(door.ShowCursor)
- }
- func width_demo(d *door.Door) {
- var w int = door.Width
- var panel door.Panel = door.Panel{X: 1, Y: 1, Width: w}
- var lineColor string = door.ColorText("WHI")
- var line string
- for y := 1; y <= door.Height; y++ {
- if y%10 == 0 {
- line = strings.Repeat("1234567890", w/10)
- for x := len(line); x < w; x++ {
- line += strconv.Itoa((x + 1) % 10)
- }
- } else {
- line = ""
- for x := 1; x < w; x++ {
- if x%10 == 0 {
- line += strconv.Itoa(y % 10)
- } else {
- line += " "
- }
- }
- }
- var l door.Line = door.Line{Text: line, DefaultColor: lineColor}
- panel.Lines = append(panel.Lines, l)
- }
- var message string = fmt.Sprintf("Screen Size: %d X %d", door.Width, door.Height)
- d.Write(panel.Output())
- // Output alert on top of panel
- var cx, cy int
- cx = (door.Width - len(message) + 2) / 2
- cy = (door.Height - 3) / 2
- var alert []string = door.AlertBox(message, 1)
- d.Write(door.ColorText("BRI YEL ON BLUE"))
- for idx, ab := range alert {
- d.Write(door.Goto(cx, cy+idx) + ab)
- }
- d.Write(door.Reset + panel.GotoEnd())
- // Pause for key
- d.WaitKey(door.Inactivity)
- panel.Lines = make([]door.Line, 0)
- var background string = "BUGZ Test Door in GO "
- var bl int = len(background)
- for y := 1; y <= door.Height; y++ {
- offset := (y - 1) % bl
- line = background[offset:]
- for len(line) < w {
- if len(line)+bl <= w {
- line += background
- } else {
- line += background[0 : w-len(line)]
- }
- }
- var l door.Line = door.Line{Text: line, RenderF: door.RenderBlueYellow}
- panel.Lines = append(panel.Lines, l)
- }
- d.Write(panel.Output())
- d.WaitKey(door.Inactivity)
- }
- func panel_demo(d *door.Door) {
- var width int = 55
- var panel door.Panel = door.Panel{X: 5, Y: 5, Width: width, Style: door.DOUBLE, BorderColor: door.ColorText("CYAN ON BLUE"), Title: "[ Panel Demo ]"}
- var lineColor string = door.ColorText("BRIGHT WHI ON BLUE")
- // Add lines to the panel
- for _, line := range []string{"The BBS Door Panel Demo", "(C) 2021 Red Green Software, https://red-green.com"} {
- if door.Unicode {
- line = strings.Replace(line, "(C)", "\u00a9", -1)
- }
- var l door.Line = door.Line{Text: line, Width: width, DefaultColor: lineColor}
- panel.Lines = append(panel.Lines, l)
- }
- panel.Lines = append(panel.Lines, panel.Spacer())
- panel.Lines = append(panel.Lines, door.Line{Text: "Welcome to golang!", Width: width, DefaultColor: lineColor})
- width = 10
- var single door.Panel = door.Panel{X: 6, Y: 12, Width: width, Style: door.SINGLE, BorderColor: door.ColorText("WHITE ON BLUE"), Title: "< Single >"}
- single.Lines = append(single.Lines, door.Line{Text: "Example", Width: width, DefaultColor: door.ColorText("WHI ON BLACK")})
- single.Lines = append(single.Lines, single.Spacer())
- single.Lines = append(single.Lines, door.Line{Text: "More Text", Width: width, DefaultColor: door.ColorText("BRI GREEN ON BLACK")})
- width = 15
- 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}
- double_single.Lines = append(double_single.Lines, door.Line{Text: "Double / Single", Width: width, DefaultColor: door.ColorText("BRI WHI ON GREEN")})
- double_single.Lines = append(double_single.Lines, double_single.Spacer())
- double_single.Lines = append(double_single.Lines, door.Line{Text: "Some Other Text", Width: width, DefaultColor: door.ColorText("BRI CYAN ON GREEN")})
- var single_double door.Panel = door.Panel{X: 46, Y: 12, Width: width, Style: door.SINGLE_DOUBLE, BorderColor: door.ColorText("BRI YELL ON RED")}
- single_double.Lines = append(single_double.Lines, door.Line{Text: "Single / Double", Width: width, DefaultColor: door.ColorText("BRI WHI ON RED")})
- single_double.Lines = append(single_double.Lines, single_double.Spacer())
- single_double.Lines = append(single_double.Lines, door.Line{Text: "Text Goes Here ", Width: width, DefaultColor: door.ColorText("BRI GREEN ON RED")})
- d.Write(door.Clrscr)
- d.Write(panel.Output())
- d.Write(single.Output())
- d.Write(double_single.Output())
- d.Write(single_double.Output())
- }
- func main() {
- var message string
- /*
- go func() {
- http.ListenAndServe(":6060", nil)
- }()
- */
- var d door.Door = door.Door{}
- d.Init("testdoor")
- defer func() {
- if err := recover(); err != nil {
- // This displays stack trace stderr
- debug.PrintStack()
- fmt.Println("ERROR:", err)
- log.Println("FAILURE:", err)
- // Display error to user
- d.Write(fmt.Sprintf(door.Reset+door.CRNL+"Exception: %v"+door.CRNL, err))
- }
- }()
- defer d.Close()
- // Updaters work best when the screen doesn't scroll, so start
- // us off at the very top.
- d.Write(door.Clrscr)
- // Start spinrite effects
- var ticker *time.Ticker = time.NewTicker(time.Millisecond * time.Duration(100))
- var spin door.SpinRiteMsg = door.SpinRiteMsgInit(15, 5,
- door.ColorText("RED ON GREEN"),
- []string{"RED", "GREEN", "SOFTWARE"})
- var spin2 door.SpinRite = door.SpinRiteInit(13, 5,
- door.ColorText("BRI CYA ON BLUE"))
- go func() {
- var output string
- for range ticker.C {
- output = door.SavePos + door.Goto(door.Width-16, 1) + spin.Output() +
- door.Goto(door.Width-15, 3) + spin2.Output() + door.RestorePos
- if !d.Disconnect() {
- d.Write(output)
- } else {
- ticker.Stop()
- return
- }
- }
- }()
- var wopr door.WOPR
- wopr.Init(d.StartTime, d.TimeOut, "") // TimeUsed(), d.TimeLeft(), "")
- wopr.ElapsedPanel.X = door.Width - 19
- wopr.ElapsedPanel.Y = door.Height - 15
- wopr.RemainingPanel.X = door.Width - 19
- wopr.RemainingPanel.Y = door.Height - 8
- wopr.Animate(&d)
- // bold := door.Color(1, 37, 40)
- var bolder string = door.ColorText("BOLD YEL ON BLUE")
- d.Write("Welcome to " + bolder + "go door go TestDoor." + door.Reset + door.CRNL + "..." + door.CRNL)
- d.EnableMouse(door.Normal)
- press_a_key(&d)
- d.Write(door.CRNL)
- var b []string
- if door.CP437 {
- b = door.AlertBox("Alert: go \xfb is in use!", 1)
- } else {
- b = door.AlertBox("Alert: go \u221a is in use!", 1)
- }
- warningColor := door.ColorText("BRI WHI ON GREEN")
- for _, line := range b {
- // Prevent color bleeding.
- d.Write(warningColor + line + door.Reset + door.CRNL)
- }
- d.Write(door.Reset + door.CRNL)
- var left time.Duration = d.TimeLeft()
- message = fmt.Sprintf("You have %0.2f minutes / %0.2f seconds remaining..."+door.CRNL, left.Minutes(), left.Seconds())
- d.Write(message)
- press_a_key(&d)
- var mainmenu door.Menu = MainMenu()
- var choice int
- for choice >= 0 {
- d.Write(door.Clrscr + door.HideCursor)
- choice = mainmenu.Choose(&d)
- d.Write(door.ShowCursor)
- if choice < 0 {
- break
- }
- option := mainmenu.GetOption(choice)
- wopr.Stop()
- // Clear WOPR panels.
- d.Write(door.Reset + wopr.Clear())
- r, b := mainmenu.Panel.RightBottomPos()
- d.Write(door.Goto(r, b))
- // fmt.Printf("Choice: %d, Option: %c\n", choice, option)
- switch option {
- case 'A':
- display_ansi(&d)
- press_a_key(&d)
- case 'D':
- display_information(&d)
- press_a_key(&d)
- case 'F':
- font_demo(&d)
- press_a_key(&d)
- case 'I':
- d.Write(door.Reset + door.CRNL + door.CRNL)
- input_demo(&d)
- press_a_key(&d)
- case 'M':
- // Why is this so far down on the screen? (Scrolls)
- d.Write(door.Reset + door.CRNL + "TO DO: Provide menu of options to select from..." + door.CRNL)
- press_a_key(&d)
- case 'P':
- progress_bars(&d)
- press_a_key(&d)
- case 'S':
- panel_demo(&d)
- press_a_key(&d)
- case 'T':
- about_test_door(&d)
- press_a_key(&d)
- case 'W':
- width_demo(&d)
- case 'Q':
- // This is also far down on the screen ...
- choice = -1
- case 'C': // Disabled
- var a, z int
- z = 0
- a = 10 / z
- z = a
- _ = a
- _ = z
- }
- wopr.Animate(&d)
- }
- // d.Write("\x1b[?1000l") // disable mouse
- // d.Write("\x1b[?1002l")
- d.DisableMouse()
- d.Write(door.Reset + door.CRNL)
- if d.Config.BBSID != "" {
- message = fmt.Sprintf("Returning to the %s BBS..."+door.CRNL, d.Config.BBSID)
- } else {
- message = "Returning to the BBS..." + door.CRNL
- }
- d.Write(message)
- d.WaitKey(time.Second)
- left = d.TimeLeft()
- ticker.Stop()
- message = fmt.Sprintf("You had %0.2f minutes remaining!"+door.CRNL, left.Minutes())
- d.Write(message)
- left = d.TimeUsed()
- d.Write(fmt.Sprintf("You used %0.2f seconds / %0.2f minutes."+door.CRNL, left.Seconds(), left.Minutes()))
- fmt.Println("Ending testdoor.go")
- }
|